03-23-2009 12:42 PM - edited 03-23-2009 12:42 PM
This nugget is the fifth and final in a series of nuggets on Case structures. Today I will discuss some miscellaneous tidbits that are helpful to know when using Case structures.
Case Structure Miscellany
03-23-2009 12:55 PM
Darren wrote:...
- Another tunnel feature that's been around a lot longer (since LabVIEW 6.1) is the "Use Default if Unwired" option on output tunnels. Some people think this is a dangerous option because you're not explicitly setting values for each case, but I find many situations where the option is quite convenient. Especially since I use an error case structure in most of my VIs, it's very handy to not have to worry about wiring anything in the Error case.
- ...
Error case are one of the situations where "use default if..." option is generally OK assuming the down stream code handles the error.
But "use default if unwired" is bad for State Machines and Event structures if that tunnel is holging a reference.
The "BAD" part of using them in Stae Machines or Event structures is that the code will be fine until that one case where someone did not wire the ref across executes and now stuff that seems fine most of the time simply does not work.
I speak from experience about the above exception. One of my rookies set the tunnel as a default and at some latter date another rookie added another Event that was only used once in a blue moon. So the app ran fine until "blue moon" time kicked in and now file writes are throwing errors. Start over everything was fine.
AS a result if anyone asks me to look into a "weird" problem that only happens every now and then, "Use default.." is on my short list.
So....
Ask yourself the question "what would happen if this data was bogus?" before setting tunnels to "Use default if ..."
Ben
03-23-2009 01:12 PM
03-23-2009 01:14 PM
Ben's situation is also mitigated when using Linked Input Tunnels, since new frames will automatically wire-through those tunnels. I have gotten into the habit (as any LabVIEW 8.6+ user should) of making any state wire an auto-linked tunnel in all my state machines and UI event structures.
03-24-2009 05:26 AM
Darren wrote:
...
- Another tunnel feature that's been around a lot longer (since LabVIEW 6.1) is the "Use Default if Unwired" option on output tunnels. Some people think this is a dangerous option because you're not explicitly setting values for each case, but I find many situations where the option is quite convenient. Especially since I use an error case structure in most of my VIs, it's very handy to not have to worry about wiring anything in the Error case.
In the real world, "Use Default if Unwired" is reasonable (see Ben's exceptions); but readers should be aware that you will absolutely lose precious points on the CLD exam if you leave output tunnels "Use Default if Unwired". I've taken the CLD twice, and lost points both times for this. The second time was the difference between passing and failing for me. After that, I started looking at the various libraries that ship with LabVIEW and found that "Use Default if Unwired" was quite prevelant.
If NI can continue to ship code that uses this technique, why are customers dinged for doing the same thing? Sorry to rant, but this is the reason I won't the CLD again. Maybe if I take it using 8.6 and configure Linked Input Tunnels, I might pass; but I've lost interest in certification at this point...
03-24-2009 06:17 AM
I think thatthe "Use Default" causes more problems than it solves. I try to never use this feature but sometimes it creeps in. I wish there was a setting to turn this feature off.
03-24-2009 07:42 AM - edited 03-24-2009 07:43 AM
I use "Use Default" mostly in one case: stop condition boolean for the while loop around an event structure. In most cases the loop shouldn't stop, so the boolean default (False) is fine. For those cases when it should stop (for instance the value change event on the Stop button) I wire it up. Except for this use case I don't use this feature very often.
Daniel
03-24-2009 07:52 AM
dan_u wrote:I use "Use Default" mostly in one case: stop condition boolean for the while loop around an event structure. In most cases the loop shouldn't stop, so the boolean default (False) is fine. For those cases when it should stop (for instance the value change event on the Stop button) I wire it up. Except for this use case I don't use this feature very often.
Daniel
Message Edited by dan_u on 03-24-2009 01:43 PM
Good point!
I use it in those cases as well and its much better than those silly constant people used to wire in through the corner for all non-stopping cases.
Ben
03-24-2009 07:52 AM
Darren wrote:Message Edited by Darren on 03-23-2009 12:42 PM
- There's no trick photography here...that is a missing subVI, but the VI is not broken. This is because of a change in LabVIEW 8.2, where the contents of unexecuted frames of case structures whose selectors are wired to constants are not compiled. Keep this in mind when doing things like putting VIs in a case structure that won't execute just to keep the VIs in memory...they may not actually be loaded at all.
That's interesting. I didn't know that one.
Thanks Darren!
03-24-2009 08:14 AM - edited 03-24-2009 08:16 AM
I have also noticed sometimes new users will use "default if unwired" and it passes something out of the case structure that they are not expecting because they don't know what the default actually is. Something to watch out for.