Pass Control.Name to Sub from which it is called

I have a sub that is call from many diferant textboxes.  I need to pass the control name to the called sub.

Private Sub TrigTSAWavTextBox_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TrigTSAWavTextBox.Validating
 
       ChkForNumber(This.control.name) 'Pass the Control.Name from this Sub
 End Sub

Private Sub ChkForNumber(ByVal TxtBox As Control)
        If Not IsNumeric(TxtBox.Text) Then
            TxtBox.ForeColor = Color.Red
            MsgBox("Enter only numbers for this field." & vbCrLf & "This field also cannot be blank." _
                   & vbCrLf & "Example .. -3, -2, -1, 0, 1, 2, 30", MsgBoxStyle.Exclamation, "Flight Status User Input Error")
            TxtBox.ForeColor = Color.Black
            TxtBox.Text = ""
        End If
    End Sub

Since I do not know which textbox is calling the SubChkForNumber I need to pass the textbox.name.
buzzcarterAsked:
Who is Participating?
 
dentabConnect With a Mentor Commented:
and for your example you dont want the name...

You want

ChkForNumber(Sender)

To actually reference the control
0
 
purquizCommented:
Hi.
I'm not sure, haven't used the 2008 version, but I noticed you defined a Sub that takes a control as an argument:

...
Private Sub ChkForNumber(ByVal TxtBox As Control)
...

but when you call it you are passing a string, not a control:

...
ChkForNumber(This.control.name) 'Pass the Control.Name from this Sub
...

Anyways, sorry if I'm wrong, but as I said I haven't worked with 2008 yet.

Greetings from Argentina;

Pablo
0
 
dentabCommented:
You mean sender.name?

e.g.
  ChkForNumber(Sender.Name)

I dont have .net instaleld on this machine to check, but I am sure it is as simple as that.
0
 
buzzcarterAuthor Commented:
Prefect, that saves alot of work.  Thanks
0
All Courses

From novice to tech pro — start learning today.