06-08-2006 11:19 AM
06-08-2006 11:21 AM
06-08-2006 11:33 AM
06-08-2006 12:05 PM
06-08-2006 12:29 PM
06-08-2006 03:24 PM
06-08-2006 03:44 PM - edited 06-08-2006 03:44 PM
Here again, a shift register is the answer. A case statement must must have an output from each case. In can be data or you can righ click on the output tunnel and select "Use Default". In you case, the default (an empty array) won't work because you want to keep old values. If you use a shift register and in one case, append new results and in the other case just pass the shift register wire straight through.
By the way, about your earlier comment about shift registers versus local variables. It is always preferable to use wires (i.e. like in a shift register) over locals. It is never considered good programming practice to use a local variable just to make the diagram look "prettier". Every time you use a local, you are creating a copy of the data. Locals can also be the cause of race conditions when one part of the program is writing and another part is reading and you have no control of what is happening when. The LabVIEW Style Guide that is part of the shipping documentation has a lot of good recomendations on on your terminals and wires should be laid out in order to avoid 'spaghetti' code.
Message Edited by Dennis Knutson on 06-08-2006 02:45 PM
06-08-2006 04:26 PM
06-08-2006 10:19 PM
Here is a sample vi that shows how I deal with having local variables on a block diagram without having to make controls or indicators on the front panel.
Again, it involves a shift register. Use a cluster to hold all local variables needed, and use unbundle and bundle functions to retreive and store the variables.
You can add any type of variable to the cluster at any time.
06-09-2006 08:59 AM
You did not have to add a while loop around your case statement. You already had a while loop that you should have added the shift registers to. Without seeing your entire program it's hard to say but what you did might present some problems. For one thing, if you stop your program and re-start it without closing it, the inner most while loop's shift register will retain its last value. If you had put the shift register on the existing while loop, you could have initialized it. I think initializing the new one will defeat the purpose. If you have other loops that only execute once, then there may be a basic design flaw in the program but again, without seeing the entire thing, it's hard to say.
I know that moving from traditional, text based languages can be hard. I had to do it myself but once you're over the initial hump and start thinking about how LabVIEW does it and not how would I do that in c++, I think you'll enjoy it.