LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with While loop

I am using a while loop for a program I have written, becuase I need to
use shift registers. However, I also have some indicators within the
while loop that I need to take a reading from. When I run my vi, it will
not allow those values to leave the while loop. Is there any way that I
can make the while loop let me do this? I can do a bit of rewriting if
not, but it will be a major PITA to do so, so I'd rather not. In other
words, if it isn't a simple explaination, don't worry about it.

Harry


--
"Little Joe for the Big Heisman, '99"
0 Kudos
Message 1 of 10
(3,509 Views)
Harry King wrote:

> I am using a while loop for a program I have written, becuase I need to
> use shift registers. However, I also have some indicators within the
> while loop that I need to take a reading from. When I run my vi, it will
> not allow those values to leave the while loop. Is there any way that I

Harry,
The values in a while loop will not leave until the loop finishes.
The only way to get the values out while the loop runs is to use
global or local variables. Of course you must put this local
in a while loop also or it will only read the value once.

Kevin Kent
0 Kudos
Message 2 of 10
(3,510 Views)
Now I do have a while loop and I tried a local, and a global and neither one is updated while I have both of them in the while loop itself.  Any ideas?
0 Kudos
Message 3 of 10
(3,337 Views)

The easiest solution would be to place the terminals of these indicators inside the while loop.

(Maybe you can attach a simple example of your code so we can point out where the problem is.)

0 Kudos
Message 4 of 10
(3,328 Views)
O'k.  The while loop is in the subvi Auto VI-700.  Basically the subvie calculates outputs the increment based on the lower and uppper limits and feeds it into the Main Vi.  the programm is not finished so it's sort of messy.  The thing is that no matter where the ouput is withing the loop or outside of the loop I need to spit it out to the main VI and it would only do that with the last value.
Now I know I probably should use the for loop instead, but it builds an array on the output and it's gonna be a big PITA to interprete the array into what I need.
0 Kudos
Message 5 of 10
(3,309 Views)
If you wanted to see the results in your main program while the subVI is running, you need to put a read of the global variable in the main VI. The main VI that you posted won't work though because it doesn't have a while loop to keep reading the globabl. Do NOT use run continuous for anything except test purposes. You could also accomplish the same thing with a control reference that you pass to the subVI. The subVI does generate an array so I don't understand your comment about the for loop and the 'big PITA'. Do you really need to return all of the values in the array or just the increment? You code is overly complex if you just need the current increment value.
0 Kudos
Message 6 of 10
(3,298 Views)
I don't have a read in the main VI because I can't get the subVi to work.  All i need is to read each iteration of the subvi within the main vi?  If I remove the while loop from the subvi and put it in the main vi would that work?
0 Kudos
Message 7 of 10
(3,296 Views)

Your main vi just calls the subvi.  The main serves no purpose.  Just make the subvi the main vi.  Get rid of all those local variables, none of them are needed.  By putting the array indicator inside the loop, you will see an update every loop iteration. 

If you have to call this from a main, then do this.  In the main, create an identical indicator.  Create a reference to that indicator.  In the subvi, create a similar reference type.  Pass the main reference to the subvi reference.  In the subvi, create a value property node for the reference.  Inside the loop, write the output to the value node.  Everytime the loop executes, the value node will be updated and the main will display it because it is passed by reference.  What happens is that because of the reference, the main indicator is sharing the same memory space as the subvi value node.  So a change in one is seen in the other.

Another way to get the info from the subvi to main is to open a reference to the subvi in the main block diagram.  Use property nodes to get the subvi front panel controls.  Search by lablel to get the indicator you are wanting to display.  Use a value property node to obtain the value and update your main indicator.  I have attached an example.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 10
(3,281 Views)
Can you repost your VI in 7.0 as I can not open them and have a similar question.
0 Kudos
Message 9 of 10
(3,245 Views)

Here ya go:

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 10
(3,235 Views)