I have problem with this code;
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And (e.KeyChar <> Chr(8)) Then
e.Handle = True
End If
I need a code that trap non numeric key and allow backspace and period!
Printable View
I have problem with this code;
If (e.KeyChar < Chr(48) Or e.KeyChar > Chr(57)) And (e.KeyChar <> Chr(8)) Then
e.Handle = True
End If
I need a code that trap non numeric key and allow backspace and period!
I always use this as needed .
have fun!VB Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress 'Numeric keys start with 48 through 52 'backspace key has the ascii code 8 'period key has the ascii code 46 Dim KeyAscii As Integer KeyAscii = Asc(e.KeyChar) 'only disallow numeric values Select Case KeyAscii Case Asc("0") To Asc("9") 'acceptable keystrokes e.Handled = True ' Case Asc(".") if you want to disable 'other keys 'e.Handled = True Case Else e.Handled = False End Select End Sub