PDA

Click to See Complete Forum and Search --> : check for letters


chux007
Oct 31st, 1999, 09:07 AM
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)

smalig
Oct 31st, 1999, 04:43 PM
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
smalig@hotmail.com
smalig.tripod.com (http://smalig.tripod.com)

chux007
Nov 1st, 1999, 04:20 AM
thank you but that doesnt help me much if the code i have doesnt work...is there something wrong with the InStr command..

clint_22
Nov 1st, 1999, 04:52 AM
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....

clint_22
Nov 1st, 1999, 04:54 AM
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.

MartinLiss
Nov 1st, 1999, 04:55 AM
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

chux007
Nov 1st, 1999, 05:59 AM
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..