NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing multiple values in one case statement

For example:
 
Select (locals.a)
Case (5,10,18,29)
{
locals.B==9
}
 
How would I accomplish something of this sort?  
 
Thanks Smiley Happy
Message 1 of 3
(4,837 Views)
Hi Falcon,
 
You can accomplish what you want to do; however, it can get a little ugly. In TestStand, the case structure evaluates the expression and then passes the value of the entire expression back to compare with the select. I'm sure you saw this if you tried 5 || 10 || 18 || 29, which should have returned a 1. Because this is how TestStand handles the case statement, in order to place multiple cases on the same statement you need to construct a statement as such:
 
Select (Locals.a)
Case(Locals.a == 5 ? 5 : Locals.a == 10 ? 10 : Locals.a == 18 ? 18 : Locals.a == 29 ? 29 : -999)
{
     Locals.b = 9
}
 
In this statement, it evaluates whether Locals.a is 5 and then returns 5 (which would cause the select statement to choose the case) or checks if it is another value. The -999 will return if Locals.a fails all of the conditional statements and is a value that I should not ever show up in my select statement.
 
As you can see, it is a very ugly statement. Instead, I would recommend using If/Else If/Else statements for your flow control. While the statement is still long, it is a bit cleaner and easier to read.
 
If(Locals.a == 5 || Locals.a == 10 || Locals.a == 18 || Locals.a == 29)
{
     Locals.b = 9
}
 
 
Matt M.
National Instruments
Message 2 of 3
(4,814 Views)

Hi Matt,

 

For logic

 

If Locals.ResourceInfo.A == "123":

    Values = Locals.Array1

else If Locals.ResourceInfo.A == "456":

    Values = Locals.Array2

else: 

    Values = EmptyArray

 

How to write the statement in one line for values of parameters ? I tried following one line but syntax error

 

Locals.ResourceInfo.A == "123" ? Locals.Array1 : Locals.ResourceInfo.A == "456" ? Locals.Array2 : EmptyArray

 

BigDrum_0-1717003894853.png

 

0 Kudos
Message 3 of 3
(276 Views)