From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sub vi based on Boolean value

Solved!
Go to solution

Hi,

 

I have a main vi and I want to call a sub-vi based on a Boolean value, i.e. when the Boolean input receives true, the sub-vi should execute, else it should not.

To do this, I added the Boolean control to the connector pane of the sub-vi and I added a while loop in the sub-vi which has "continue if true" condition. I also made this terminal required in the sub-vi.

However, I noticed even if the Boolean value is false the sub-vi keeps executing.

 

Can anybody please let me know what is wrong with this approach?

 

 

Thanks,

Sharmi

0 Kudos
Message 1 of 6
(3,500 Views)
Solution
Accepted by topic author Sharmi

Put the subVI code (or the entire subVI) inside the true case of a Case structure and wire your boolean to that.  I prefer the second option.

 

Formula%20-%20Copy[1]_BD.png

Example_VI_BD.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 6
(3,493 Views)

Your subVI should not contain the loop.  Have just the calculations inside the subVI and put the subVI inside a case structure in your main VI.  The case structure should be controled by your boolean value.

 

What is happening for you right now is the boolean is just controlling a while loop.  The loop will execute at least once regardless.  And if the front panel is not being shown and a TRUE is passed in, the loop will run indefinately.  Not what you want.


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 3 of 6
(3,490 Views)

You did not attach the main VI.

 

Once the subVI is running, it will not know about a control state in the main VI. You could use a reference to the control, wire it to the subVI, and read it inside the subVI via a value proerty node.

 

Still, I think you have some misconceptions in general. Can you tell us what you are trying to do? Is the subVI interactive or does it simply receive the values from the connector? Why does it need to recalculate the same thing over and over as fast as the computer allows?

 

How about simply deleting the FOR loop in the subVI so the result is returned to the calling VI immediately after it is calculated once?

0 Kudos
Message 4 of 6
(3,488 Views)

Use case structure, so if boolean controls is true execute the subvi otherwise no.

0 Kudos
Message 5 of 6
(3,485 Views)

Hi Jim,

 

Thanks so much!

I tried the second option and it worked.

 

Sharmi

0 Kudos
Message 6 of 6
(3,474 Views)