Showing results for 
Search instead for 
Did you mean: 

Calling a LabVIEW VI to execute a task (simple switch control) from a Visual Basic Script Routine

I figure this is probably a simple question for most of you. How does one call a LabVIEW VI to execute from
a Visual Basic Script? Also can one do the opposite
and call Visual Basic Scripts from within LabVIEW? Thanks!
0 Kudos
Message 1 of 3

Here is example code to call a VI from a Visual Basic Script (VBS) using ActiveX. I don't include it as an attachment since it would certainly trigger antivirus warning...

' Reference to LabVIEW Application
Dim lvapp
' Reference to called VI
Dim viref
' Path to file VI or only the VI name if it
' is already in memory
VIname = "c:\mydir\"
VIPassword = ""
' Set resvForCall to True to invoke the Call method
' Set to False to invoke the Run method
resvForCall = True
' Name(s) of the control of the VI
' that receives the data and indicators to read.
' They must be on the connector pane.
Dim paramNames
paramNames = Array("Input1","Output1")
' Value of control(s)on call. Values
' of indicators is irrelevant
Dim paramVals

paramVals = Array("GetOutput1","")
' Open a connection to ActiveX VI Server
set lvapp = WScript.CreateObject("labview.Application")
' get a VI reference
set viref = lvapp.GetVIReference(VIname,VIPassword,resvForCall)
' call the VI
viref.Call paramNames,paramVals
' Value of Output1 is the second element
' of paramVals

The Run method is simpler. You don't have to specify arguments paramNames and paramVals, just invoke

To call a VBS from LabVIEW the most simple is to call the System with the command line: "wscript.exe [vbs path]".

You can also use ActiveX to create and execute vbscripts and javascripts without a file copy. Download from the "Microsoft Script Control" ActiveX controls. There are quite intuitive methods calls to set and run scripts.

LabVIEW, C'est LabVIEW

0 Kudos
Message 2 of 3

I have been brief on the VI side...
The called VI, here "" has at least one control named "Input1" which in this specific case is a string that receives the value "GetOutput1" when called by the script. All required inputs names on the connector pane must be included in the paramNames array.
The VI has also at least one indicator named "Output1" whose value is returned in paramVals after the call. It is easy to set and return strings, numbers or booleans. I have not been able to transfer arrays with a Visual Basic Script but I think it is possible in a Visual Basic Application.

LabVIEW, C'est LabVIEW

0 Kudos
Message 3 of 3