LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Should I make a SubVI to clean up my top level VI?

Hello,

this is a question more about LabVIEW styling and what is proper. I am refactoring code of a state machine and one of the states has a lot of loops in it. A lot of True/False states with stacked sequence structures nested in each other. It looked really messy, so I've started to clean it up by making bigger loops and structures into SubVIs. I feel iffy about this because these SubVIs will only be used once in the entire project and I am only making them to make the front panel cleaner and easier to follow. Is this stylistically alright, or is it a bad habit to overuse SubVIs like this?

0 Kudos
Message 1 of 4
(2,622 Views)

I would say it is definitely good practise to use SubVIs to clean up your code even if each SubVI is only used once. Just try to make sure to divide up your code into logical components and be careful with documentation, icons and SubVI names.

0 Kudos
Message 2 of 4
(2,613 Views)

Provided your;

 

VI name is descriptive

Icon reflects what the sub-VI does

Sub-VI documentation is good

 

Do it!

 

When you have trouble at a future date and you know what state the app is currently in, you will be able to go quickly to the associated code either by opening it from the project or from the VI Hierarchy screen.

 

Just my 2 cents,

 

Ben

 

PS Assuming there are no controls, locals, etc in that code.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 4
(2,611 Views)

Just make sure that enforcing execution order through creating subVIs isn't going to eliminate race issues.  Sounds weird, right?  But maybe the code was depending on a race condition to work correctly, and inadvertently resolving the race condition breaks the application.

 

Otherwise, this is sound practice.  One reason for subVIs is for code reuse, but another big reason is to break up code into meaningful pieces.

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 4 of 4
(2,595 Views)