NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing boolean variables by name in loop

Solved!
Go to solution

Hi everyone,

 

i'm looking for a TS (I am working with TS2019 64bits) command to set multiple boolean variable in a for loop.

My issue context:

I got the following variable: Locals.AllToto (container) with 3 variables inside (Locals.AllToto.Toto0, Locals.AllToto.Toto1, Locals.AllToto.Toto2).

my for loop got the variable Locals.Loop.

 

i need to access to Locals.AllToto.TotoX at each for loop iteration.

I tried the SetValBoolean function but it doesn't work (TS do not recognized this function).

I tried the TS_PropertyObjectSetElementValue but i have an runtime error : impossible accessing the variable Locals.AllToto.Toto0.

 

For an enum, i used Enum("Locals.Enum"+Str(Locals.Loop),"ValEnum").

I want to do the same thing with an boolean in a container.

 

Hope I was clear in my issue's explanation ^^

Thanks for reading and helping me.

 

Regards,

 

 

0 Kudos
Message 1 of 4
(1,221 Views)
Solution
Accepted by topic author Alepar29

Hello,

 

Please find attach a sample sequence file. I used GetNumSubProperties Method to get the number of iteration to perform, and GetNumSubProperties Method to get the name of SubProperties (display by a popup and then used to randomly set true or false to each sub property value)

 

Optionnaly, you also can ignore the SubProperty names and just index them (skipped expression) using GetNthSubProperty Method to get a reference to each SubProperty, and applying SetValBoolean to these references (randomly, again).

 

Hope this helps,

Message 2 of 4
(1,184 Views)

Thanks a lot, it works perfectly.

Just some little modifications to do to adapt it to my code but it is a very good start for my need.

 

I have a question about the command line used by you:

Locals.AllToto.SetValBoolean(Locals.AllToto.GetNthSubPropertyName("", Locals.Loop, PropOption_NoOptions), PropOption_NoOptions, True),

Why did you use GetNthSubPropertyName ? 

and what it's the difference between PropOption_NoOptions and 0 ?

 

The following line seems to do the same thing:

Locals.AllToto.SetValBoolean("Toto"+Str(Locals.Loop),0,True)

 

Regards. 

0 Kudos
Message 3 of 4
(1,166 Views)

I used GetNthSubPropertyName to get a programmatic access to the name of the variable. You can rename your boolean variable to "Titi0", "SampleVariable" or any supported variable name, the expression should still work.

 

By using explicitly "Toto" string, you have "hard coded" constant. It will work, but it is less flexible. Note that you may not need that flexibility, and it introduce a bit more complexity.

 

About PropOption_NoOptions and 0, there is no differences in terms of functionnality. PropOption_NoOptions is a constant related to PropertyObject, that has 0 for value. It is a more explicit way of saying in my expression that I do not want any option. But it takes more characters. So a matter of balance between readability and expression compactness.

 

See here for more details and availables constants : PropertyOptions Constants

 

Regards,

0 Kudos
Message 4 of 4
(1,148 Views)