Calling a VI by Reference
VI Server is used to make dynamic calls. To make the call, first open a reference to the VI using Open VI Reference, available on the Application Control palette

The type specifier forces the refnum to carry the connector type information with it. This is important for the Call By Reference Node, available on the Application Control palette, which allows us to call the dynamically loaded subVI from the main VI, as shown.

Note that when we finish the call, we close the VI reference. The advantage of making this sort of call is that the subVI is in memory only from the open to the close, rather than during the entire execution of the program.
Another advantage of this method is that multiple subVIs can be called from the same node, as long as they all have the same connector type. For example, suppose that we have a set of data files where each contains a VI name and two numbers.
doc1.op | doc2.op | doc3.op |
| add.vi 4.3 2.5 | subtract.vi 5.6 3.4 | multiply.vi 2.0 6.0 |
The two numbers should be passed to the specified VI. We want to process all of the data files at once. We can write a VI that loops around and dynamically loads and executes each file, as shown.


After allowing the user to select a directory in which the .op files exist, the VI gets a list of all .op files in the directory. For each file, inside the loop, it reads the first three lines of the file and passes the data to a Scan from String function that extracts the VI name (first line) and the two numbers. We can then dynamically load the Add, Subtract, or Multiply VI, compute the result of the specified operation, and display it via the output indicator.
Not only does this simplify the code for the VI, since the statically linked method would require a case structure, but it also allows us to easily expand the functionality if any new operations are necessary in the future, such as a Divide VI. All that is necessary is to create the new function, making sure that it has the same connector type, and to place it in the same location as the other function VIs. The main VI's code would remain identical.
Reader Comments | Submit a comment »
Actually, dynamic loading does have its
place. If you develop a framework in
LabView for a general type of testing but
want to allow users to develop plug-ins
for the framework without rebuilding the
main application, then dynamic loading
is the only way to accomplish this.
However, in general, I believe it is correct
that you don't want to use dynamic
loading without any thought as to why.
- Sep 23, 2008
Disadvantages
The disadvantages of dynamic loading
are:
1. Loss of vi heirarchy browsing.
2. Unable to easily traverse heararchy
and understand / edit large projects.
3. Unable to isolate dead/unused vis.
4. More difficult to create projects.
The advantages of dynamic loading can
also be gained by using the vi memory
settings.
Dynamic loading in general is a very
stupid thing to do.
- richard, tctec. admin@emx.net.au - Jan 2, 2007
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
