05-17-2010 10:48 AM - edited 05-17-2010 10:58 AM
Hi, I'm just about satisfied with a rough draft of my program, but I've found now it will enter into an infinite loop. This is what I want the program to do:
1. enter money
2. press a button for selection
3. calculate change
4. reflect calculated change at the input
5. terminate program
I've got 1-3 to work, but when I reflect the change at the original input this is where it enters a crazy loop. Is there an easy way to terminate from a case structure? When I tried doing this, as you can see in my code, it terminates the program but it doesn't calculate change at all. I'd like it go in sequential order, then terminate. Sorry if my code is messy too, it's rough draft so far. I'm using verison 8.2
**edit: this version I've put the stop commands on each case structure that calculates change, and the program just terminates. Without these added it enters the crazy loop.
05-17-2010 12:36 PM
05-17-2010 01:32 PM
OMG. (sorry for the chat abbreviation). I have to agree with Jim. The entire vi needs to be re-written from scratch. A state machine is the way to go. Using the Labview Stop function is bad practice. If other parts of the code are still executing, like a loop in mid loop, they will come to a halt when the first Stop is executed. My suggestion to JJJ is to study the state machine architecture (look for examples), then re-write the code using a state machine. Post your re-write and ask for help. I don't think anyone would want to try to fix your current vi.
05-17-2010 01:33 PM - edited 05-17-2010 01:34 PM
Piece of donut? Not a fan of cake huh?
A
few pointers for the OP:
- Try to avoid the 'Stop' function, it doesnt do exactly what you think
it does. It will literally halt your program, instead of stopping just
the current loop. This is not generally a good idea, because usually
after a loop there are some loose ends (punn intended) that should be
cleaned up.
- You have too many local variables. This will cause race conditions in your code if you are not careful.
- As Jim said, you should think about re-writing the code using a state-machine architecture. This will help avoid your a lot of your boolean acrobatics Feel free to ask questions if you are unsure how to set up a state-machine.
Edit: tbob pretty much beat me to the punch on this one haha