NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

ForEach subscript

Solved!
Go to solution

I am having trouble specifying the Current subscript in the ForEach step.

 

I have a local array of containers called FreqContainer where each container contains three numbers: LoFreq, MidFreq, and HiFreq.

 

On the ForEach Loop tab Array to Iterate Over is : Locals.FreqContainer, Current Element and Current Offset are blank. The Current Subscript  is a string, Locals.Iteration.

 

In a step in the foreach loop I try to access one of the elements using:

 Locals.CurrentFreqMHz = Locals.FreqContainer[Locals.Iteration].MidFreq

 

The subscript causes a problem, it appears to be '[''[0]'']'.

 

Can't find much useful documentation or examples on ForEach.

 

thanks, jvh

 

0 Kudos
Message 1 of 5
(3,827 Views)

You probably need to do "[\"[0]\"]"

 

 

Regards
Ray Farmer
0 Kudos
Message 2 of 5
(3,824 Views)

 


@Ray Farmer wrote:

You probably need to do "[\"[0]\"]"

 

 


Perhaps my post was unclear, In the expression "Locals.CurrentFreqMHz = Locals.FreqContainer[Locals.Iteration].MidFreq", Locals.Iteration is being interpreted as '[''[0]'']'

 

0 Kudos
Message 3 of 5
(3,812 Views)
Solution
Accepted by topic author jvh75021

Assuming you have a single dimensional zero-based array, you should use Current Offset, not Current Subscript.

 

The subscript is a string so that it can return a multidimensional subscript in a single value. To use it in an expression, you would need to call Evaluate such as:

 

Evaluate("Locals.MyArray" + Locals.Subscript) = 10

Message 4 of 5
(3,807 Views)

Thanks James.

 

I have been searching for documentation or an example that delineates the difference between subscript and offset. I think  there could be a little more information on ForEach and examples that use "offsets" and subscripts. Being a text coder, subscript seemed logical to me.

 

Much obliged.

 

jvh 

0 Kudos
Message 5 of 5
(3,777 Views)