by N. Pandu Ranga Rao (3 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Wed 26th August 2009
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
Validates textboxes, comboboxes for correct user input, when a user presses some key.
API Declarations
Public Const LCase As Integer = 2
Public Const BothCase As Integer = 3
Public Const BothCaseNum As Integer = 4
Dim OCnt As Integer
OCnt = 0
Select Case KeyAscii
Case 8
AcceptNumbers = KeyAscii
Exit Function
Case 48 To 57 And Len(Trim(Obj.Text)) <> MaxDigits
AcceptNumbers = KeyAscii
Exit Function
Case Else
If Len(Trim(Obj.Text)) <> MaxDigits Then
Dim i As Integer
For i = 0 To UBound(Exceptions)
If Asc(Exceptions(i)) = KeyAscii Then
OCnt = AppearCount(Obj.Text, CStr(Exceptions(i)))
If OCnt = NoTimesAllow Then
AcceptNumbers = 0
Exit Function
End If
If KeyAscii = 32 And Len(Trim(Obj.Text)) = 0 Then
AcceptNumbers = 0
Exit Function
Else
AcceptNumbers = KeyAscii
Exit Function
End If
End If
Next i
Else
AcceptNumbers = 0
End If
End Select
End Function
Public Function AcceptAlphabets(Obj As Object, KeyAscii As Integer, MaxDigits As Integer, AlphabetCase As Integer, ParamArray Exceptions()) As Integer
If Len(Obj.Text) = MaxDigits Then
AcceptAlphabets = 0
Exit Function
End If
Select Case KeyAscii
Case 8
AcceptAlphabets = KeyAscii
Exit Function
Case 32 And Len(Trim(Obj.Text)) = 0
AcceptAlphabets = 0
Exit Function
Case 65 To 90 And AlphabetCase = UCase
AcceptAlphabets = KeyAscii
Exit Function
Case 97 To 122 And AlphabetCase = LCase
AcceptAlphabets = KeyAscii
Exit Function
Case 97 To 122, 65 To 97 And (AlphabetCase = BothCase)
AcceptAlphabets = KeyAscii
Exit Function
Case 97 To 122, 65 To 97, 48 To 57 And (AlphabetCase = BothCaseNum)
AcceptAlphabets = KeyAscii
Exit Function
Case Else
Dim i As Integer
For i = 0 To UBound(Exceptions)
If Asc(Exceptions(i)) = KeyAscii Then
AcceptAlphabets = KeyAscii
Exit Function
End If
Next i
AcceptAlphabets = 0
End Select
End Function
Private Function AppearCount(Strl As String, Kee As String) As Integer
Dim Cnt As Integer
Cnt = 0
Dim i As Integer
For i = 1 To Len(Strl)
If Mid(Strl, i, 1) = Kee Then
Cnt = Cnt + 1
End If
Next i
AppearCount = Cnt
End Function
'-----------------------------------------------------------
' Usage
'-----------------------------------------------------------
KeyAscii = AcceptNumbers(Sub1Code, KeyAscii, 4, 1, ".")
KeyAscii = AcceptAlphabets(CourseName, KeyAscii, 50, BothCase, " ", ".")
No comments have been posted about Validates textboxes, comboboxes for correct user input, when a user presses some key.. Why not be the first to post a comment about Validates textboxes, comboboxes for correct user input, when a user presses some key..