by Dennis Kennedy (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 2nd June 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Put in the text 'KeyPress' event to restrict the text boxes to specific keys, upper case, numbers, decimals or date. [email protected]
'restrict the text boxes to specific keys,
'upper case, numbers, decimals or date
'Syntax:
' KeyAscii = TextKeyAscii(KeyAscii, vbDouble, Text1.Text)
' KeyAscii = TextKeyAscii(KeyAscii, vbLong)
' KeyAscii = TextKeyAscii(KeyAscii, vbDate)
' KeyAscii = TextKeyAscii(KeyAscii, vbString)
'http://www.geocities.com/dkblid
'mailto:[email protected]
Public Function TextKeyAscii(ByVal KeyAscii As Integer, ByVal KeyType As Integer, Optional ByVal sString As String) As Integer
Dim per As Integer
If KeyAscii < 32 Then
If KeyAscii = 3 Then 'copy
ElseIf KeyAscii = 8 Then 'backspace
ElseIf KeyAscii = 13 Then 'enter
ElseIf KeyAscii = 22 Then 'paste
ElseIf KeyAscii = 24 Then 'cut
ElseIf KeyAscii = 27 Then 'escape
Else
KeyAscii = 0
End If
Else
Select Case KeyType
Case vbLong
If (KeyAscii < 48 Or KeyAscii > 60) Then
KeyAscii = 0
End If
Case vbDouble
If KeyAscii = 46 Then
per = InStr(sString, ".")
If per > 0 Then
KeyAscii = 0
End If
ElseIf (KeyAscii < 48 Or KeyAscii > 60) Then
KeyAscii = 0
End If
Case vbDate
If (KeyAscii < 48 Or KeyAscii > 60) And KeyAscii <> 47 Then
KeyAscii = 0
End If
Case vbString
KeyAscii = IIf(KeyAscii >= 97 And KeyAscii <= 122, KeyAscii - 32, KeyAscii)
End Select
End If
TextKeyAscii = KeyAscii
End Function
No comments have been posted about Put in the text 'KeyPress' event to restrict the text boxes to specific keys, upper case, numbers, . Why not be the first to post a comment about Put in the text 'KeyPress' event to restrict the text boxes to specific keys, upper case, numbers, .