Results 1 to 7 of 7

Thread: check for letters

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Location
    Passaic, NJ, USA
    Posts
    4

    Post

    The code below is my check for a letter through a textbox array...it doesnt seem to work since it has a type mismatch at the points with ***

    Thanx in advance.


    Dim i As Integer
    i = 0
    Dim letterCheck(2) As Integer
    Dim searchStr As String
    searchStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    For i = 0 To 2
    letterCheck(i) = InStr(txtValues(i), searchStr)
    If letterCheck(i) = Not (0) Then
    Answer = "LETTER"
    txtValues(i).Text = ""
    Exit For
    End If
    Next i
    *** a = txtValues(0)
    *** b = txtValues(1)
    *** c = txtValues(2)

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Post

    You can check character code with Asc() function.

    For sample:
    If (Asc(your_char)>=65 and Asc(your_char)<=90) or (Asc(your_char)>=97 and Asc(your_char)<=122) Then Answer="LETTER"

    ------------------
    smalig
    [email protected]
    smalig.tripod.com

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Location
    Passaic, NJ, USA
    Posts
    4

    Post

    thank you but that doesnt help me much if the code i have doesnt work...is there something wrong with the InStr command..

  4. #4
    New Member
    Join Date
    Oct 1999
    Location
    Birmingham, Al, United States
    Posts
    10

    Post

    I could be mistaking but you have:

    Dim searchStr As String

    in you code. You're using searchStr as an array. You'll probably have to say something like this.

    Dim searchStr() As String

    You're treating a string like an array. Strings don't have elements. That probably why you're getting errors on the lines that say searchStr(0), searchStr(0), etc. Well, hope that helped....


  5. #5
    New Member
    Join Date
    Oct 1999
    Location
    Birmingham, Al, United States
    Posts
    10

    Post

    Sorry, I looked at txtValues(0) and was thinking you put searchStr(0). I'm not too sure what the problem is now because I don't see how txtValues() is defined. Sorry for the error.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Are you attempting to determine one by one if the characters in a textbox are alphabetic? Is txtValues() a textbox control array? If so then your code has a basic problem in that txtValues(i) will contain the complete text that the user enters in the textbox and not just one character and your comparison will in all likelyhood never be true. To get at one character you need to do something like Mid(txtValues(i), StartPosition, 1) where you would increment StartPos from 1 to Len(txtValues(i)). Also I believe what smalig was trying to show you was that you don't need to build your own compare string (abcde....etc) like you did, because there are features built into VB to do it for you. Finally, you did not show a, b and c Dim'ed in your code. When I Dim'ed them as Strings I got no errors.

    ------------------
    Marty

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Location
    Passaic, NJ, USA
    Posts
    4

    Post

    txtValues() is a textbox control array of 3 elements....
    i want to check through all three elements separately or together for ANYTHING other than a number...for now....checking for letters is fine..
    If txtValues(i) contains only one character...how would teh check occur if the user typed "2b" in txtValues(0)

    i hope this clears it up...not sure though

    a, b, and c are single type since i need them in a calculation..

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