Example Code

Calling a LabVIEW VI from Visual Basic through ActiveX

Code and Documents

Attachment

Overview


This Visual Basic program calls LabVIEW through ActiveX. The program programmatically opens a VI, shows it on the screen (if selected) and sends parameters to the VI. The VI runs and collects the data and displays it in a Visual Basic textbox. The attached Visual Basic program opens and runs an example VI included with LabVIEW. Before the LabVIEW ActiveX interface can be called in Visual Basic, you must open a reference to the LabVIEW 6.0 type library. You can open a reference by checking the correct references in Visual Basic. Make sure to place a checkmark for LabVIEW 6.0 type library in the Project»References menu in Visual Basic. The attached zip file includes an illustration of this menu.

Visual Basic calls the following methods:

Set lvapp = CreateObject("LabVIEW.Application")

Set vi = lvapp.GetVIReference(viPath) 'Load the VI in memory

vi.FPWinOpen = True 'show the front panel

vi.Call(paramNames,paramVals) 'run the VI

lvapp.Quit 'quit LabVIEW

The VI you want to call must have the same number of parameters as the setup in Visual Basic and LabVIEW exposes the parameters by wiring the connector of the VI.

Make sure that VI Server is enabled in LabVIEW. Enable VI Server in the Tools»Options menu by selecting VI Server: Configuration from the pull-down menu. Refer to the LabVIEW Help for more information about ActiveX.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors