validation for text box and using data from one form in second for

P

Pam

I originally posted this message in the wrong area, I hope I'm in the right
area now.

I am new to visual basic and trying to make a form that will eventually
(maybe?) dump into an access database.
I have a "customer" form and when the user selects the payment type it
brings up different forms for validation.
for instance, when they select "visa" it brings up another form "visa" and
the form validates that they are inputting 16 digits.
My question is twofold.
1-How can I call the results entered into the "visa" form back to textboxes
on the "customer" form. or
2-How can I perform the validation on the "customer" form without calling
the other forms?
below is the code I have from my customer and visa forms, I have searched
but haven't found a working answer for Visual Basic 2008.
Thank you for any help you can give me.
***customer***
Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
If ComboBox3.Text = "Visa" Then
Visa.Show()
ElseIf ComboBox3.Text = "MasterCard" Then
MasterCard.Show()
ElseIf ComboBox3.Text = "Discover" Then
Discover.Show()
ComboBox3.Text = ""
ElseIf ComboBox3.Text = "Check By Phone" Then
CheckByPhone.Show()
ElseIf ComboBox3.Text = "American Express" Then
AmericanExpress.Show()
ElseIf ComboBox3.Text = "Other" Then
Other.Show()
End If
End Sub
***visa***
Public Class Visa
'To validate that credit card number is 16 digits
Private Sub Visa_No_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles Visa_No.Validating
'Private Sub Visa_No_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Visa_No.TextChanged
If Len(Me.Visa_No.Text) < 16 Then
MsgBox("Credit Card Number must be 16 digits!")
ElseIf Len(Me.Visa_No.Text) > 16 Then
MsgBox("Credit Card Number must be 16 digits!")
End If
End Sub
End Class
 
C

Cor Ligthert[MVP]

Pam,

The probably in long terms best one is to set all your validations in a
seperated class (I name that rules). I use for that even a seperated dll but
that depends how big your solution is.

As you use a main form from which everything is starting you can everytime
call the subforms seperatly. That can be dialogforms(probably the most easy
ones because you don't need threading at all for those) or it can be normal
ones. Don't forget to close the normal ones (you show those with show) and
to dispose the showdialog ones.

As you do that, you probably as an VB developer you start using everything
shared (Static in C). Try to avoid that, in fact it is seldom necesary.

I hope this helps.

Cor
 
J

James Hahn

Take a look at the dialog form template (Project/Add Windows Form/Common
Items/Dialog). This form type is specfically designed to return a result
(such as OK or Cancel) and (optionally) a value to the calling form. For
instance, a file open dialog might return a cancel indicator if the user
cancelled the operation, or an OK indicator and a file name if the user
selected a file. Your dialogs will return a valid credit card number or a
failure indicator if the credit card number was invalid or the user
cancelled the operation.

The 'Creating Modal Dialog Boxes' section of this article may be useful. It
was written before the dialog became a template, so some of the work
described there is already done for you if you use the template, but the
description of how to make a call to the form and process the results is
useful:
http://msdn.microsoft.com/en-us/library/ms973856.aspx

This one looks interesting too, but you are only interested in step 5 (extra
code for the dialog - you will add your validation routine to the OK button
clicked event) and step 6 (code for the calling form) as everything else is
done for you by the template. The properties you define in step 5 will both
be read-only (the examples are read/write). One will be the credit card
number, and the other will be a valid/invalid flag. The code in step 6 will
change - there is no initialization of the properties (they are read only)
and you will retrieve the two properties (number and valid) when the dialog
closes and process the result depending on the valid flag.
http://www.techexams.net/blogs/70-526/creating-dialog-boxes-in-net/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top