NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Array Element Loop Variables (optional): Current Element -- Suspicion of a bug in the ForLoop step

I think, there is a bug in the ForLoop step.

 

Before I get to the point, the circumstances:

 

My internal loop:

Locals.InternalLoop[0]="Mouse"

Locals.InternalLoop[1]="Cat"

Locals.InternalLoop[2]="Dog"

Locals.InternalLoop[3]="Wolf"

 

My external loop:

Locals.ExternalLoop[0]

Locals.ExternalLoop[1]

 

The external loop is a parent of internal loop (internal is nested)

 

Please execute the sequence attached, and pay attention to the value of Current Element variable which isLocals._IL_currentElement during end of first and start of second iteration of the parent ForEach loop.

 

At the end of last iteration of the internal loop (first iteration of the external loop) the set of values is:

 

Locals._IL_currentOffset = 3
Locals._IL_currentElement = "Wolf"
Locals._IL_currentSubscript = "[3]"

 

However, in the next toss (second iteration of the loop) the set variables above looks inconsistent as the variables are like below:

 

Locals._IL_currentOffset = 3
Locals._IL_currentElement = ""

Locals._IL_currentSubscript = "[3]"

 

IMO all of they should be cleared.

 

I think it is a symptom of the bigger defect, as in my other bigger sequence, the Locals._IL_currentElement is not getting refreshed at all which stopping me using it. It look like at the beginning of the next iteration I still have a "Wolf" as a current element. 

0 Kudos
Message 1 of 4
(4,265 Views)

Where are you setting your breakpoint to look at these values? I am consistently seeing:

 

Locals._IL_currentOffset = 3
Locals._IL_currentElement = ""

Locals._IL_currentSubscript = "[3]"

 

After the end of the inner loop (breakpoint on the end step of the outer loop). After the last loop of a foreach, the flow of execution goes back to the "For Each" step, then jumps to the loop's End step, where the CurrentElement variable is getting cleared/restored. Also, at the beginning of the next run of the inner loop, although the offset and subscript have their old values before the "For Each" step is run, they have the correct new values after the "For Each" step is run. So as long as you aren't accessing these variables outside of the loop, they should have the correct values. I tested with both TestStand 4.5 (2010 f2) and TestStand 2014 and saw the same behavior.

 

Hope this helps,

-Doug

0 Kudos
Message 2 of 4
(4,249 Views)

1. Put the break point at first line,

2. Use F10 key to iterate over,

3. In watch window observe _IL_currentOffset, _IL_currentElement, _IL_currentSubscript

4. You will see that during second iteration of parent ForEach loop situation like that:

 

Before execution (F10 between line 1 and line 2):

 

 

Locals._IL_currentOffset = 3
Locals._IL_currentElement = "Wolf"
Locals._IL_currentSubscript = "[3]"

 

 

After execution (F10 between line 1 and line 2):

 

 

Locals._IL_currentOffset = 3
Locals._IL_currentElement = ""
Locals._IL_currentSubscript = "[3]"

 

By reporting this behaviour I wanted to draw attention to a bigger problem. In other sequence I cannot post it on this forum I have behaviour like the current element is still pointing at the last used element from the prevoius parent iteration. the situation is like that:

 

 

Locals._IL_currentOffset = 0
Locals._IL_currentElement = "Wolf"
Locals._IL_currentSubscript = "[0]"

 

In both these situations there is inconsistency because three different methods of accesing the current element (Current Element, Current Offset, Current Subscript) returns different result.

 

IMO it should be like that:

 

Locals._IL_currentOffset = 0
Locals._IL_currentElement = "Mouse"
Locals._IL_currentSubscript = "[0]"

 

 for sure not like this:

 

Locals._IL_currentOffset = 3
Locals._IL_currentElement = ""
Locals._IL_currentSubscript = "[3]"

 

or like this:

 

Locals._IL_currentOffset = 0
Locals._IL_currentElement = "Wolf"
Locals._IL_currentSubscript = "[0]"

 

0 Kudos
Message 3 of 4
(4,229 Views)

I am not seeing the behavior you describe in TestStand 2010 f2.

 

I set a breakpoint at the first step in your sequence. Did F10 until I got back to the first step. At which point the watch expressions said:

 

Locals._IL_currentOffset = 3
Locals._IL_currentElement = ""
Locals._IL_currentSubscript = "[3]"

 

Not:

 

Locals._IL_currentOffset = 3
Locals._IL_currentElement = "Wolf"
Locals._IL_currentSubscript = "[3]"

 

currentElement being set back to its initial value and the other variables being left alone is the expected behavior at this point in the execution of the sequence.

 

I don't see anything related to foreach in either the f1 or f2 patch notes for TestStand 2010, but you might try installing it if you haven't already. If you do have the f2 patch, perhaps I am still not doing exactly the same thing as you. Are you verifying this issue with the exact same sequence you attached to this forum thread? Please describe exactly what you are doing in as much detail as possible.

 

Another thing to try might be to re-run the version selector to ensure that all of the COM servers for TestStand are properly registered.

 

Also, the intent of those loop variables is that they be used while inside the loop. Outside of the loop to which they apply, you should not be relying on the values of those variables. If your use case has additional requirements beyond those variables being valid and correct while inside the loop, please explain your use case.

 

Thanks,

-Doug

0 Kudos
Message 4 of 4
(4,211 Views)