Global variables share data among multiple VIs. To create a global variable, add a global variable object to the block diagram and modify the global VI for the global variable. Then, associate the global variable with front panel objects.

Global variables operate outside of the dataflow paradigm that LabVIEW uses. Before creating global variables, understand when to use global variables and performance considerations for global variables.

Note Use a global variable only when you cannot route a wire through multiple VIs to share data. For example, if a file path is changed in one VI and another VI must open that path, there might not be a logical way to wire the path through numerous calling VIs. Using a global variable to hold the path data might be the best choice.

You can use different approaches to create global variables:

  • Create several single-object global VIs with one front panel object each
  • Group similar variables together: create one global VI that contains multiple front panel objects

In general, creating global variables involves two steps:

  1. Create the global VI.
  2. Add the global variable to the block diagram of a VI and assign the global variable to front panel objects of the VI.
Note If you create a copy of a global variable node, LabVIEW associates the new global variable node with the global VI of the variable node you copy it from.

Creating a New Global Variable

To define the data that a global variable shares, create the global VI for the global variable and add front panel objects to it. Then, associate the global variable with the objects that you want to use the global variable.

To create a global VI for a global variable and associate the global variable with front panel objects, complete the following steps.

  1. Add a global variable (Icon of a global variable from the Data Functions palette.) to the block diagram from the Functions palette and place it on the block diagram.
  2. Use the Operating tool or Positioning tool to double-click the global variable node.
    The front panel window of the global VI for the global variable opens.
  3. Add one or more controls or indicators to the front panel window the same way you do in a standard front panel window.
    Tip LabVIEW uses owned labels to identify global variables. Label the front panel controls and indicators with descriptive owned labels.
    The controls and indicators that you add to the global VI define the data that the global variable shares among VIs.
  4. Save and close the global VI.
    Tip Remember where you save the global VI. To associate other VIs with a global variable, you add the global variable to the block diagram from this file location.
  5. Return to the block diagram of the original VI and associate the global variable with front panel objects.
    • Right-click the global variable node and select a front panel object from the Select Item shortcut menu.

      The shortcut menu lists all the front panel objects that have owned labels.

    • Use the Operating tool or Labeling tool to click the global variable node and select the front panel object from the shortcut menu.

If you create a copy of a global variable node, LabVIEW associates the new global variable node with the global VI of the variable node you copy it from.

Integrating an Existing Global Variable Into a VI

To integrate an existing global variable into a VI, complete the following steps.

  1. On the Functions palette, click the Select a VI icon or text, navigate to the folder where you saved the global VI, and double-click the VI.
  2. Add the global variable to the block diagram.
    By default, the global variable is associated with the first front panel object with an owned label you added to the global VI.
  3. Associate the global variable with the data from another front panel object.
    1. Right-click the global variable node you added to the block diagram.
    2. Select the front panel object to associate with the global variable from the Select Item shortcut menu.