LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stop a while loop in subvi

Solved!
Go to solution

Hi,

I have a subvi which has a while loop, and It is located in my main vi in a sequence structure, I want to stop the loop inside of the subvi using a boolean in main vi.

I tried global variable but It didn't work since the stop botton in my main vi doesn't get updated when the program is running...

could you please help me?

I appreciate any ideas 🙂

thanks:)

Darya

0 Kudos
Message 1 of 13
(8,541 Views)
Why the sequence structure? Why don't you use the stop button on the subVI? Why don't you have the while loop in the main.

A global will work as will a reference in a separate loop but these are often work-arounds for bad design.
0 Kudos
Message 2 of 13
(8,538 Views)

Hi,

i have to use the sequence structure because the main vi controls 5 hardwares and I need delays between each action.

I could try pulling the while loop out of the subvi but If there is a way to stop the subvi from outside it would be better.

and I don't want to use the stop botton in subvi because I don't want too many windows open. and wanna control the program from the main vi.

Darya 

0 Kudos
Message 3 of 13
(8,528 Views)
There is no need for a sequence structure when the delay function has error in/out connections.

As I said, there are ways to stop the subVI. You just can't have the global/reference in the same loop that calls the subVI.

How can you know when to stop the subVI when the window is not shown? How can a user even know that something is running? Sounds like some other design problems.
0 Kudos
Message 4 of 13
(8,522 Views)

the sequence works so no problem with that.

the subvi graphs some values and I can get the graphs in main vi since I passed their references to the main vi. I don't need to have the subvi open while I run the main vi.

as for how the user knows how many windows are running, that doesn't matter.

 I didn't want the user to go to subvi and stop from there.

If I take the loop out of the subvi and put it in main vi it works just fine.

if you can give me a tip for stopping the subvi while loop from main vi, I'll appreciate it.

Darya

0 Kudos
Message 5 of 13
(8,515 Views)
For the last time, use a global or reference in a separate loop.

This same question has been asked numerous times. Have you done a search? How about posting your VI? Since putting the loop inside the main works fine, use that.
0 Kudos
Message 6 of 13
(8,505 Views)

Let me see if I understand this.  You have a (probably bad) design, ask for help, and get suggestions from one of the real experts on this forum.  Instead of saying "Thank you" or "I don't understand, could you please explain", you argue that "there's no problem with my desgn".  Not to mention that you don't actually show any code, making it difficult to be really helpful.

 

I think of myself as a pretty good LabVIEW programmer.  I almost never a sequence structure, and, in fact, would love to see it disappear.  Except in extremely rare circumstances, it is not necessary, and only serves to clutter up the Block Diagram (in my humble opinion).  But go ahead and use it ...

0 Kudos
Message 7 of 13
(8,504 Views)

I'm sorry. I didn't mean to be rude I just didn't see the effect the sequence structure may have on the while loop problem.

I'm not saying my design is perfect! obviously not!

thanks for the replies

 Darya

0 Kudos
Message 8 of 13
(8,489 Views)
Solution
Accepted by daryasea

As a general rule of thumb, you should avoid using Sequence Structures.  The reason being that they break data flow.  If you can control the flow of data with wires, that is the most efficient way to make your program work.  So the suggestion to get rid of your sequence structures is to make another subVI for your wait that also has an Error In and Error Out.  Then you can use the error cluster to force the execution.

 

And having While loops inside of subVIs is a common beginner problem.  If you are controlling when the loop ends based on a front panel control from the mainVI, then the loop really needs to be in the main VI.

 

I hope that was a good summary of what has been said.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 13
(8,474 Views)

Thanks!

I remove the loop then...

 

0 Kudos
Message 10 of 13
(8,467 Views)