Certification

cancel
Showing results for 
Search instead for 
Did you mean: 

when to create a subVI

Solved!
Go to solution

Happy new year folks

 

My question is based on style.

 

Should a SubVI be created with the view of simplifying a main VI or with the view of a general purpose. To make my question more clear i'll state an example. 

 

I have a Cluster of 4 controls and based on the value of one control i must increment or decrement another control. Now, do i pass the complete cluster into a subVI and unbundle inside or Send in only the two controls involved in the process? because the other 2 control valuses would remain unchanged. Doing the former would make a simpler Main VI and the latter would permit me to use this same Sub VI somewhere else.Which is a better practice to use?

 

Thank you

 

0 Kudos
Message 1 of 7
(5,578 Views)

Happy new year to you too.

 

I think the answer to your question heavily relies on how likely you are to re-use the code in the subvi.

 

In principle you can also simply do both at once: encapsulate the common functionality in a subvi. Then encapsulate the subvi in another subvi which does nothing else but fishing out the cluster elements you need for processing. That way you have modularised in a re-usable subvi and have tidied up the code by putting the clunky unbundeling in another subvi which is not going to be re-used.

Message 2 of 7
(5,572 Views)

Thank youj

 

That makes sense. i'm going tobe giving my CLD in a few days. Should i go ahead with this plan for the style? Going on with this stratergy might increase the number of SubVIs of the project. 

0 Kudos
Message 3 of 7
(5,567 Views)
Solution
Accepted by topic author Mayur_VIenthusiast

Yes it increases the amount of subVIs which obviously takes time to create and the CLD is a tight race for points. If you're one of these extremely fast coders you might consider doing that. If you rather say that it is hard enough as it is I would probably prioritise reusability over tidyness. It should be possible to route the wires in a way that it doesn't look too messy even when unbundeling in the main vi.

Message 4 of 7
(5,564 Views)

Personally, I think I may have had 2 subVIs in my CLD.  If you go for the subVI, make sure it is a concise function.  In the exam setup (because of time), go for the ease of reading (which will also be tidyness).  In your exact example, I wouldn't make the subVI unless it was something that I would need in multiple places.


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
0 Kudos
Message 5 of 7
(5,559 Views)

In general I try to stick to this rule of thumb:

 

1 functional area = 1 sub-vi

 

For example take the "Sprinkler example"

 

the sub vi-s that come to mind immidiately are; a Pausable Timer Action Engine, a File IO.vi Action Engine and likely a Dialog for Zone set-up (the dialog may not be in the specs today but, in the real world the client will change the scope and demand it) Slap a nice event driven QMH on the main and the code writes itself in nicely organized cohesive modules.

 

Going back to your example;  You just discribed the "class" "Cluster.lvclass" with 4 properties(W, X, Y Z) and the method "Change Value of Cluster.X based on Cluster.Y"  But why are the other two properties in the Cluster?

 

AH! that brings up the term "Cohesion"  W and Z have no "Purpose" in the Class so you need to re-think your class private data (unless there is an unstated Class requirement)

 

Thinking in OOP terms can help get your data structure in order and that can guide your choices on when a sub-vi is a good idea.


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 7
(5,547 Views)

Mayur,

 

The LabVIEW style guide mentions using SubVIs for both "Logical divisions of labor or potential code reuse".  I would tend to lean towards more general if you can because it gives you more options to reuse it in the future.

 

Personally I used 2, maybe 3, SubVIs in my CLD.  One was a big block of logic that didn't really fit on my Main VI which was used once and the other was a general purpose VI that I used in a bunch of places.  As far as I remember there were no mentions or SubVI use when I got my CLD back.

Matt J | National Instruments | CLA
0 Kudos
Message 7 of 7
(5,541 Views)