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

Calling Cicode from CitectVBA

Calling a Cicode function from CitectVBA is accomplished by two CitectVBA functions: CicodeCallOpen()and CicodeCallReturn().

To call a given Cicode function, use the CicodeCallOpenfunction which will create and execute a Cicode thread that runs the function. For multitasking purposes, a separate function CicodeCallReturnis used to obtain the return-value of the completed Cicode function most recently called by the CicodeCallOpenfunction.

UNINTENDED EQUIPMENT OPERATION

Do not nest the CicodeCallOpen and CicodeCallReturn functions. Nesting these functions can lead to unintended equipment operation when your program is run.

Failure to follow these instructions can result in death, serious injury, or equipment damage.

The return value is initialized when control is returned to the CitectSCADA kernel. This occurs only after completion of the line of CitectVBA code containing CicodeCallOpen. For details on multithreading in CitectVBA, see Multithread Considerations with CitectVBA.

To call a given Cicode function or subroutine from CitectVBA, use the CicodeCallOpenfunction. Upon return from CicodeCallOpen, you can call the CicodeCallReturnfunction to obtain the return value of the Cicode function called.

The CicodeCallOpenfunction is a CitectVBA function used to call a Cicode function from CitectVBA. It is used to initiate and execute a call to the Cicode function and returns an integer value representing the success or the type of error encountered by the CicodeCallOpen function.

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

where:

The CicodeCallReturnfunction is a CitectVBA function used to obtain the return value of the most recently completed Cicode function opened with the CitectVBA CicodeCallOpenfunction.

<ReturnValue> = CicodeCallReturn()
		

where:

No arguments are passed to the CicodeCallReturnfunction, as it can only return the result of the most recent return-value for the Cicode function called by the CitectVBA CicodeCallOpenfunction.

Note:In the following example, a CitectVBA variable is enclosed in brackets to force the passing of the variable by value. See Passing variables Byref and Byval.

CitectVBA

' declare modular variant variable to store function results
Dim vntRet as Variant
Function TestCicode() As Integer
' declare local variables
Dim intRet As Integer
Dim strReply as String
Dim intMaxScale as Integer
' copy current tag value to variable
' uses the project variable tag named MAX_SCALE
intMaxScale = MAX_SCALE
' call Cicode function
' for example: TrnSetScale( AN, Pen, Percent, Scale)
intRet = CicodeCallOpen( "TrnSetScale", 53, -1, 100, (IntMaxScale) )
' Note the syntax used:
'- brackets around the CitectVBA function argument list
'(Only necessary when the CitectVBA function is preceded by an equals (=) sign .)
' - double quotes around the Cicode function name
'- no brackets around the Cicode function argument list
'- brackets around individual variable arguments
' test results
If intRet = 0 Then
'
' insert code for successful completion here
'
vntRet = CicodeCallReturn()
strReply = "CicodeCallOpen Function successfully called"
Else
'
' insert code for unsuccessful completion here
'
Select Case intRet
Case = 1
' assign return comment for this case
strReply = "CicodeCallOpen Function call general error"

Case = 2
' assign return comment for this case
strReply = "Cicode Function not found"
Case = 3
' assign return comment for this case
strReply = "Wrong number of arguments "_
& "in Cicode CallOpen function call"
Case Else
' assign return comment for this case
strReply = "Unknown error"
End Select
End If
' display return comment for your information
MsgBox strReply
' assign return value for this function
TestCicode = intRet
End Function

See Also

Calling CitectVBA from Cicode