Programmatically Create a File Global Variables in TestStand

Updated Nov 30, 2022

Environment

Software

  • TestStand

This article introduces on how to programmatically create a Sequence File Global variable in the TestStand sequence.

You can create a Sequence File Global variable using the TestStand API either in your sequence or in a code module. The following TestStand API methods can be used to create a new variable of their respective types: 
SetValNumber()SetValBoolean()SetValString()SetValVariant(), and SetValIDispatch().

The following expression can be inserted into a Statement step in your TestStand sequence file to create a new File Global variable: 

RunState.Main.SequenceFile.FileGlobalsDefaultValues.SetValNumber("Numeric1",PropOption_InsertIfMissing,5)

 
where 

  • "Numeric1" is the name of the variable to be created

  • PropOption_InsertIfMissing is the Property Option used to set the method to insert the variable if the variable name does not exist.

  • 5 is the value of the variable


For other solutions you can follow the tutorial to programmatically create variables in TestStand.

Additional Information

This solution will add the file global to the current execution. However it will not be part of the original sequence file. If you want to add the file global to the original sequence file, use the following API calls either in your code module or in your sequence using the ActiveX/COM Adapter:

  1. Get a reference to the Sequence File's FileGlobalsDefaultValues

     
    ActiveX/COM reference: Sequence File
    Automation Server: TestStand API (your current version #)
    Object Class: Sequence File
    Action: Get Property
    Property: FileGlobalsDefaultValues
    Return Value: Locals.FileGlobalsReference
 
  1. Using this reference, use one of the SetVal* methods (any of the functions listed above, for example SetValNumber()) with the options flag set to 1 (insert if missing) to insert a new file global. By creating the file global with the FileGlobalsDefaultValues, the value is stored in the original sequence file. 
     
    ActiveX/COM reference: Locals.FileGlobalsReference 
    Automation Server: TestStand API (your current version #)
    Object Class: Property Object
    Action: Call Method
    Method: SetVal*
    lookupString: "FileGlobals.NewFileGlobal"
    options: 1
    newValue: 123