M
Matt MacDonald
Hi everyone,
Maybe I'm just discovering something late that everyone else knew already,
but it caught me off guard. In the past I could do an expression like "If 1
<= x <= 10 Then ..." to see if x was in the numeric range 1-10. So x = 5
would evaluate to True, whereas x = 0 would evaluate to False. Well now it
seems that no matter what x is, the statement evaluates to True. I can't
find anything concrete to support my theory, but my guess is that the order
of operations is the problem here. For example.
Rather than the compiler (or whatever) evaluating the above expression as
"(1 <= x) AND (x <= 10) it's evaluating it as "(1 <= x) <= 10". So if x is
5 then the first operation (in the parenthesis) will evaluate to True (or -1
converted to an integer) and if x is 0 then the first operation will
evaluate to False (or 0 converted to an integer). Either way, once the
second expression is evaluated, you will always get True, sinse "-1 <= 10"
and "0 <= 10" both equate to True.
Anyway, sorry for the long winded example, but is my theory correct? If so,
then I would assume that the best way to achieve what I need is "If 1 <= x
AndAlso x <=10". To be honest this situation doesn't come up that often
for me, so it could be that the last time it came up I was using a language
with different syntax rules like C# or C++.
Thanks,
Matt
Maybe I'm just discovering something late that everyone else knew already,
but it caught me off guard. In the past I could do an expression like "If 1
<= x <= 10 Then ..." to see if x was in the numeric range 1-10. So x = 5
would evaluate to True, whereas x = 0 would evaluate to False. Well now it
seems that no matter what x is, the statement evaluates to True. I can't
find anything concrete to support my theory, but my guess is that the order
of operations is the problem here. For example.
Rather than the compiler (or whatever) evaluating the above expression as
"(1 <= x) AND (x <= 10) it's evaluating it as "(1 <= x) <= 10". So if x is
5 then the first operation (in the parenthesis) will evaluate to True (or -1
converted to an integer) and if x is 0 then the first operation will
evaluate to False (or 0 converted to an integer). Either way, once the
second expression is evaluated, you will always get True, sinse "-1 <= 10"
and "0 <= 10" both equate to True.
Anyway, sorry for the long winded example, but is my theory correct? If so,
then I would assume that the best way to achieve what I need is "If 1 <= x
AndAlso x <=10". To be honest this situation doesn't come up that often
for me, so it could be that the last time it came up I was using a language
with different syntax rules like C# or C++.
Thanks,
Matt