To become familiar with the LabVIEW programming environment, let us calculate the sum and average of two input values in the following step-by-step example.
Sum and Average VI Example Using Graphical Programming
To create a new VI, click on the Blank VI under New, as shown in Figure 2. This can also be done by choosing File → New VI from the menu. As a result, a blank front panel and a blank block diagram window appear, see Figure 2. Remember that a front panel and block diagram coexist when one builds a VI, meaning that every VI will have both a front panel and an associated block diagram.
![]() |
The number of VI inputs and outputs is dependent on the VI function. In this example, two inputs and two outputs are needed, one output generating the sum and the other generating the average of two input values. Create the inputs by locating two numeric controls on the front panel. This can be done by right-clicking on an open area of the front panel to bring up the Controls palette, followed by choosing Controls → Modern → Numeric → Numeric Control. Each numeric control automatically places a corresponding terminal icon on the block diagram. Double-clicking on a numeric control highlights its counterpart on the block diagram and vice versa.
Next, label the two inputs as x and y using the Labeling tool from the Tools Palette, which can be displayed by choosing View → Tools Palette from the menu bar. Choose the Labeling tool and click on the default labels, Numeric and Numeric 2, to edit them. Alternatively, if the automatic tool selection mode is enabled by clicking Automatic Tool Selection in the Tools Palette, the labels can be edited by simply double-clicking on the default labels. Editing a label on the front panel changes its corresponding terminal icon label on the block diagram and vice versa.
Similarly, the outputs are created by locating two numeric indicators (Controls → Modern → Numeric →Numeric Indicator) on the front panel. Each numeric indicator automatically places a corresponding terminal icon on the block diagram. Edit the labels of the indicators to read “Sum“ and “Average.”
For a better visual appearance, one can align, distribute and resize objects on a front panel window using the front panel toolbar. To do this, select the objects to be aligned or distributed and apply the appropriate option from the toolbar menu. Figure 3 shows the configuration of the front panel just created.
![]() |
Now build a graphical code on the block diagram to perform the summation and averaging operations. Note that <Ctrl-E> toggles between a front panel and a block diagram window. If objects on a block diagram are too close to insert other functions or VIs in-between, one can insert a horizontal or vertical space by holding down the <Ctrl> key to create space horizontally and/or vertically. As an example, Figure 4b illustrates a horizontal space inserted between the objects shown in Figure 3a.
![]() |
Next, place an Add function (Functions →Express →Arith & Compar →Express Numeric →Add) and a Divide function (Functions →Express →Arith & Comp →Express Numeric →Divide) on the block diagram. Enter the divisor, in this case 2, in a Numeric Constant(Functions →Express →Arith & Compar →Express Numeric →Numeric Constant) and connect it to the y terminal of the Divide function using the Wiring tool.
To achieve proper data flow, wire functions, structures and terminal icons on a block diagram using the Wiring tool. To wire these objects, point the Wiring tool at the terminal of the function or subVI to be wired, left-click on the terminal, drag the mouse to a destination terminal and left-click once again. Figure 5 illustrates the wires placed between the terminals of the numeric controls and the input terminals of the Add function. Notice that the label of a terminal gets displayed whenever one moves the cursor over the terminal if the automatic tool selection mode is enabled. Also, note that the Run button
on the toolbar remains broken until one completes the wiring process.
![]() |
For better block diagram readability, one can clean up wires hidden behind objects or crossed over other wires by right-clicking on them and choosing Clean Up Wire from the shortcut menu. Any broken wires can be cleared by pressing <Ctrl-B> or Edit →Remove Broken Wires.
To view or hide the label of a block diagram object, such as a function, right-click on the object and check (or uncheck) Visible Items →Label from the shortcut menu. Also, one can show a terminal icon corresponding to a numeric control or indicator as a data type terminal icon by right-clicking on the terminal icon and unchecking View As Icon from the shortcut menu. Figure 6 shows an example where the numeric controls and indicators are depicted as data type terminal icons. The notation DBL indicates double precision data type.
![]() |
It is worth noting that there is a shortcut to build the above VI. Instead of choosing the numeric controls, indicators or constants from the Controls or Functions palette, one can use the shortcut menu Create, activated by right-clicking on a terminal of a block diagram object such as a function or a subVI. As an example of this approach, create a blank VI and locate an Add function. Right-click on its x terminal and choose Create →Control from the shortcut menu to create and wire a numeric control or input. This locates a numeric control on the front panel as well as a corresponding terminal icon on the block diagram. The label is automatically set to x. Create a second numeric control by right-clicking on the y terminal of the Add function. Next, right-click on the output terminal of the Add function and choose Create →Indicator from the shortcut menu. A data type terminal icon, labeled as x+y, is created on the block diagram as well as a corresponding numeric indicator on the front panel.
Next, right-click on the y terminal of the Divide function to choose Create →Constant from the shortcut menu. This creates a numeric constant as the divisor and wires its y terminal. Type the value 2 in the numeric constant. Right-click on the output terminal of the Divide function, labeled as x/y, and choose Create →Indicator from the shortcut menu. If the wrong option is chosen, the terminal does not get wired. An incorrect terminal option can easily be changed by right-clicking on the terminal and choosing Change to Control from the shortcut menu.
To save the created VI for later use, choose File →Save from the menu or press <Ctrl-S> to bring up a dialog window to enter a name. Type “Sum and Average” as the VI name and click Save.
To test the functionality of the VI, enter some sample values in the numeric controls on the front panel and run the VI by choosing Operate →Run, by pressing <Ctrl-R> or by clicking the Run button on the toolbar. From the displayed output values in the numeric indicators, the functionality of the VI can be verified. Figure 7 illustrates the outcome after running the VI with two inputs, 10 and 15.
![]() |



















