Click to See Complete Forum and Search --> : Restrict input of a textbox to numbers


bloodemon
April 30th, 2001, 01:48 AM
I wanna make a textbox only accept number input,what shall I do?

Source code may make me easier :P

O.K
April 30th, 2001, 02:06 AM
Hi,
you could use this code:

private Sub Text1_KeyPress(KeyAscii as Integer)
Select Case KeyAscii
Case Asc("0") to Asc("9")
Case else:
KeyAscii = 0
End Select
End Sub




Bye,
O.K

SAKYA
April 30th, 2001, 05:46 AM
private Sub Text1_KeyPress(KeyAscii as Integer)
if keyAscii=8 then exit sub
if not isNumeric(chr(KeyAscii)) then
KeyAscii=0
end if
End Sub



the ascii value of BackSpace is 8.
isnumeric is a function used to check whether the value is numeric or not.