May 09, 2024, 11:17:08 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


If / EndIf prob

Started by srod, July 25, 2007, 05:17:06 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

srod

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.

srod

Okay, brackets fixed it!  Doh!

:-[

LarryMc

Don't feel bad.

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

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Mark1Up

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

srod

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!

Ionic Wind Support Team

July 25, 2007, 03:53:34 PM #5 Last Edit: July 26, 2007, 04:37:34 AM by Paul Turley
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.
Ionic Wind Support Team

srod

July 26, 2007, 03:14:06 AM #6 Last Edit: July 26, 2007, 04:37:57 AM by Paul Turley
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!