LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I access the value of a loop index outside the loop?

I have a sequence structure in Labview 8.6.  At one frame of the sequence I have a while loop.  The loop runs for a while and then stops and the program then moves to the next frame of the sequence.  Several frames further on down the sequence I have a cluster, the elements of which are outputs on the front panel.  The index of the mentioned loop is one of the cluster elements, an numeric output.  While the loop is running, I want the index to be displayed on the front panel in the output contained in the cluster.  How can I do this?

 

 

0 Kudos
Message 1 of 3
(3,014 Views)

 You can connect the "i" to be a (non-indexed) loop output, and then connect that to a build cluster anywhere.  Does that answer your question or would you like an example?

 

-Matt Bradley

************ kudos always appreciated, but only when deserved **************************




0 Kudos
Message 2 of 3
(3,012 Views)

The easiest way to do this is to use a local variable of your cluster.  You'll need one copy set to read; connect that to a bundle by name, bundle in your index value from the loop, and wire the bundle output to a write copy of your local variable.  You can create a local variable by right-clicking on the cluster terminal (in the block diagram) and choosing create local variable.  You can change the local variable to read or write by right-clicking on it.

 

However, in general the use of both local variables and sequence structures is discouraged, and the right solution may be to rewrite your code with a while loop containing a case structure in which you update the cluster every time through the loop.  This will look like a state machine; you'll also need a shift register in place of the loop iteration counter.  If you post your code (ideally the VI, but if not then a screenshot of the block diagram) then we can provide more useful assistance.

0 Kudos
Message 3 of 3
(2,996 Views)