Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

question about If/Then statement


lespedeza Oct 11, 2010 08:35 PM

I may be missing something obvious, so please help me out if I am. I have the following statement in a program for the CR206 (OS just got updated to v10).

If (condition1) AND (condition2) AND (condition3) Then
thenstatements
EndIf

In my program,

condition1 evaluates to 0 (false)
condition2 evaluates to -1 (true)
condition3 evaluates to 0 (false)

yet, the thenstatements are executed even though they shouldn't be.

In my efforts at debugging, I also put the following statement in my program

x = condition1 AND condition2 AND condition3

x also equals 0 (false) after execution of the above statement, so I'm not sure why the thenstatements are being executed in the above if example.

I was always taught that "false and true and false" should evaluate to false, but for some reason inside the if statement it is evaluating to true in my program.

Any help would be appreciated.

Thanks.


lespedeza Oct 11, 2010 08:48 PM

The only way that I can get this to work is by doing the following

boolean1 = condition1 AND condition2

If boolean1 AND condition3 Then
thenstatements
EndIf

I've also tried grouping with parentheses, but to no avail. The following doesn't work either

If (condition1 AND condition2) AND (condition3) Then
thenstatements
EndIf

Nor does this

If ((condition1 AND condition2) AND (condition3)) Then
thenstatements
EndIf

Why can't the If statement handle a compound expression to evaluate for the condition? Is this a bug?

Thanks.

* Last updated by: lespedeza on 10/11/2010 @ 3:11 PM *

Log in or register to post/reply in the forum.