by K.SATHYA SAGAR KIRAN KUMAR (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Thu 5th April 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Validates user input
Private Sub text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 Then
KeyAscii = 0
End If
If Chr(KeyAscii) Like "#" <> True And KeyAscii <> vbKeyBack And KeyAscii <> vbKeyDelete Then
KeyAscii = 0
End If
End Sub
'* the following code allows only numbers and letters
Private Sub text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 Then
KeyAscii = 0
Exit Sub
End If
If ((KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii = vbKeyDelete) Or (KeyAscii = vbKeyBack)) <> True Then
KeyAscii = 0
End If
End Sub
'* the following code allows only alphabets
Private Sub text1_KeyPress( KeyAscii As Integer)
If KeyAscii = 46 Then
KeyAscii = 0
Exit Sub
End If
If Chr(KeyAscii) Like "[a-zA-Z]" <> True And KeyAscii <> vbKeyBack And KeyAscii <> vbKeySpace And KeyAscii <> vbKeyDelete Then
KeyAscii = 0
End If
'* the following code allows only numbers and "-"
private sub text1_keypress(keyascii as integer)
If KeyAscii = 46 Then
KeyAscii = 0
Exit Sub
End If
If Chr(KeyAscii) Like "#" <> True And KeyAscii <> Asc("-") And KeyAscii <> vbKeyBack And KeyAscii <> vbKeyDelete And KeyAscii <> vbKeySpace Then
KeyAscii = 0
End If
End Select
End Sub
'* the following code allows only one decimal point
Private Sub text1_KeyPress(KeyAscii As Integer)
Static dotentered As Boolean
If InStr(txtper, ".") > 0 Then
dotentered = True
Else
dotentered = False
End If
If KeyAscii = 46 And dotentered Then
KeyAscii = 0
Exit Sub
End If
If Chr(KeyAscii) Like "#" <> True And KeyAscii <> vbKeyBack And KeyAscii <> vbKeyDelete Then
KeyAscii = 0
End If
End Sub