NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing Variables by using their Name from another string

Hey guys,

 

I just started to use TestStand and I have got the following question:

 

I have 2 fileglobals:

FileGlobals.Limit1 and FileGlobals.Limit2

 

The User will define the fileglobals in an INI File and the names and values from the files will first be stored in 2 Arrays.

Array of string: FileGlobals.ArrayNames  (Element 0 is "Limit1" and Element 1 is "Limit2")

Array of number: FileGlobals.ArrayValue (Element 0 contains value of "Limit1" and Element 1 contains value of "Limit2")

 

In one step I check if the name in the array is a fileglobals: In other words: Does FileGlobals.Limit1 and FileGlobals.Limit2 really exist.

PropertyExists("FileGlobals.ArrayNames[0]") and PropertyExists("FileGlobals.ArrayNames[1]") 

 

Now I know that the Globals exist. the next step is saving the values of the Array (FileGlobals.ArrayValue) in the FileGlobals Limit1 and Limit2.

 

Is there a possibility to avoid the following:

Fileglobals.Limit1 = FileGlobals.ArrayValue[0]

 

I would like to use something like this:

FileGlobals."FileGlobals.ArrayNames[0]" = FileGlobals.ArrayValue[0]

I know that the Fileglobal really exists and I know the name of it. This would make later changes in variable names more easier in this case...

 

I hope you know what I mean and you can help me.

Thanks a lot!

 

Walter 

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

Hi Walter,

 

That is possible. Just use following Expression:

FileGlobals.SetValNumber(FileGlobals.ArrayNames[0],0,FileGlobals.ArrayValue[0])

 

 

Regards
Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
Message 2 of 5
(4,694 Views)

You can also use the Evaluate() function to get the reference of your variable.

This function is a little bit magic because if write some thing like this :  "Evaluate(FileGlobals.ArrayNames[0]) = FileGlobals.ArrayValue[0]" it will directly write ArrayValue[0] into the variable described by FileGlobals.ArrayNames[0].

To have this working you just have to ensure that 'FileGlobals.ArrayNames[0]' contains the whole variable name (lookup string): for example "Locals.MyValue" is correct ; "MyValue" alone is not !

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 3 of 5
(4,648 Views)

Hello Juergen,

 

thanks for your answer.

 

Could you save the example for TestStand 2010?

 

Thanks,

Walter

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

Hi Walter,

 

Here you are

 

Regards

 

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 5 of 5
(4,609 Views)