-
I have a variable that can equal oh, let's say, the letter "A", the number "9" or an exclamation mark "!". Is there any way that I can ask the computer "Yo, computer! Is my variable a letter, a number, or a symbol?"
All I need right now is to be able to tell the difference between the letter and number, bu the symbol thing would be nice also.
-
you could try using the IsNumeric function to check for a number.
-
The type of variable you would use is VARIANT and you would use the ISTYPEOF keyword to deduce the type of data held in the variable and the various types including all the common ones can be deduced by applying the VARIANT TYPE CONSTANTS to an if statement.
I do believe it does not work (is not supported) in a SELECT CASE statement and is expected to be used in an IF THEN ELSEIF ELSE kinda statement.
DocZaf
{;->
Look for VARIANT in the helpfile.
VB5 SP3
-
Here is a procedure I made for you. It includes everything you wanted. Have fun with it and let me know if you need anything else.
Code:
Private Sub Form_Load()
Text1.Text = ""
Text1.MaxLength = 1
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim char
If KeyAscii = 13 Then
char = Asc(Text1.Text)
If IsNumeric(Text1.Text) = True Then
MsgBox "It's A Number!"
Else
If (char > 63 And char < 91) Or (char > 96 And char < 122) Then
MsgBox "It's a letter!"
Else
MsgBox "It's a Symbol!"
End If
End If
Text1.Text = ""
End If
End Sub
-
Just in case you hadn't noticed krah, the key to this is that numbers, letters and symbols are in different ranges of the ASCII character set.
All the IsNumeric function does is check if the ASCII code for the character is in the range 48-57 ('0' to '9'). The capital letters are in the range 65-90 ('A' to 'Z') and the lower case letters are in the range 97-122 ('a' to 'z'). All the other characters are either symbols or special characters (ASCII codes 0-32 are special characters, for instance 13 is carriage-return, which is the character the enter key yields).
-