Link to home
Start Free TrialLog in
Avatar of WLoftus
WLoftus

asked on

if wrkChar >= "0" then --- and wrkChar = "1" --- why is this return false

Think I am brain dead today.  Look at my code:
'
Dim wrkchar as string * 1
'
for I = 1 to 10
If I > 4 And I <= 10 Then
            wrkChar = Mid(txtBarCode, I, 1)
            If wrkChar >= "0" Then
                MsgResp = MsgBox("Invalid bar code format", vbOKOnly, "Format Error")
                txtBarCode.SetFocus
                Exit Sub
            End If
        End If
Next I
Avatar of Harisha M G
Harisha M G
Flag of India image

Hi,

try

            If Asc(wrkChar) >= Asc("0") Then

wrkChar is a character (String to be precise) and hence you can't use >= operator

---
Harish
Avatar of WLoftus
WLoftus

ASKER

If Asc(wrkChar) >= Asc("0") Then

Did not work, still give a false when comparing against a "1"
Put

MsgBox wrkChar

before the if statement. What do you see?
What are you basically checking ? Checking for digits or non digits ?
"1" > "0" returns True. I suggest that you check that wrkChar really is "1".
may be just use val

ie

If Val(wrkChar) >= 0 Then
Avatar of WLoftus

ASKER

wrkChar really is 1
I resolved the problem with

wrkChar = Mid(txtBarCode, I, 1)
            Select Case wrkChar
                Case "0" To "9"
                Case Else
                    MsgResp = MsgBox("Invalid bar code format", vbOKOnly, "Format Error")
                    txtBarCode.SetFocus
                    Exit Sub
                End Select
       
 -------------

but should I not be able to compare a char 0 to a char 1 with the >= operator.          
       
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WLoftus

ASKER

Ok, I began this question with I am brain dead today.  

The logic should have been:

If wrkChar < "0" And wrkChar > "9" Then

I had it just backwards.  Sorry about that everyone.  How Embarrassing
Thanks and get well soon :)