04-23-2015 01:43 PM
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?
04-23-2015 02:32 PM
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>
04-23-2015 02:44 PM
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.
04-23-2015 02:57 PM
Can you use multiple ? operators to get more than two options? The example I included did that.
04-23-2015 03:06 PM
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.