Re: Simple IF discrepancy :S
Ok so I've isolated the problem quickly to something that is sooo stupid, who ever programmed it should be shot.
If 35 And 65 Then MsgBox "TEST" -> validates
If 37 And 65 Then MsgBox "TEST" -> validates
If you noticed, the AND statement validates WHEN both integers are odd or both are even :S. WHAT THE HELL IS THAT ABOUT? I didn't even know any language does such a useless validation :S.
Re: Simple IF discrepancy :S
Quote:
Originally Posted by INF3RN0666
Ok so I've isolated the problem quickly to something that is sooo stupid, who ever programmed it should be shot.
VB isn't doing anything wrong. You are.
'And' performs a bit-comparison of two numbers. to use your examples:
Code:
1000001 - 65 in binary
0100100 - 36 in binary
-------
0000000 - if both bits are 1 we'll get a 1 in the resulting bit position else we get a 0
the above comes out as 0 which is False
1000001 - 65 in binary
0100101 - 37 in binary
-------
0000001 - the result is 1, which is Not False and hence True
what are you trying to achieve?
Re: Simple IF discrepancy :S
VB Code:
If 36 Then MsgBox "START"
If 65 Then MsgBox "END"
If (36) And (65) Then MsgBox "BOTH"
Try this:
VB Code:
If 36 Then
MsgBox "START"
ElseIf 65 Then
MsgBox "END"
Else
MsgBox "BOTH"
End If
Re: Simple IF discrepancy :S
OHHH bit comparison. I thought it evaluated each term on its own to 1 or 0, then it compared both. DAMN! I was doing InStr in a function and I usually put InStr > 0 but I realized that it should work either way. Now I understand why to put > 0. Thx for your help.
Re: Simple IF discrepancy :S
well you can use a single InStr on it's own like that:
VB Code:
If InStr("aaaa", "a") Then
but once you introduce multiple terms with And / Or / etc. then each part needs to be a Boolean, otherwise you won't get the right results.
Re: Simple IF discrepancy :S
Errr to what variable are you comparing the values against? Those statements will always return True.
EDIT: Or try bushmobile's suggestion