Create and Configure a LabVIEW SubVI

Updated Jul 31, 2023

Environment

Software

  • LabVIEW

Modularity, by definition, means to use modules or smaller parts for the overall objective. Within LabVIEW, program modularity means creating smaller sections of code known as subVIs. A subVI is similar to a subroutine in text-based programming languages.

The power of NI LabVIEW software lies in the modular nature of the VI. After you create a VI, you can use it on the Block Diagram of another LabVIEW program – this VI can now be referenced as a subVI. Using modular programming helps you reduce duplication of efforts through code reuse, streamline and visually clean up code, manage changes to code, and debug the Block Diagram quickly.

SubVIs contain front panels and block diagrams which you specify when creating the subVI. Unlike built-in LabVIEW function, when creating these VIs yourself, you must configure the a connector pane to set your VI’s inputs and outputs. You can also edit the icon of the subVI that is seen when it is on the block diagram to be an intuitive representation of what your function does.

In this tutorial, you will learn how to create a subVI, how to edit its icon display, and how to build and configure the connector pane. Creating and editing subVIs is a process available in all LabVIEW development systems. This tutorial will be useful for a beginner LabVIEW user or a user who is looking to capitalize on the modular design benefits of LabVIEW.
 

The following sections explain how to create and configure a LabVIEW SubVI.

  • Create a LabVIEW SubVI

  • Edit the SubVI Icon

  • Build the Connector Pane


Create a LabVIEW SubVI

You can simplify the block diagram of a VI by converting sections of the block diagram into subVIs. There are two ways to make a subVI in LabVIEW: 
  • Creating a standalone VI and then use it (drag and drop it) in a higher-level VI as a subVI
    • If you have already created the code that you would like to use in other VIs as its own standalone VI, continue on to the Edit the SubVI Icon section
  • Create a subVI from a section of code within another VI.
    1. Launch LabVIEW and open the VI from which you want to create a subVI
  1. Highlight the code you would like to convert into a subVI
  1. From the Edit menu, select Create SubVI to create a subVI from your selection.
    • The selected section of the block diagram is replaced with a default icon for the subVI. LabVIEW creates controls and indicators for the new subVI, automatically configures the connector pane based on the number of control and indicator terminals you selected, and wires the subVI to the existing wires. 
    • In the following sections, we will step through how to adjust the default icon and connector pane configurations.
 

Edit the SubVI Icon

The subVI icon is what you see from the block diagram that the subVI is placed on. Although it is not necessary to change it, updating the subVI icon is useful to create easily-identifiable functions. This is especially helpful if you creating many subVIs to include in your code. You have options to update like adding built-in glyphs, text, or importing your own images.
  1. Open the subVI 
    • If you created the subVI from a section of code in an existing VI, double-click the newly placed icon to open.
  2. From the front panel or block diagram of the subVI, double-click the icon in the upper right-hand corner to launch the Icon Editor
  1. Explore the pages of the Icon Editor dialog box and update your icon as desired.
  2. Press OK to save the icon. 

 
 

Build the Connector Pane

In order to use the subVI in line with other code, you need to configure the connector pane. The connector pane is a visual representation of how inputs and outputs are connected to the subVI from the calling VI. 

  • If you created a subVI from a subsection of code, LabVIEW configures inputs and outputs automatically. 
  • If you created a standalone VI to be used as a subVI (not created from sections of code), your terminals will be blank. You will assign inputs and outputs to terminals on the connector pane in the next step. 

  1. Select the connector pane pattern by right-clicking the connector pane icon >> Pattern >> choose from the arrays available to suit your function's needs.
    • Each rectangle on the connector pane represents a terminal. You will use the rectangles to assign inputs and outputs.
    • See Building the Connector Pane in LabVIEW Help for more considerations when deciding on patterns and wiring terminals.
  1. Examine the connection terminals that are connected (if any).
    • You can check the default configured connections by left-clicking on the colored boxed in the connection pane. The linked input/output will become highlighted on the front pane  
  2. Assign (or re-assign) connection terminals to controls and indicators.
    1. Click a terminal of the connector pane.
    2. Click the front panel control or indicator you want to assign to that terminal.
      • It is generally good programming practice to organize the inputs to a subVI on the left and the outputs on the right.
      • Note that the terminal color changes to that of the data type to which you have connected it.
      • You also can select the control or indicator first and then select the terminal.
      • If you need to unassign a terminal, right-click the terminal and select Disconnect this Terminal
    3. Click an open space on the front panel to deselect the control.
    4. Repeat these steps for all the controls and indicators that you will use to pass data to and from the calling VI.
  1. Set the Required, Recommended, and Optional Inputs and Outputs 
    1. Right-click a terminal in the connector pane.
    2. Select This Connection Is from the shortcut menu.
    3. Select Required, Recommended, or Optional.
      • In the Context Help window, the labels of required terminals appear bold, recommended terminals appear as plain text, and optional terminals appear dimmed. The labels of optional terminals do not appear if you click the Hide Optional Terminals and Full Path button in the Context Help window. Output terminals cannot be set as Required.
    • Alternatively, you also can select Tools»Options»Front Panel and put a checkmark in the Connector pane terminals default to Required checkbox. This option sets terminals on the connector pane to Required instead of Recommended. This applies to connections made using the wiring tool and to subVIs created using Create SubVI.

You have now created and configured your subVI for use in higher-level VIs! You can add the subVI to VIs by dragging and dropping from the Project Explorer or by using the Functions palette >> Select a VI ... >> navigate to your VI >> click on the block diagram to place the subVI.
One benefit on having the modular code in the subVI is that if you need to change the functionality, you can edit the subVI once and it will affect all calls to the subVI, not just the current instance.