CitectVBA Programming Reference > Integrating CitectVBA into your project > Calling CitectVBA from Cicode

Calling CitectVBA from Cicode

Three new Cicode functions allow CitectVBA code to be called from within Cicode script, and be pre-emptively multitasked by CitectSCADA. These calls VbCallOpen(), VbCallRun(), and VbCallReturn()can be nested to implement the entire function set with a single line of Cicode.

Note: When using the CiVBA language override in a Command field, the compiler constructs the nested call for you. The same mechanism is used even though it is not self evident. For details, see Using CitectVBA in CitectSCADA Command or Expression fields.

For information on multithreading in CitectVBA, see Multithread Considerations with CitectVBA.

To call a given CitectVBA function or subroutine from Cicode, use the VbCallOpenfunction. This returns a handle which can then be used to execute the call by passing it to the VbCallRunfunction. Upon return from VbCallRun, you can call the VbCallReturnfunction to get the return value of the CitectVBA function called.

The Cicode VbCallOpen()function is used to initiate a call to the CitectVBA function or subroutine, and returns a handle to the open function.

<ReturnValue> = VbCallOpen(<FunctName>, <ArgList>)


The Cicode VbCallRun()function is used to execute the CitectVBA function or subroutine (previously opened with the Cicode VbCallOpenfunction), and requires the handle returned from the VbCallOpenfunction call. The VbCallRunfunction provides an opportunity for the opened CitectVBA function to complete and return a value in the multi-threaded CitectSCADA environment. It passes its argument value (of OBJECT data type) through as its return value upon completion.

<ReturnValue> = VbCallRun(<CallHandle>)


The Cicode VbCallReturn()function is used to obtain the return value of the completed CitectVBA function (previously opened with the Cicode VbCallOpenfunction), and requires the handle returned from the VbCallRunfunction call.

<ReturnValue> = VbCallReturn(<CallHandle>)



INT iRet;
STRING sMsg = "Hello";
INT iVal = 123;
iRet = VbCallReturn(VbCallRun(VbCallOpen("CiVBATest", iVal)));
Message("TestCitectVBA Function", "CiVBATest = " + IntToStr(iRet), 0);


Function CiVBATest(Value As Integer) As Integer
CiVBATest = Value * 2
End Function

See Also

Calling Cicode from CitectVBA