NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating value expressions dynamically with strings and numbers?

Hello everybody!
 
I'm having a problem regarding passing arguments (DLL-Adapter) from different locations to a function in TestStand 3.5.
Here is what I have:
FileGlobals.Data.MyArray
and
StationGlobals.Data.MyArray
 
Which means there are 2 arrays of the same type, one stored in the sequence and one globally. "Data" is just a container.
 
The type of MyArray is a custom one each element containing a string and a number: Array[n].Name and Array[n].Nr
 
Now I want to pass (string) arguments of the array to a function using a value expression of: FileGlobals.Data.MyArray[Step.index].Name
Whereas Step.index is a local property (number) of a custom step. It's working well!
 
Here is the actual problem:
Since I have to sources, FileGlobals OR StationGlobals, I want to specify dynamically which string to pass.
Therefore I introduced a property Step.ThisIsMyScope . It's a string containing either "FileGlobals" or "StationGlobals".
I have been experimenting in expressions like
Step.ThisIsMyScope + ".Data.MyArray[" + Step.index + "].Name"
or Evaluate(...) , etc.
Nothing worked.
I do not want to use the API, though I managed to do things with getValString and temporary saving the Value in the step, but that's not nice nor transparent enough.
 
May anyone help me?
Thank you very much,
Stefan
0 Kudos
Message 1 of 16
(4,616 Views)

Hi,

have you tried Evaluate(Step.ThisIsMyScope + ".Data.MyArray[" + Step.index + "].Name")
 
or
 
(Step.ThisIsMyScope == "FileGlobals"  )  ?  (FileGlobals.Data.MyArray[ Step.index].Name)  :  (StationsGlobals.Data.MyArray[ Step.index].Name)
 
Regards
Ray Farmer

Message Edited by Ray Farmer on 04-05-2007 10:09 AM

Regards
Ray Farmer
0 Kudos
Message 2 of 16
(4,614 Views)
The first one does not work. ("token" error)
 
The second option is surprisingly good, I even can do something like a switch statement (ok, it's not that good to read, but it works).
So the second work-around is working in my case, although it is not completely dynamic. What if I had wanted to actually "use" the string to build up my expression? Maybe the conditional statement may help me there too, but right now I can't see how?
0 Kudos
Message 3 of 16
(4,615 Views)

Hi,

I think you have to do:

Evaluate(Step.ThisIsMyScope + \".Data.MyArray[\" + Step.index + \"].Name\")

so you dont get the token error

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 4 of 16
(4,613 Views)
No, that's not working: it says "unexpected token : \"   !
0 Kudos
Message 5 of 16
(4,612 Views)

Ok

Evaluate(Step.ThisIsMyScope + ".Data.MyArray[" + Str(Step.index) + "].Name")

The parameter of Evaluate must be a string, and I'm guessing Step.index is a number so convert it to a string.

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 6 of 16
(4,612 Views)
Actually that's what I tried first, because it seems quite obvious to me. Unfortunately this leads to : "unexpected token : . "
TestStand does not like the first dot at --->  ".Data.MyArray[" !
If I remove it, the error is gone but then the property is not correct... Smiley Indifferent
0 Kudos
Message 7 of 16
(4,611 Views)

Hi,

Should that be Data.MyData or Is it DataMyData?  What is the full structure of Data?

I've just tried a similar example which worked for me using TestStand 2.0

Can You post a small example.

Regards

Ray Farmer

 

Regards
Ray Farmer
0 Kudos
Message 8 of 16
(4,609 Views)
Here are two examples that show the full structure of the data assuming that we want to get the 3rd element of each array:
 
FileGlobals.Data.MyArray[3].Name
 
respectively
 
StationGlobals.Data.MyArray[3].Name
 
to clarify it even more:
StationGlobals (Default Top Level)
         |----Data                (container)
                  |-------MyArray        (array of custom type)
 
The custom type contains:
|----- Name (string)
|----- Nr (number)
 
 
I hope it is clear now. How is your structure and the corresponding expression?
0 Kudos
Message 9 of 16
(4,604 Views)

Hi,

I'm not seeing the problem you are having.

if you put FileGlobals.Data.MyArray[2].Name in the expression

Locals.expr = Evaluate("FileGlobals.Data.MyArray[2].Name") do you get the expected value returned in Locals.expr.

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 10 of 16
(4,574 Views)