04-14-2023 10:17 AM
Hello, please see my example code.
I want first loop to call the top loop, multiply 4 by 5 and receive 20 inside that same loop, then I want second loop to call the top loop and multiply 3 by 5 to return 15 into second loop.
This is what I have, it kind of works but the problem is that it is inefficient because it runs through the code every single time. Ideally, I want to call the loop on the top ONLY when conditions of one of the bottom loops is met, pass value back to the bottom loop and continue. I have two commands only, what if I have, lets say 10 commands, wiring will become a mess.
Can I make use of shift registers to achieve what I want?
Solved! Go to Solution.
04-14-2023 10:42 AM
I cannot see your code because I'm running LabVIEW 2019 and 2021, but I wonder if you don't know about sub-VIs? It sounds like your "top loop" should be a sub-VI (what other Programming Languages call a "subroutine" or a "function"), where you pass in two (or more) parameters and it passes out "the answer (or answers).
A sub-routine looks like any other LabVIEW routine -- it has Controls (= Inputs) and Indicators (= Outputs) on its Front Panel. A difference is that you need to use the "Connector Pane", the checkerboard-like thing in the upper right corner of the Front Panel screen, next to the "generic icon"). The top two squares on the left hand side are for "inputs" (which are the Controls on your Front Panel). When you get your cursor over, say, the upper-left square of the Connector pane, you might see it turn into a "wiring spool". Click the upper-left square, then click the first "input/Control". The square should turn the color of the wire associated with the Control (i.e. orange for a Dbl, blue for an Integer, etc.).
An easier way is to select code already on your Block Diagram that you want to make a sub-VI. Select it (don't worry about the wires dangling out), right-click it, and choose "Create Sub-VI" from the Edit menu. Now name it. Open it, and clean it up. Now you can simply "call it" whenever you want to use it. Note how little space it takes (32x32 pixels) -- this can be a great help as you start writing larger, more complex routines.
Bob Schor
04-14-2023 11:13 AM - edited 04-14-2023 11:22 AM
@John32d wrote:
This is what I have, it kind of works but the problem is that it is inefficient because it runs through the code every single time.
I think you need to start with some basic tutorials about dataflow, whatever you have attached is not fixable. It also helps to arrange the front panel elements in a logical way instead of scattering them randomly across the panel. Give all controls and indicators reasonable names that hits at their purpose ("subarray 2", "element 3", etc. are NOT reasonable names!
Here's your diagram so others with lower version can see it
@John32d wrote:
Hello, please see my example code.
I want first loop to call the top loop, multiply 4 by 5 and receive 20 inside that same loop, then I want second loop to call the top loop and multiply 3 by 5 to return 15 into second loop.
To most of us, your description is pure gibberish! Don't explain HOW you want to do it, but WHAT you want to do. You don't "call" things, you just place them into the correct data dependencies. You don't "receive" things, you just out it to an indicator or other code section.
What should the user see after one iteration? How about at the next iteration? How about after an infinite time?
@John32d wrote:
Ideally, I want to call the loop on the top ONLY when conditions of one of the bottom loops is met, pass value back to the bottom loop and continue. I have two commands only, what if I have, lets say 10 commands, wiring will become a mess.
There are no "conditions" in any of the loops. There are no "commands"!. The only user control is the stop button.
04-14-2023 11:34 AM
See if this can give you some ideas.... (I am sure it is not what you want, but maybe you get some ideas.... 😄 )