LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop nested inside a Case Stucture....

Hello everyone,

I'm a total n00b here.  Working on a school project in LabVIEW and its bugging the heck out of me.  Been stumped on this problem for a few hours.  Its probably very easy but I haven't had any FORMAL training in the application.  Anyways...

I have a Case Structure, and in the False Case I basically have it setup to where the variable X (write to)  = X + Y (Read from).  I want it to calculate a new X just once, so I thought a For loop would work to do this everytime the Case is False.  Unfortunately, when I run the VI it gets stuck in an infinite loop and X continually changes (in increments of Y) until the Case changes to True.  Maybe, I'm overlooking some small detail, but does anyone know how I might go about doing what I mentioned above?

Thanks,
Jeremy
0 Kudos
Message 1 of 10
(3,744 Views)
 
You say you want to calculate a new X just once. So why do you want to use a "For loop" which is used to repeat the code several times?????
 
I don't understand your point!
 
0 Kudos
Message 2 of 10
(3,733 Views)
Your description is full of contradictions. ( e.g. "calculate just once" vs. "everytime the case is false" in the same sentence).
 
If you want to do something "just once", adding a FOR loop is very counterproductive!!! 😉
 
Maybe you can attach a simple version of the code you made so far so we can get a better understanding.
0 Kudos
Message 3 of 10
(3,730 Views)
Well, INITIALLY, I didn't have a FOR loop.  It would calculate X continually without the FOR loop though.  I will post a screen shot of the part of the VI I am working on.  I actually got it wrong in my first post.  The True Case is actually the case I had put the FOR loop in.
0 Kudos
Message 4 of 10
(3,731 Views)
Please post some real code (Attach a VI). These images make no sense whatsoever. 🙂
0 Kudos
Message 5 of 10
(3,718 Views)
This is just a small part of a much larger VI that is complex and pretty messy right now.  I haven't taken the time to make it look good, but up until this point it has worked.  I wouldn't want to post it and then get critiqued on everything else in the VI.  I'm only looking to solve this one problem right now.  I will post it if you really want me to though.
0 Kudos
Message 6 of 10
(3,709 Views)
It seems to me there is a fundamental misunderstanding of dataflow programming.
 
If you place a FOR loop around something and wire a "1" to N, this is the same as leaving the FOR loop out in this case. Everytime, this FOR loop is encountered in the dataflow, it will execute for one iteration. It does not mean the code executes only once overall. Is all this in a bigger loop somehow or are you running this with the "continuous run" button?
 
Your code is just peppered with local variables, but none is called X as in your text description.
 
You shouldn't be afraid to post code. You already said that you just started with LabVIEW, but had no formal training. I am sure you'll get the best benefit if you let us look at the program and point out ways to improve it. If you don't, bad ideas will become bad habits very quickly and it will be harder to un-learn them later. 🙂
0 Kudos
Message 7 of 10
(3,700 Views)
You're right, I understand that not having a For loop is the same as running it one time.  I realize that after having tried the For loop, but initially I didn't have the for For loop and it seemed to have the same result.

My description in the beginning is a lot different than my code because I simplified it and combined some local variable in my head thinking that my description would be enough to figure out what was going wrong. X is "Initial Fill Value (g)" and Y is "Upper Limit" - "Fill Column Lower Limit".

The "Total Consumption (g)" variable is not really part of the problem (at least from what I can tell).  It is functioning as it should in my front panel.

I will post a copy of the VI for you to take a look at and I apologize if its hard to follow.  I have worked on it with a few different people (who are gone for a few days) for a few weeks or more.  I will do my best to answer if you have any questions about it.  I had to convert some of the DAQ assistants to custom sub VIs and I didn't attach them, but I don't think they should be necessary.

@altenbach wrote:
It seems to me there is a fundamental misunderstanding of dataflow programming.
 
If you place a FOR loop around something and wire a "1" to N, this is the same as leaving the FOR loop out in this case. Everytime, this FOR loop is encountered in the dataflow, it will execute for one iteration. It does not mean the code executes only once overall. Is all this in a bigger loop somehow or are you running this with the "continuous run" button?
 
Your code is just peppered with local variables, but none is called X as in your text description.
 
You shouldn't be afraid to post code. You already said that you just started with LabVIEW, but had no formal training. I am sure you'll get the best benefit if you let us look at the program and point out ways to improve it. If you don't, bad ideas will become bad habits very quickly and it will be harder to un-learn them later. 🙂




0 Kudos
Message 8 of 10
(3,691 Views)

Jeremy,

What you may be looking for is the "First Call?"  function, located in the pallette Advanced -> Synchronization. Instead of a For loop, surround the code you want to execute only once with a case structure that is wired to the output of the "First Call?" function. This will cause it to execute only the first time that section of code is run. See the help for an explanation of the function.

I hope this helps. Don't get discouraged - we all started somewhere and may have forgotten over the years that what seems so elementary now was at one time something we didn't know.

Allen

weekleysystems.com

 

 

 

 

 

0 Kudos
Message 9 of 10
(3,685 Views)
First call didn't work for me, but I got some help with it from my brother and figured it out.  Thanks for everyone's help though.
0 Kudos
Message 10 of 10
(3,633 Views)