VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



'Simple code to allow only characters to be typed into a textbox without 'using any API's .DELETE

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 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




'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

Download this snippet    Add to My Saved Code

'Simple code to allow only characters to be typed into a textbox without 'using any API's .DELETE Comments

No comments have been posted about 'Simple code to allow only characters 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 characters to be typed into a textbox without 'using any API's .DELETE.

Post your comment

Subject:
Message:
0/1000 characters