Force numbers only in a text box in Visual Basic 6.0

Use this code if you want to force numbers only in a textbox using Visual Basic 6.0.
You can even change the type you want, numbers, letter or both of them.

This is a simple code.

Get the code:






' Force numbers only in a text box
' place this in the 'Keypress' event of a text box

' -------------
' 1st Method
' -------------
Const Number$ = "0123456789." ' only allow these characters

If KeyAscii <> 8 Then
If InStr(Number$, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
Exit Sub
End If
End If

' -------------
' 2nd Method
' -------------

' Force numbers only in a text box
If IsNumeric(Chr(KeyAscii)) <> True Then KeyAscii = 0





Related Posts by Categories



Widget by Hoctro

Enter your email address:

Delivered by FeedBurner

Followers



Source Code