LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to add a sub vi to each case statement option?

Is there a way to add a sub vi to each case statement option?

Without opening every case statement and manually inserting the sub vi.

I have a radio button output connected to a case statement.

Inside each case I want to the same vi with just the inputs to the vi changed.

 

Thanks for the help.

0 Kudos
Message 1 of 9
(3,468 Views)

@RickDTS wrote:

Is there a way to add a sub vi to each case statement option?

Without opening every case statement and manually inserting the sub vi.

I have a radio button output connected to a case statement.

Inside each case I want to the same vi with just the inputs to the vi changed.

 

Thanks for the help.


No, but you can right-click the frame and select Duplicate Case.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 9
(3,452 Views)

Just have the subVI outside of the case structure and you can just pass all of its inputs out of the case structure.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 9
(3,441 Views)

@crossrulz wrote:

Just have the subVI outside of the case structure and you can just pass all of its inputs out of the case structure.


I have to agree with crossrulz here..

 

If every single case inside your case structure will have the same VI then that VI does NOT belong inside the case structure.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 9
(3,432 Views)

@RTSLVU wrote:

@crossrulz wrote:

Just have the subVI outside of the case structure and you can just pass all of its inputs out of the case structure.


I have to agree with crossrulz here..

 

If every single case inside your case structure will have the same VI then that VI does NOT belong inside the case structure.


To clarify a bit:

Stuff that changes from case to case, such as different values depending on the case, belong inside the case structure.  Since the subVI will be the same in all cases, it goes outside the case structure.  The subVI gets fed whatever values are inside the case that was selected.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 9
(3,394 Views)

If you have some cases that call a VI, and some that do not, and the cases are the same in one group of situations, you can also specify multiple matches for your Case structure.

 

That may or may not help you...

Example_VI_BD.png


GCentral
0 Kudos
Message 6 of 9
(3,358 Views)

@cbutcher wrote:

If you have some cases that call a VI, and some that do not, and the cases are the same in one group of situations, you can also specify multiple matches for your Case structure.

 

That may or may not help you...

Example_VI_BD.png


Although to make a point of what goes inside the case and outside, the only thing inside the cases should be the strings "Even" and "Odd".

Certified LabVIEW Architect
0 Kudos
Message 7 of 9
(3,277 Views)

@thols wrote:

@cbutcher wrote:

Example_VI_BD.png


Although to make a point of what goes inside the case and outside, the only thing inside the cases should be the strings "Even" and "Odd".


Yes - I meant this as an example with analogies to something like

  • SubVI1.vi and SubVI2.vi
  • SubVI1 and nothing in the other case

but since that wasn't what I actually showed, you're right that the 1-button dialog could (and should) have been outside of the Case Structure.

 

To the OP - the idea is twofold:

  1. You can only see code in one case at a time - if it is the same in all cases, moving it outside means I can more easily identify what changes and what is the same
  2. Don't Repeat Yourself (DRY). If I write the same code twice, then have to fix it, I need to remember to fix it in two places. So don't do this! (repeat identical code unnecessarily)
    • This would also be a reason for a subVI, if some code needed to appear in some cases and not others - then I only write the code in the subVI, not each case...

GCentral
0 Kudos
Message 8 of 9
(3,250 Views)

@RickDTS wrote:

Is there a way to add a sub vi to each case statement option?

Without opening every case statement and manually inserting the sub vi.

I have a radio button output connected to a case statement.

Inside each case I want to the same vi with just the inputs to the vi changed.

 

Thanks for the help.


The truth is: yes, you can automatically add a sub VI to each case statement option.

 

But I doubt it would do you any good. The question should be: "how do I prevent having to put a the same VI in every case of a case structure". That's been answered already.

 

You can automatically put a sub VI (even a different sub VI) in every case of a case structure with scripting.

 

Having said that, it's almost certainly bad advice.

 

Scripting is most convenient for simple repetitive tasks. This is a complex and specific task, and only used a few times at most. Unless you want to change a bad situation (old code, external code), rethink what you're doing. You'd really don't want to use scripting to create those bad situations.

 

If you want to call a different VI for a (large number) of cases, I'd rather look at VI Server or OO (Polymorphism).

0 Kudos
Message 9 of 9
(3,242 Views)