11-07-2012 11:08 AM
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
Solved! Go to Solution.
11-07-2012 11:17 AM - edited 11-07-2012 11:21 AM
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.
11-07-2012 11:21 AM
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.
11-07-2012 11:21 AM
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?
11-07-2012 11:23 AM
Use case structure, so if boolean controls is true execute the subvi otherwise no.
11-07-2012 12:10 PM
Hi Jim,
Thanks so much!
I tried the second option and it worked.
Sharmi