11-21-2019 04:03 AM
Dear Labview community,
I got a question that I have frequently encountered, I wonder what is the best solution to this.
Often I need to do an operation to something if a condition is true and there is nothing to do if it is false.
But if I wire that variable.. as in dataflow..then I need to specify what is the false case value. But often I do not need a false case value and it should not be zero either ( as in default if unwired) for example..
What I tried is simply use a property node of my variable and a sequence as shown in the jpg. Attached VI.
Is there a better way of doing this?
Additional question:
To maintain dataflow with a variable, sometimes I used a similar sequence + error control attached to the property node or error in.
Is there a more elegant way instead of using a sequence + an error control to maintain dataflow?
Solved! Go to Solution.
11-21-2019 04:27 AM
As a general rule, it's best to have the controls on the outside of the case structure.
steve
11-21-2019 04:31 AM
Ahhhhh!! Thank you!!! 👍👍
11-21-2019 06:21 AM
And since you're fairly new and learning, here's a little bit of the *why*.
One little bit of "tribal knowledge" us old-timers carry is that the LabVIEW compiler is able to do more efficient optimizations when controls and indicators are placed on the base block diagram, not inside any structures. I think this is especially true if those controls or indicators are assigned as wire-able terminals for the vi.
It's a fine-tuning detail, which isn't really crucial in a lot of apps, but it isn't bad to learn about and develop good habits early.
So while we're on the topic of fine-tuning, there's another small mod worth considering. As shown, the False case will read a value from the control and then write the same value back to it via local variable. It's essentially a no-op. You might consider coding it that way to make the no-op nature clear. See the snippet below.
As for the rule of thumb about putting controls and indicators on the base diagram instead of inside structures, I don't think it applies to local variables, at least not nearly as strongly.
-Kevin P
11-21-2019 08:23 AM
Thank you very much Kevin for the tips! I got some valuable tips from you many times before on other posts. As soon as I have time I will try to search your previous posts on the forum to learn more from you 😉