Data Entry Control

  • Thread starter Thread starter Christopher Brandy
  • Start date Start date
C

Christopher Brandy

Do anyone know how to evaluate each character a user
enters to determine if it is numeric? I don't want to
let the user type in an alpha character. If they hit a
alpha character I want the computer to beep but retain
the numbers they already typed in.

Your help is appreciated
 
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar.IsNumber(e.KeyChar) Then

MsgBox("Numeric")

End If

End Sub

Regards - OHM
 
What if it's not numeric? How do I not add that
character to the textbox. In VB6, I just set the key
code to 0.
 
Else
e.Handled=True

End If

Regards - OHM


Christopher said:
What if it's not numeric? How do I not add that
character to the textbox. In VB6, I just set the key
code to 0.
 
I'm afraid this does not work. The alpha character is
still added to the textbox. Any other suggestions?
 
It does work. Look at this NOTE ( KEY PRESS EVENT ). I Just tested it

OHM

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If Char.IsNumber(e.KeyChar) Then

'Do nothing

Else

e.Handled = True

End If

End Sub
 
Back
Top