Click to See Complete Forum and Search --> : Textbox help


Screaming Fist
August 24th, 1999, 08:51 PM
Is there a way to limit what can be typed into a textbox? For instance, only numbers or letters?

--
Screaming Fist
A witty saying proves nothing.

Gary Ng
August 24th, 1999, 10:48 PM
Hi,

Yes, we can limit the characters in a textbox. Here is an example which limit the characters to Hexadecimal value:


private Sub Text1_KeyPress(KeyAscii as Integer)
Dim strValid as string

strValid = "0123456789ABCDEF" 'valid input

KeyAscii = Asc(UCase(Chr(KeyAscii))) 'force uppercase

If KeyAscii > 26 then 'if not control code
If InStr(strValid, Chr(KeyAscii)) = 0 then
KeyAscii = 0
End If
End If

End Sub





Enjoy yourself and good luck to you.

Gary Ng