ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

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,469 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,463 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,460 Views)
Thanks Becktho, thanks Rod !
0 Kudos
Message 4 of 4
(3,450 Views)