08-22-2017 01:39 PM
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.
Solved! Go to Solution.
08-23-2017 12:01 PM
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..]
08-23-2017 12:11 PM
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.
08-23-2017 12:47 PM
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.
09-06-2017 09:55 AM
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.