Hi, just wondering if I'm doing something stupid here? :D
The following runs fine:
a = ftStyle&8
If a = 8
blah blah
However, in the following which should be identical, the statements following the If always run regardless of the value of ftStyle!
If ftStyle&8 = 8
blah blah - this always runs!
All variables are of type INT.
Any ideas what I'm doing wrong here?
Thanks.
Okay, brackets fixed it! Doh!
:-[
Don't feel bad.
I've been bitten by that one more than once.
Larry
According to the docs you have a choice of either a Block If (which requires an EndIf statement) or a single-line If which uses a Then followed by the statement to be executed on the same line (if the If is true). I'm kind of surprised that the first example was working for you since I would have though the compiler would have treated it as a single-line If and the next line as an unrelated statement.
-Mark
Hi,
I was usiing a If / EndIf construct in both cases.
The second case seems weird to me; I'd almost put it down as a bug, but oh well brackets saved the day!
Read up on operator precedence ;)
The compiler sees this:
If ftStyle&8 = 8
as
If ftStyle & (8 = 8 )
Since 8 = 8 resolves as TRUE (1) and if ftStyle has it's LSB set to 1 then the statment is true. Adding parenthesis gives you the correct result.
If (ftStyle & 8 ) = 8
Paul.
Quote from: Paul Turley on July 25, 2007, 03:53:34 PM
Read up on operator precedence ;)
The compiler sees this:
If ftStyle&8 = 8
as
If ftStyle & (8 = 8 )
Since 8 = 8 resolves as TRUE (1) and if ftStyle has it's LSB set to 1 then the statment is true. Adding parenthesis gives you the correct result.
If (ftStyle & 8 ) = 8
Paul.
I thought about that but convinced myself this wasn't the problem since I thought ftStyle was typically zero. Turns out that I'd set things up so that the default value of ftStyle was 1! Doh! What a twit! :-[ I should go back to school sometimes!