NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically create StationGlobal variable

Solved!
Go to solution

Hello,
currently i have this statement to set all values in an array:
SetElements(StationGlobals.Project.Serial.Response_Array, "-999")

Now i need to replace the ..Serial.. with Serial0, Serial1, Serial2 where the numeric value is the ThisContext.RunState.TestSockets.MyIndex

 

How can i define the StationGlobal to use the addidtional MyIndex for the correct container?

Thanks

0 Kudos
Message 1 of 7
(969 Views)

You mean, you want each socket execution to create theri respective element in the StationGlobals?

StationGlobals.Project.Serial0

StationGlobals.Project.Serial1

.

.

.

?

Message 2 of 7
(961 Views)

Yes, i have four containers and in each of them an array should be set to -999

0 Kudos
Message 3 of 7
(954 Views)
//Create the Serialx Container
StationGlobals.NewSubProperty("Project.Serial"+ Str(RunState.TestSockets.MyIndex),PropValType_Container, False,"", PropOption_SetOnlyIfDoesNotExist),
//Create the Array
StationGlobals.NewSubProperty("Project.Serial"+Str(RunState.TestSockets.MyIndex)+".Response_Array",PropValType_String, True,"", PropOption_SetOnlyIfDoesNotExist),
Message 4 of 7
(935 Views)

The four containers and the arrays already exist i only want to set the array values to -999

0 Kudos
Message 5 of 7
(925 Views)

Hello,
 
in a statement i want to do this (what is not running):

SetElements(StationGlobals.Project.Serial" + Str(ThisContext.RunState.TestSockets.MyIndex) + ".Response_Array, "-999")

When executing a 4x batchmodel it should set all values in the four arrays to -999.
The four StationGlobal arrays already exist
StationGlobals.Project.Serial0.Response_Array
StationGlobals.Project.Serial1.Response_Array
StationGlobals.Project.Serial2.Response_Array
StationGlobals.Project.Serial3.Response_Array

Thanks
@Olil_Wachno, in your reply i can only see four lines in the code, are there more lines hidden after the comma?

0 Kudos
Message 6 of 7
(824 Views)
Solution
Accepted by OnlyOne

@OnlyOne wrote:

Hello,
 
in a statement i want to do this (what is not running):

SetElements(StationGlobals.Project.Serial" + Str(ThisContext.RunState.TestSockets.MyIndex) + ".Response_Array, "-999")



OK, this one took me a bit at first 🙂

If you look at the description 

Oli_Wachno_0-1788785233150.png

 

the first argument of function is an Array. You gave it a string.
To get the Array which the from the String is  referring to, you can use the Evaluate() function like so

 

Oli_Wachno_1-1788785395951.png


@OnlyOne wrote:


Thanks
@Olil_Wachno, in your reply i can only see four lines in the code, are there more lines hidden after the comma?


 

Only those four lines, I misunderstood your question thinking you were asking on how to create the data structure programmatically.

 

 

Message 7 of 7
(816 Views)