Results 1 to 6 of 6

Thread: How do I tell if a variable is composed of letters or numbers, etc?

  1. #1

    Thread Starter
    Addicted Member krah's Avatar
    Join Date
    Jan 1999
    Location
    Arkansas, her hyuck!
    Posts
    163

    Cool

    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-

  2. #2
    Addicted Member
    Join Date
    May 2000
    Posts
    188
    you could try using the IsNumeric function to check for a number.

  3. #3
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554

    Wink

    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

  4. #4
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655

    Cool

    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

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  6. #6

    Thread Starter
    Addicted Member krah's Avatar
    Join Date
    Jan 1999
    Location
    Arkansas, her hyuck!
    Posts
    163

    Smile

    Perfect. Thanks people!
    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
  •  



Click Here to Expand Forum to Full Width