Abid Durrani
New member
- Joined
- Nov 26, 2010
- Messages
- 3
- Programming Experience
- Beginner
hi, i am working in vb.net 2005 i have more than 10 vb forms and each form has number of textboxes, and maskedtextboxes, so i have to validate them all. i am using this way that on keypress event of textbox i use this code
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim a As Char
a = e.KeyChar
If Char.IsSymbol(a) Then
MsgBox("Please insert only digits")
e.Handled = True
End If
If Char.IsLetter(a) Then
MsgBox("Please insert only digits")
e.Handled = True
End If
If Char.IsPunctuation(a) Then
MsgBox("Please insert only digits")
e.Handled = True
End If
end sub
but this is very lengthy code, i mean that on each form i have almost 15 to 20 textboxes, and if i use the same code on each's textbox keypress event so it will be very very lengthy code. so please assist me that how i solve this problem? and how do i use the shortest code?
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim a As Char
a = e.KeyChar
If Char.IsSymbol(a) Then
MsgBox("Please insert only digits")
e.Handled = True
End If
If Char.IsLetter(a) Then
MsgBox("Please insert only digits")
e.Handled = True
End If
If Char.IsPunctuation(a) Then
MsgBox("Please insert only digits")
e.Handled = True
End If
end sub
but this is very lengthy code, i mean that on each form i have almost 15 to 20 textboxes, and if i use the same code on each's textbox keypress event so it will be very very lengthy code. so please assist me that how i solve this problem? and how do i use the shortest code?