LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop nested inside a while loop with case structures

I am developing a chemical process control application. I have a while loop that has true and false case structres. The true/false case structure is based on the selection a user makes on the front panel. If the user chose to run on an automatic control mode, the true case is executed; if not the false is executed. Inside the true case there are a series of statements that need to be executed. After a certain line, I want to enter a for loop to iterate for a value 3 times. This value that is being iterated for comes from one of the lines in the while loop. After this I would like to go on and continue with a few more lines in the true case structure in the while loop. How do I go about inserting the for loop within the case structure? The trigger to stop the while loop is pressing the stop button on the program.

 

This is what the strucure is like, maybe to put it across better.

 

Run program

   While Loop

     True/False Selection

         TRUE

           Calculation

           Calculation

           Calculation

                  For Loop

                     Calculation

                  Loop

** Exit For back to TRUE Case

            Calculation

            Calculation

** Exit True

** Exit While

** Stop Program

 

Thanks in advance for your time. Greatly appreciate any inputs.

 

 

       

    

0 Kudos
Message 1 of 9
(4,827 Views)

@AGovi wrote:

This is what the strucure is like, maybe to put it across better.

 


We would prefer to look at a LabVIEW diagram instead.

 

I am not sure why you want to deeply stack structures. Maybe a simple statemachine is all you need.

0 Kudos
Message 2 of 9
(4,823 Views)

To insert a for loop inside a case structure, you simply draw the loop inside the case structure.

 

That's all there is to it.

 

Here I've made the program you described.  I used a "+1" each time you said "calculation."

 

Loop In Case.png

 

There are a few different things we could do with it. Once you try this one out, tell us how it goes and we'll take it from there.

0 Kudos
Message 3 of 9
(4,821 Views)

 

Thanks LandBelenky. Sorry for not providing more information. Here is what I want to do. I missed out on a detail. I have a formula node inside the case structure (pls see fig above). So as soon as LV enters the case structure and then the formula node it automatically completes all the calculations inside the formula node and only then enters the for loop. On the above figure, I want to do b=a*100 and then enter the for loop and then exit the for loop and get back to the formula node, finish doing d=a*b*c and then exit the case and the while.  Is this possible?

 

Thanks!

0 Kudos
Message 4 of 9
(4,809 Views)

Thanks Altenbach. Here is a diagram. of what I am talking about. I missed mentioning the formula node inside the case structure.  untitled.JPG

0 Kudos
Message 5 of 9
(4,808 Views)

Ah. I see now.

 

I don't think you can put a for loop inside a formula node.  I wouldn't even try.

 

A formula node is basically an opportunity to insert some text-based code into a Labview program.  I dislike them because I dislike text-based code.  When I'm working in Labview, I like everything to be in visual code, but that's just my personal preference.

 

The formula node does allow you to write for loops, but these are text-based for loops, not Labview style.  Check out the help topic "Formula Node Syntax".

 

The other approach would be to delete the formula node altogether and do everything with Labview style numeric operations.

0 Kudos
Message 6 of 9
(4,801 Views)

Thanks for the reply LandBelenky. Can I do something like this. 


Create a sub VI that has the calculations before the for loop, another with calculations I want done after the for loop and finally a VI that has the for loop with its calculations. 

 

Inside the true case structure then, can I call the sub VI with calculations before the for loop, then the for loop sub VI, and then the sub VI after the for loop. Does this seem like a good way to go about this?

 

I cannot by pass all the text based code, because we are working on some kind of numerical methods solution to chemical engineering problems. 

0 Kudos
Message 7 of 9
(4,792 Views)

Yes, that would work, but you don't need three separate subVIs to do it.

 

You can put all that code side-by-side inside your case structure.

 

loop and formulas.png

0 Kudos
Message 8 of 9
(4,786 Views)

Placing the calculations inside subVIs is not necessarily a bad thing to do. If needed they can easily be reused. Also, a decent icon can easily convey what is being done. In addition, you can put a description of the calculation in the VI properties and you get a nice context sensative help to assist in making the code more readable. Of course this depends on exactly what is happening in those coalculations. If they are very basic inlining them is not that bad either.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 9
(4,781 Views)