Windows Develop Bookmark and Share   
 index > Windows Forms General > Passing Parameters during a Call
 

Passing Parameters during a Call

    I would like to pass the name of a control to a sub for control validation. I have a great quantity of controls and don't want to code validation over and over. I have tried the following code, but keep getting errors.  I'm new to vb.net and appreciate the help.
    Am I on the right track? Thanks.

Mark F.

Private Sub txtEnterNumber(....)
  valnums(txtEnterNumber)
End Sub


Private Sub valnums(ByVal name)
        Dim strTest As String = name
        If strTest.Text = "" Then
            MessageBox.Show("The name Value is required.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            With strTest
                .Text = Nothing
                .Focus()
            End With

        ElseIf Not IsNumeric(strTest.Text) Then
            MessageBox.Show("The name Value must be numeric.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            With strTest
                .Text = Nothing
                .Focus()
            End With
        End If
    End Sub
MigrationUser 1  Wednesday, September 17, 2003 3:48 PM
You don't have to pass the name of the TextBox, you can pass the TextBox object itself to your validation:

Private Sub txtEnterNumber(sender As Object, e As EventArgs) ...
  Valnums(DirectCast(sender, TextBox))
End Sub

Private Sub valnums(strTest As TextBox)
  If strTest.Text = ""
  ...
End Sub
MigrationUser 1  Thursday, September 18, 2003 1:13 AM
Daniel,

    Thanks for the assist. Now I can clean things up a bit.
     Again, thanks.

Mark F.
MigrationUser 1  Thursday, September 18, 2003 11:13 AM

You can use google to search for other answers

Custom Search

More Threads

• contextmenustrip problem
• textbox validation
• Assembly Icon problem
• Simple binding textbox to decimal column in dataset problems
• dispose exception with write back caching
• OpenFileDialog
• Thread not abort when the form closes
• how to populate lable controls in a table inside FlowLayout panel?
• how to get Drop Down portion of combox1 closed message in .net 1.1
• Controls acting as a treenode within a Treeview Control