NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating value expressions dynamically with strings and numbers?

Of course I do!
THIS is working even if I'm not accessing the 2nd element with a constant but with a variable! ( FileGlobals.Data.MyArray[Step.Index].Name )

The problem I'm talking about is:

 I can not replace "FileGlobals" with a variable, runtime-given string.

0 Kudos
Message 11 of 16
(1,496 Views)

Can you post an example sequencefile highlighting your problem.

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 12 of 16
(1,493 Views)
Ok, here we go:
There are 3 Steps (see expressions).
The aim is to get a value from an array which may exist at two different locations. 
 
Explanation:
The first step is OK as I'm specifying the value expression "path" directly.
 
The second one is trying to build an expression at runtime using its local "Step.Scope" string ! Same for the third one. They fail because of a syntax error (I' ve tried many ways there, all of them giving a syntax error, so this one only shows the principle of what I want to do).
 
Please try to rewrite the post expression using "Evaluate(...)", "Step.Index" and "Step.Scope" (without using the conditional operator "?:" ) to create an expression that can get the desired element of the array.
0 Kudos
Message 13 of 16
(1,486 Views)
Quick look at your sequencefile:
 
On the second step you are not changing Step.Index to a string and the second item, dont you need to include Name in the string as Step.MyResult is of type string not Type Info.
 
[SF.Seq[0].Main[1].TS]
Id = "ID#:UfdOFg1uu0+wU3MUymaGrC"
PostExpr = "Step.MyResult = Evaluate( Step.Scope + \".Data.Array[\" + Step.Index + \"]\")"
 
It needs to be of the format
[SF.Seq[0].Main[1].TS]
Id = "ID#:UfdOFg1uu0+wU3MUymaGrC"
PostExpr = "Step.MyResult = Evaluate( Step.Scope + \".Data.Array[\" + Str(Step.Index) + \"].Name\")"
 
Regards
Ray Farmer
Regards
Ray Farmer
Message 14 of 16
(1,475 Views)
I accidentally forgot the ".Name" in my quick example, you're right.
I have changed my expression to the one you provided. First I got an token error because of the dot ("."). Then I ran the sequence, it worked!
 
I made the following mistakes that led to my problem:
- providing the Evaluate expression with ' \ ' included, like: Step.Scope + \".Data.Array[\" + Str(Step.Index) + \"].Name\")". Now I'm realizing that this is only the way TS is storing the value! So in the expression box you can write:  Evaluate ( Step.Scope + ".Data.Array[" + Str(Step.Index) + "].Name" )
- confusing the token error "." with a syntax error: The syntax of " Evaluate ( Step.Scope + ".Data.Array[" + Str(Step.Index) + "].Name" )  " was correct, but the property only exists at runtime!
- using Step.Index instead of Str(Step.Index) !!
 
A very weird mixture of these mistakes have led to the problems I had. Thank you Ray for helping me out so patiently! I'm glad about your help!
Thank you!
0 Kudos
Message 15 of 16
(1,470 Views)

That's ok, still got a bit of hair leftSmiley Very Happy

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 16 of 16
(1,461 Views)