Creating sub VIs in LabView : tutorial 13

In this tutorial you will learn the working of subVI. A subVI is same in LabView as a function or subroutine in text based programming language. At the start you are provided with an introduction to a subVI, including why we need them and what a subVI basically is. After that an explanatory VI is designed in which a subVI is used and some different features of the subVI ar also discussed.

Introduction to SubVIs in labview

Using sub Vis in LabView is defined as modularity, and by definition, using smaller modules or smaller parts for the overall objective collectively the same tasks as the bigger project will be doing is known as modularity. Creating smaller sections of your overall code is known as a sub VI and in LabView also known as program modularity. In LabView there is no much difference between a VI and a sub VI they are similar to each other. Each sub VI is composed of its own block diagram and its own front panel, but we can only access a sub VI by calling it in its parent VI.

An icon can be seen within the VI representing the sub VI is created when you create a sub VI within a VI and use it. This icon can be customized; the icon for a sub VI is the same as in the upper right corner of a simple Vis block diagram and front panel window. Customizing an icon is also explained in the later section of the tutorial.

If you are a user of C or any other text based programming language you must be familiar with the terms like classes functions and subroutines. The purpose of a subroutine is simply to do a bigger task in smaller portions. Like if you want to build a project using microcontrollers, you can write one function to implement timers’ initializations and other is used to implement the main function, whereas both of them are called in main function.

Translating this in the language of LabView, the timer initialization and main function implementations is done in subVI, however, both of them are called in the main VI of the program. In the following program you will understand the working of sub VIs

Example of creating SUBVI in labview

  • Moving to the programming part, create a VI as we have done in 1st tutorial and save it for future use, as we have done in all previous tutorials.
  • To understand the use of sub VIs, what we have to do is to first design a program (bigger one) which we want to convert into modules or sub VIs. To save our time lets use the VI we have already created in the graphs and charts tutorial. The one in which temperature is converted from Fahrenheit to Celsius scale, as shown in the figure below,Block diagram

Figure 1: Block diagram

  • From the top bar, when you click on the edit button a dropdown will appear. In this dropdown create subVI option is present as shown in the figure below.creating SUBVIs in labview

Figure 2: Creating subVI

  • Select the area of the code or block diagram from the complete VI that you want to put inside the subVI, for reference see the figure below,

Figure 3: Module selection

  • In the above figure we want to create a subVI in which the blocks inside the selected portion will appear, and in place of this selected portion only an icon will appear. This icon represents the presence of a subVI. See the figure below,SubVI created in labview

Figure 4: SubVI created

  • When you double click on the icon shown in the figure above, a different front panel will appear as shown in the figure below.subVI front panel

Figure 5: SubVI front panel

  • You can also see the block diagram of the subVI using the instructions I give. From the top bar click on window and then click on show block diagram as shown in the figure below,

Figure 6: Showing blocking diagram

  • The block diagram of the subVI will appear as shown in the figure below,subVI block diagram labview

Figure 7: SubVI block diagram

  • From the above figure you can see that this is the same as the blocks we selected the creation part of the subVI.
  • One good thing about using subVI is that, we can modify them, to some additional functionality, let’s say in this code we want to modify the conversion. i.e. we want the user to decide whether he want to convert the temperature from Fahrenheit to Celsius or he simply wants to display the temperature as it is.
  • This is the same task as we have done before in the case structure tutorial. In this case too, we will use a case structure with a button to decide which case to be used.
  • In the subVI place a button on the front panel to toggle the decision of the user. Also from the function palette select a case structure from structures and place all the blocks in that structure as shown below,case structure

Figure 8: Case structure placement

  • After selecting case structure select the area where you want to place it as shown in the figure below,

Figure 9: Case structure selection

  • The true condition of the switch will return the converted scale of temperature i.e. from Fahrenheit to Celsius as shown in the figure below,

Figure 10: True condition

  • The false condition of the switch will return the temperature in Fahrenheit as shown in the figure below,

Figure 11: False condition

  • Now, the point is, the switch present in the subVI cannot be operated from the main VI right now. How to make a connection of this switch in the main VI?? From the upper right corner of the subVI there is an icon smilar to the subVI icon present in the main VI as shown in the figure below.

Figure 12: properties icon

  • The matrix with orange color in it represents 2 terminals of subVI i.e. the input and the output terminal. If you want to add another terminal in it, as we want right now for toggle switch, click on any of the block it will turn black as shown below

Figure 13: Selected terminal

  • Now click on the toggle switch, and this slot will turn green because the switch is a Boolean and green color also represents Boolean as we have discussed in previous tutorials. Refer to the figure below.

Figure 14: Boolean terminal

  • Now, if you check the main VI you can see that a Boolean terminal is also present on the subVI icon as shown in the figure below.Boolean terminal on main VI

Figure 15: Boolean terminal on main VI

  • Right click on this terminal and create a control on it as we have done in previous tutorials. The complete block diagram is shown in the figure below.Complete block diagram SUBVIs in labview

Figure 16: Complete block diagram

  • You can also customize the icon of the subVI by right clicking on the icon and selecting edit icon as shown below,Customizing icon

Figure 17: Customizing icon


Design a sub VI that will take two integer inputs and return 4 outputs i.e. their sum, product, quotient and subtracted value.

<<Previous tutorial                                                 Next tutorial>>

Add Comment