NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Traversing through Array

I am trying to have an array of say size 30 and I want to traverse through it one by one and display the results digitally.
I tried using INDEX ARRAY function but keeps on giving me a constant value and does not traverse through to the next element after displaying first one.
Any advice please.
0 Kudos
Message 1 of 3
(3,210 Views)
Hi,

I'm not sure I understand what function you tried to use. If it's the PropertyObject.GetArrayIndex, then the function will always return the array index string at a given offset in the array.

The clasic way of traversing an array is to define an index for iterating, for example: Locals.index.
Next insert a Label and a GoTo step.
The GoTo step has to be configured as follows:
1. Destination - 'Label'
2. Precondition = Locals.index < GetNumElements(Locals.Array)
3. PostExpression = Locals.index++

In between the Label and GoTo step place your steps for accessing the array elements, based on the Locals.index.

Hope this helps,
Silvius
Silvius Iancu
0 Kudos
Message 2 of 3
(3,200 Views)
What Silvus said is correct, but there are a couple things that you may want to keep in mind.

1. If you have TestStand 3.1, there is a "For Each" function that will loop through the arry for you.

2. If using TestStand 3.0 or earlier use something like this (don't forget to initialize the Index:
Assume array size of 30, from 0 to 29,

Statement Step: Initialize the Locals.nIndex=1
Label Step: Top Of For Loop
Steps for Array: Calulate Array Value...
Expression: Locals.nMyArray[Locals.nIndex]= ...

Goto Step: Goto Top Of For Loop,
Precondition: Locals.nIndex<29
Post Expression: Locals.nIndex++ 'Increment the Index

Mike
0 Kudos
Message 3 of 3
(3,190 Views)