You can use two TestStand API methods defined in the PropertyObject class:
- PropertyObject.GetNumSubProperties(lookupString)
-
This method returns the number of subproperties belonging to a particular object (e.g. number of local variables, sequence file globals, subproperties of a TestStand container and so on). You can then have a loop with as many iterations as number of subproperties to get the name of each variable using the PropertyObject method described next - PropertyObject.GetNthSubPropertyName(lookupString, index, options) - This method returns the name of a subproperty that the index specifies.
How to correctly use these methods and pass them the correct reference depends on how your code module is called:
- If the code module is called from a step in a sequence you need to pass the SequenceContext to your code module and use it as the ActiveX reference for the PropertyObject methods described above. Please refer to the following instructions, based on your development environment:
- In LabVIEW, you must first call the SequenceContext.AsPropertyObject method and use the return value as the ActiveX reference for the PropertyObject methods. Pass one of the following values to the lookupString parameter: Locals, Parameters, FileGlobals or StationGlobals, depending on the scope of the variables you want to obtain. Do not use the quotes in LabVIEW.
- In LabWindows/CVI your code might look like:
// Get the number of Local Variables
tsErrChk (TS_PropertyGetNumSubProperties (testData->seqContextCVI, &errorInfo, "Locals", &NumOfSubproperties));
for (Index == 0; Index < NumOfSubproperties; Index++)
{
// Get the Nth variable name and store it in the variable called "VariableName"
tsErrChk (TS_PropertyGetNthSubPropertyName (testData->seqContextCVI, &errorInfo, "Locals", Index, 0, &VariableName));
}
- In .NET your code may look like:
// Gets a list of Local Variables
PropertyObject locals = mySequence.Locals;
- If your code module is not called from any sequence or you need the reference to variables defined in a sequence file other than the one calling your code module, then you will not have the SequenceContext available. In this case, you can use the following methods and properties to get an object to be used as the reference for the two PropertyObject methods listed above:
Once you have the desired object (i.e. Locals, Parameters, FileGlobals or StationGlobals object), use it as the ActiveX reference for the PropertyObject methods described above and use an empty string for the lookupString parameter.