NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

possible to use an expression for a property path?

Hello,

I've run into a problem.  I want to use SetNumElements on an array, for which I'd like to vary the first "array" parameter based on an iteration of a loop.   I want to increment the size of a different array for every iteration of a "for each" loop.  The array which the forEach loop is iterating over contains the names of the arrays contained in Parameters.  So I'm trying to use an expression to build the property path within the SetNumElements parameter, but it is complaining.  My expression is:

 

SetNumElements("Parameters." + Locals.CurrentElement, GetNumElements("Parameters." + Locals.CurrentElement) + 1)

 

I get "expected array, found string" syntax error.

 

Is it possible to "build" the property name string in this function?  I see the "evaluate" function, but that seems it will try to return the contents of the property, which I don't want.  I just want to build the array name itself.

 

Thanks for any input.

 

David Jenkinson

 

 

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

Use the Evaluate() expression function.  You can do SetNumElements(Evaluate("Parameters." + Locals.CurrentElement), ......).

 

Allen P.

NI

0 Kudos
Message 2 of 4
(3,099 Views)

So evaluate wants to return the contents of the property, which is contained in the elements I am iterating over.  So I modified my expression to be:

 

SetNumElements(Evaluate ("Parameters.StepTypesToSearchFor[" + Str(Locals.i) + "]"),  1)   /* the 1 is for simpicity while debugging the first part of the expression

 

I get "error in argument 1, expected array, found string" error.  The string value which is being pointed to by the expression is actually the same name as the array I want to resize.  So SetNumElements seems to want the name of the array expressed literally?

0 Kudos
Message 3 of 4
(3,097 Views)

Hello David,

 

It looks like you are evaluating a specific element (in this case that element is a string).

 

Here is a simple example of what I believe your overall objective is:

 

 

Parameters.Random is an array of numerics with 10 elements 

Locals.String = "Random"

 

In my statement step I have:

 

SetNumElements(Evaluate("Parameters."+Locals.String), 1)

 

So essentially we must use evaluate when building an expression for the entire array, not just one element.

 

If the expression you want is contained in that array (ie if Parameters.StepTypesToSearchFor[1] = some string of the array ("locals.array") then you will need another Evaluate() function to evaluate that expression.

 

As an aside, this will only change the size at runtime, the variables (unless they are Station Globals) will return to the defaults when the execution is complete.

With warm regards,

David D.
0 Kudos
Message 4 of 4
(2,965 Views)