NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Easy Way to Offset Starting Point of ForEach Loop?

Solved!
Go to solution

Does anyone know if there is a simple way to offset a ForEach loop in TestStand to start at some index of the iterating array other than 0?

 

I know the ForEach step has an offset output which can be used to get this offset, but I don't see a way to set this offset.  I was hoping to be able to write a variable assigned to this offset and have the loop start from that but I guess it does an initialization when the loop first runs and resets it to zero.

 

For some insight into the why, I'm looking to implement a recovery function which I can use to restart a test at a specific loop cycle.  I realize this can be done via some expressions but this functionality will need to be implemented in a number of different sequences so I'm trying to avoid having to use a number of expressions which I'd then need to copy/paste between sequences creating a maintenance issue.



I saw my father do some work on a car once as a kid and I asked him "How did you know how to do that?" He responded "I didn't, I had to figure it out."
0 Kudos
Message 1 of 5
(3,577 Views)
Solution
Accepted by topic author blackburnite

Not sure this is exactly what you are looking for but you could use a Bracket array expression operator along with a numeric variable for setting the starting point of the array (aka feed in a subset of the array into the For Each loop).  eg. Local.MyArray[Local.StartOffset..]  

 

Capture.JPG

 

 

Herrlin

Just trying to spread the LabVIEW love.
0 Kudos
Message 2 of 5
(3,529 Views)

This is what I'm currently doing and it technically works, but I have to write a several expressions to clear the start offset out and update my "true" loop offset to equal the current loop offset + the saved star offset and with several nested loops across a number of sequences, it's going to be tedious and prone to errors mistyping variable names, etc.

 

I was just hoping there was some way that I'd missed to basically say "on first call of this loop, don't initialize the current offset variable to zero, that way the functionality I'm looking for would be really clean as I could just initialize the current offset variable directly to a saved starting value.



I saw my father do some work on a car once as a kid and I asked him "How did you know how to do that?" He responded "I didn't, I had to figure it out."
0 Kudos
Message 3 of 5
(3,527 Views)

I don't know if a "simple" way.

 

If I am following you correctly though why don't you just have an expression as the first step of your for each loop that sets your current offset equal to itself + the start offset?  Some thing like this:

 

Locals.CurrentOffset = Locals.CurrentOffset + Locals.StartOffset

 

This way you only have to adjust it in one location.

Herrlin

Just trying to spread the LabVIEW love.
0 Kudos
Message 4 of 5
(3,523 Views)

There turned out to be more complexity with what I needed to do anyhow so this was less of a concern in the grand scheme of things.  Your original post though is effectively the best way to accomplish this.



I saw my father do some work on a car once as a kid and I asked him "How did you know how to do that?" He responded "I didn't, I had to figure it out."
0 Kudos
Message 5 of 5
(3,470 Views)