LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

IF statement in Formula Node

I have the following statement in a Formula Node in LabVEW 7.1:
 
if (x=1) y = 3; else y = 1;
 
When running the VI, whatever the value of X is, I obtain Y = 3 !!!!
 
Why ???
 
Tom
0 Kudos
Message 1 of 4
(3,277 Views)
Try x == 1 (instead of x = 1).
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 2 of 4
(3,271 Views)

The formula node uses c-like constructs, so if you want to check for equality use " if (x==1) ..... "

With a single = sign in the 'test' it becomes an assignment. In C the expression (x=1) has the value of the right hand side of the assignment, here 1 (true) so the true part of the if will always execute. It's a common source of error in c programming.

I presume that this is part of a larger formula, ortherwise you should use native LabVIEW tests.

Rod.

 

Message 3 of 4
(3,268 Views)
Thanks Becktho, thanks Rod !
0 Kudos
Message 4 of 4
(3,258 Views)