NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Assignment in conditional expression

Solved!
Go to solution

Shouldn't this work? I get a status error:unexpected token at the 2nd =:

 

True ? Locals.x = 1 : Locals.x = 2

 

Stephen

0 Kudos
Message 1 of 4
(5,861 Views)
Solution
Accepted by topic author stephenb2

You need parenthesis: True ? (Locals.x = 1) : (Locals.x = 2)  Because it takes the first expression available.  In this case Locals.x was the first expression after the :  This means that it doesn't know how to evaluate the rest of the expression.

 

A better way to do this: Locals.x = (True ? 1 : 2)  Of course I understand your scenario might be slightly different and you were just using this as an example.  But I always try to move as much as I can outside of the conditional statement.

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 2 of 4
(5,858 Views)

Thanks, makes sense. Is multiple assignment possible?

 

True ? (Locals.x = 3, Locals.y = 4) : (Locals.x = 1, Locals.y = 5)

 

 

0 Kudos
Message 3 of 4
(5,850 Views)

Yes you can.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 4 of 4
(5,848 Views)