After you build a VI, you can call it from the diagram of another VI within the same project.
A VI called from the diagram of another VI is a
subVI. SubVIs contain reusable code and simplify the diagrams of calling VIs. SubVIs are analogous to functions or subroutines in other programming languages.
When you add an instance of a subVI to the diagram of another VI, the subVI appears as a single node, similar to a node from the palette. When data in the calling VI reaches the subVI node, the software executes the diagram of the subVI.
The following diagram shows two common situations that benefit from subVIs.
- Users may have difficulty understanding the purpose of this section of code because it performs several operations. The more complex a diagram, the more time it takes to interpret sections of code.
- The same code appears in two different places. Repeated code increases the likelihood of errors. For example, if you change one section of repeated code, you must remember to make the same change everywhere the code section occurs.
The following diagram shows two solutions that subVIs provide.
- The Coin Flip subVI represents the highlighted code inside the For Loop of the previous diagram. The subVI simplifies the diagram and communicates the purpose of the code through its label and node icon.
- The Percentage subVI represents one of the duplicate sections of highlighted code from the previous diagram. The Percentage subVI performs the same function in two places without repeating code. If you change code in the VI called by the Percentage subVI, both instances of the subVI change.