LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to store a single value embedded in several loops

I have a situation where I have 3 while loops embedded inside one another and I need to pass a single value obtained from the first iteration of the central loop.  I have thought of a few ways to do this, but I'm not sure which is the best or most efficient.  The two ideas I have are to either use shift registers (which can get messy with 3 loops) to store the value, or to write to a local variable only once and then read it out later.  Right now I'm using a combination of shift registers and auto-indexing, and finding the first value after the loops have completed.  It works, but it doesn't seem very elegant.  I'd love to hear some new suggestions or some thoughts about using local variables vs. shift registers.
 
Any help would be appreciated.
 
Ken
0 Kudos
Message 1 of 4
(2,732 Views)
Ken,

Do you need the value while the loops are running only after they have finished?

If after finished, shift registers and a case structure or a select node is probably best. Passing data via wires is almost always the best way to move data in LV.

If you need the data in a parallel loop while the loop which generates the data is still running a queue or notifier may be a good choice. An Action Engine is also good, but may be overkill for your applicaiton. Local variables can be used, but are prone to race conditions and may force a switch to the UI thread. Many experienced LV programmers rarely use locals and almost never for that application.

Lynn
0 Kudos
Message 2 of 4
(2,726 Views)


@halvorka wrote:
The two ideas I have are to either use shift registers (which can get messy with 3 loops) to store the value,

Not really that messy :). let's assume that the innermost loop sees all iteration (i.e. is not inside a case structure), all you need in an unintialized shift register in the innermost loop as e.g. shown in the figure.


Message Edited by altenbach on 08-30-2007 01:57 PM

Message 3 of 4
(2,724 Views)
Thank you both for your responses. I actually just realized on the way into work this morning what altenbach said - that I only need the shift register on the innermost loop. I think this is probably the best way, as you both suggest.

However, I was thinking of using the first call function (which I've never used before) to the T/F selector instead of comparing the sum of the three "i" values to zero as in altenbach's diagram. Is there any downside of this approach compared to the diagram already proposed?

Thanks again for the suggestions...

Ken
0 Kudos
Message 4 of 4
(2,690 Views)