KeyPress Numeric enforcing
I am using a textbox and using the keypress event
to make the characters uppercase.
I have another textbox that I am using that I want
to ignore all characters except numerics. What
value should the KeyAscii variable be set to.
In addition I want to have the escape sequence characters not be affected. A tab should go to the next control in the tab order.
Any thoughts??
Re: KeyPress Numeric enforcing
Private Sub Text1_KeyPress(KeyAscii As Integer)
Const Numbers$ = "0123456789."
If InStr(Numbers, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
Exit Sub
End If
End Sub
Tab will send you to the next control
Iouri Boutchkine
[email protected]
Re: KeyPress Numeric enforcing
It's always faster to manipulate numbers than strings. So, a better method will be
private Sub Text1_KeyPress(KeyAscii as Integer)
If KeyAscii >= 48 and KeyAscii <= 57 then KeyAscii = 0
End Sub
48 is the code for "0" and 57 for "9"