|
-
Jun 21st, 2000, 03:13 AM
#1
Thread Starter
Addicted Member
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.
Is it tired in here or is it just me?
Ryan Williams
-Using Vb6-
-
Jun 21st, 2000, 03:23 AM
#2
Addicted Member
you could try using the IsNumeric function to check for a number.
-
Jun 21st, 2000, 06:50 AM
#3
Fanatic Member
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
-
Jun 21st, 2000, 06:56 AM
#4
Fanatic Member
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
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Jun 21st, 2000, 08:30 AM
#5
Frenzied Member
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).
Harry.
"From one thing, know ten thousand things."
-
Jun 21st, 2000, 11:06 AM
#6
Thread Starter
Addicted Member
Is it tired in here or is it just me?
Ryan Williams
-Using Vb6-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|