NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How To Dynamically Create Variables Within An Expression?

I am attempting to create a sequence file through the TestStand API.  The sequence steps consist of Statements containing Expressions.  I can create the Statement steps, but need to create the variables contained within the statement.

 

1. Is there a way for TestStand to automatically create variables within an expression?

2. Is there a way for TestStand to detect the type of variable that should be created?

 

 

Thanks!

CLA, CTA
0 Kudos
Message 1 of 6
(7,625 Views)
If you are using TestStand 4.0 or higher, you can use API in expressions to do this.  The easiest way is to use the PropertyObject class and use the InsertIfMissing option.  You could set the value at the same time using this.  Locals.SetValNumber("NewVar", 15, 0x1) would set a new variable called Locals.NewVar to 15.
0 Kudos
Message 2 of 6
(7,612 Views)

Allen,

 

Thanks for the reply.

 

1.  Is there a way for TestStand to automatically create variables within an expression?

It seems the SetValNumber function could be used to "declare" variables using expressions during runtime/dynamically.  Is it possible for this "automatically" (without additional expression lines) to occur?

 

 

 

2. Is there a way for TestStand to detect the type of variable that should be created?

 

I am trying to determine the best way of extracting variables (and expected types) from an expression.  I am currently using a LabVIEW VI that searches for "Locals.","FileGlobals.", or "StationGlobals." and also validating the expression using the Expression.Validate method, but is there a way for TestStand to return the expected type of a variable?  Then the proper SetValString, SetValNumber, SetValBoolean, ... could be called.

CLA, CTA
0 Kudos
Message 3 of 6
(7,587 Views)

I'm not sure what you mean by automatically.  There is no way to do this without using the API.  You'll have to have a step that creates the variable if it does not exist, or call the API from a code module or expression to set the value.

 

Each variable has a type associated with it, so you can use the PropertyObject.Type property on each of the variables.


If I have misunderstood something about what you are trying to do, let me know. 

0 Kudos
Message 4 of 6
(7,580 Views)

I am developing an application that will convert a text file of expressions into a TestStand sequence file using the API. My goal is to extract and create required variables from expressions written in the text file.  I can currently identify variables, but need to determine the variable type for each expression.

 

My question to "automatically create" is derived from the EvalOption_CreateNonExistentVariables option of the Evaluate method (see below)

 

 

Evaluate Method

Syntax

Expression.Evaluate ( evaluationContext, evaluationOptions = EvalOption_NoOptions)

Return Value

PropertyObject

Returns the result of the expression in the form of a PropertyObject. The PropertyObject can contain a value of any type depending on the expression. Release the result when you finish using it. If the expression is empty and you pass EvalOption_AllowEmptyExpression, this method returns a NULL dispatch pointer or object reference.

Purpose

Evaluates an expression and returns the result.

Parameters

evaluationContext As PropertyObject

[In] Pass the context in which to evaluate the expression. This method uses this object to locate variables the expression specifies.

evaluationOptions As Long

[In] Pass 0 to specify the default behavior, or pass one or more EvaluationOptions constants. Use the bitwise-OR operator to specify multiple options.

This parameter has a default value of EvalOption_NoOptions.

 

 

EvaluationOptions

EvaluationOptions Constants

These constants represent the options you can use with the evaluationOptions parameter of the PropertyObject.EvaluateEx, Expression.Evaluate, Expression.Validate, ExpressionEdit.Evaluate, and Engine.CheckExpression methods. Use the bitwise-OR operator to specify more than one option.

  • EvalOption_AllowEmptyExpression–(Value: 0x2) Use this option to prevent TestStand from treating empty expressions as syntax errors.
  • EvalOption_AllowIndexingEmptyArrays–(Value: 0x4) Use this option to make TestStand return a value whose type is the array element type for empty arrays with subscripts. If this option is not specified, TestStand treats an empty array with subscripts as an error.
  • EvalOption_CreateNonExistentVariables–(Value: 0x8) Use this option to have TestStand create temporary objects for variables in an expression that does not exist. This option is useful when evaluating an expression for error checking if the expression might contain dynamically created variables.
  • EvalOption_DoNotAlterValues–(Value: 0x1) Use this option to prevent TestStand from altering the value of any variable or property the expression contains. This value is not used by the Expression.Validate and Engine.CheckExpression methods because they never alter values.
  • EvalOption_NoOptions–(Value: 0x0) No options.
 

 

CLA, CTA
0 Kudos
Message 5 of 6
(7,572 Views)

That option will only create them during the evaluation so that any variables that don't exist won't cause an error.  The type information will have to be stored somehow within the text file, as there would be no way to know what type of variable to create.

0 Kudos
Message 6 of 6
(7,563 Views)