NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Can you use case statements in Post-Expressions

I'm trying to figure out how to use the Post-Expression like an if else but I'm having difficulty finding a way to implement for cases that have more than just two options.

 

Anyone ever done this?

0 Kudos
Message 1 of 5
(4,831 Views)

Expressions are just.... expressions. There are no loops, variable declarations, case statements, if/then's, or method definitions.

 

However, you can use the ? :  conditional operators as a substitute for if/then and case, such as:

 

Locals.number =
    Locals.string == "A" ? 1 :
    Locals.string == "B" ? 2 :
    Locals.string == "C" ? 3 :
    4

 

 

The syntax is:

 

<boolean> ? <value-if-true> : <value-if-false>

Message 2 of 5
(4,826 Views)

Yeah, I have a LabVIEW vi that runs the same 9 tests at 3 different voltages, what I was looking to do was use Locals.Index (iterative variable) to determine the ReportText to be written to my datasheet, problem is the ? : only would cover two options, and I need 3 and sometime even more in other tests that perform repetative loops at different voltage levels.

 

I've come across several posts asking this same question, but they were a few years old, was hoping there was a "new" way that I just had not come across yet.

 

Thanks.

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

Can you use multiple ? operators to get more than two options? The example I included did that.

0 Kudos
Message 4 of 5
(4,821 Views)

I'll have to give it a try, but I had already re-coded my program before I got your response, but I thought I had tried a version of this method and TestStand kept throwing evaluation errors because of the ?, which is what sent me to the discussion forums.

 

 

0 Kudos
Message 5 of 5
(4,819 Views)