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
Force numbers only in a text box in Visual Basic 6.0
Force numbers only in a text box in Visual Basic 6.0
2008-02-16T18:20:00-08:00
Bonitoo
Programming
|
Source Code
|