Bucher100

Numbers only in TextBox

Apr 16th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.42 KB | None | 0 0
  1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  2.  
  3.     '97 - 122 = Ascii codes for simple letters
  4.     '65 - 90  = Ascii codes for capital letters
  5.     '48 - 57  = Ascii codes for numbers
  6.  
  7.     If Asc(e.KeyChar) <> 8 Then
  8.         If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
  9.             e.Handled = True
  10.         End If
  11.     End If
  12.  
  13. End Sub
Add Comment
Please, Sign In to add comment