Click to See Complete Forum and Search --> : KeyPress Numeric enforcing


DLARLICK
April 6th, 2001, 03:37 PM
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??

Iouri
April 6th, 2001, 03:50 PM
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
iouri@hotsheet.com

shree
April 6th, 2001, 08:13 PM
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"