NI TestStand

Showing results for 
Search instead for 
Did you mean: 

how do i access RunState.LoopIndex

I am executing the test for X times by looping the step.
Is it possible to access RunState.LoopIndex variable.
Thanks in Advance,
0 Kudos
Message 1 of 6


How are you looping on the step?
Are you executing it interactively or you just set the number of loops in the step properties/loop options?
Remember that if you loop on the step interactively you create a new interactive execution and the RunState.LoopIndex is not updated.
If you loop on the step by setting the step's loop options you can access RunState.LoopIndex.

The easiest way to prove it is creating a sequence containing a Message Popup step and displaying the RunState.LoopIndex every time the step is executed.

See attached file.

Hope it helps.

Message Edited by Antonio Lie (NI) on 07-22-2005 01:54 PM

0 Kudos
Message 2 of 6

Hi Antonio Lie,

I am looping the sequence using Step - Properties (LoopOptions).

Trying to access RunState.LoopIndex by Teststand API given below.

TS_PropertyGetValNumber(testData->seqContextCVI, &errorInfo, "RunState.LoopIndex",  0, LoopCount);

Whether the parameter that i am passing is correct ?
0 Kudos
Message 3 of 6
Hi Sivanath:

I'm not sure if you are using TestStand 3.1 or not. In TestStand 3.1 there is a Flow Control step called For...End. You can right click this step and configure parameters for looping here. You can define a new loop variable for Number of Loops and Loop Variable, right click on it and add it to the Locals list. Please see the example program below and let me know if you have any questions.

National Instruments
0 Kudos
Message 4 of 6
Hi Sivanath,
Yes you can use the TestStand API to access the "RunState.LoopIndex" Property.
You could also pass the property as an input parameter to your function.
In the following code I am doing both to give you an idea how it works.
I do not use the input parameter though.
int __declspec(dllexport) __stdcall LoopIndex_Count (CAObjHandle context, double InLoopIndex)
    int         error = 0;
    ERRORINFO   errorInfo;
    char loopIndexStr[1024];
    ErrMsg      errMsg;
    double loopIndex = -1;
    MessagePopup("Loop Index",loopIndexStr);
    return error;
Check the attached example.
Hope it helps.
0 Kudos
Message 5 of 6
Sivanath  -
I do not know if your posted code is exactly what you have in your module, but your LoopCount variable needs to be passed by ref to the GetValNumber function, i.e. &LoopCount.
Scott Richardson
National Instruments
0 Kudos
Message 6 of 6