IonicWind Software

IWBasic => General Questions => Topic started by: srod on July 25, 2007, 05:17:06 AM

Title: If / EndIf prob
Post by: srod on July 25, 2007, 05:17:06 AM
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.
Title: Re: If / EndIf prob
Post by: srod on July 25, 2007, 05:22:43 AM
Okay, brackets fixed it!  Doh!

:-[
Title: Re: If / EndIf prob
Post by: LarryMc on July 25, 2007, 06:21:29 AM
Don't feel bad.

I've been bitten by that one more than once.

Larry
Title: Re: If / EndIf prob
Post by: Mark1Up on July 25, 2007, 12:24:21 PM
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
Title: Re: If / EndIf prob
Post by: srod on July 25, 2007, 01:31:04 PM
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!
Title: Re: If / EndIf prob
Post by: Ionic Wind Support Team 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.
Title: Re: If / EndIf prob
Post by: srod on July 26, 2007, 03:14:06 AM
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!