- Home
·
- String Manipulation
·
- 'Simple code to allow only characters to be typed into a textbox without 'using any API's .DELETE
'Simple code to allow only characters to be typed into a textbox without 'using any API's .DELETE
'Simple code to allow only characters to be typed into a textbox without 'using any API's ."DELETE", "BACKSPACE" AND "." keys also work.
Rate 'Simple code to allow only characters to be typed into a textbox without 'using any API's .DELETE
(1(1 Vote))
'Submitted by Rajesh Sivaraman [email protected]
'Simple code to allow only characters to be typed into a textbox without
'using any API's ."DELETE", "BACKSPACE" AND "." keys also work. Nothing
'happens when numbers are typed.
'code
Private Sub Text1_KeyPress(KeyAscii As Integer)
'ascii 8 stands for-backspace,46-delete , 65-90 stands for A to Z and 97-122 stands for a to z
If KeyAscii <> 8 And KeyAscii <> 46 And KeyAscii < 65 Or KeyAscii > 90 And KeyAscii < 97 Or KeyAscii > 122 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 charonly(KeyAscii As Integer)
If KeyAscii <> 8 And KeyAscii <> 46 And KeyAscii < 65 Or KeyAscii > 90 And KeyAscii < 97 Or KeyAscii > 122 Then
charonly = 0
Else
charonly = KeyAscii
End If
End Function
'The function can be called as shown below
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = charonly(KeyAscii)
End Sub
'Simple code to allow only characters to be typed into a textbox without 'using any API's .DELETE Comments
No comments yet — be the first to post one!
Post a Comment