Check The Type Of Character

Easily check if character is upper case, lower case, alpha or numeric using API.

Preparations

Add 1 Text Box to your form.

Module Code

Declare Function IsCharUpper Lib "user32" Alias "IsCharUpperA" _
  (ByVal cChar As Byte) As Long
Declare Function IsCharLower Lib "user32" Alias "IsCharLowerA" _
  (ByVal cChar As Byte) As Long
Declare Function IsCharAlpha Lib "user32" Alias "IsCharAlphaA" _
  (ByVal cChar As Byte) As Long
Declare Function IsCharAlphaNumeric Lib "user32" Alias _
  "IsCharAlphaNumericA" (ByVal cChar As Byte) As Long

Form Code

Private Sub Text1_KeyPress(KeyAscii As Integer)
'1 - True, 0 - False
   MsgBox "Upper Case: " & IsCharUpper(KeyAscii) & _
   " Lower Case: " & IsCharLower(KeyAscii) & _
   " Alpha: " & IsCharAlpha(KeyAscii) & _
   " Alpha or Numeric: " & IsCharAlphaNumeric(KeyAscii)
End Sub

Go Back