by Rajesh Sivaraman (4 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 1st July 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
'Simple code to allow only numbers to be typed into a textbox without 'using any API's ."DELETE", "BACKSPACE" AND "." keys also work.Nothing
'Submitted by Rajesh Sivaraman [email protected]
'Simple code to allow only numbers to be typed into a textbox without
'using any API's ."DELETE", "BACKSPACE" AND "." keys also work.Nothing
'happens when characters are typed.
'code
Private Sub Text1_KeyPress(KeyAscii As Integer)
'ascii 8 stands for-backspace,46-delete and 48-57 stands for 0 to 9
If KeyAscii <> 8 And KeyAscii <> 46 And KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
'Aliter
'The same above is made into a function which you can put in a module and use
'in multiple forms by simply calling the function.
Public Function numonly(KeyAscii) As Integer
If KeyAscii <> 8 And KeyAscii <> 46 And KeyAscii < 48 Or KeyAscii > 57 Then
numonly = 0
Else
numonly = KeyAscii
End If
End Function
'The function can be called as shown below
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = numonly(KeyAscii)
End Sub
No comments have been posted about 'Simple code to allow only numbers to be typed into a textbox without 'using any API's .DELETE, . Why not be the first to post a comment about 'Simple code to allow only numbers to be typed into a textbox without 'using any API's .DELETE, .