Applies To:
  • CitectSCADA 3.40, 4.20, 5.00

How do I access Tags and run Cicode functions from a DDE client such as Microsoft Excel? 


Citect can use DDE I/O Devices to transfer Tag information to and from a DDE server. Citect can also act as a DDE server to clients such as Excel. Clients can access Citect via the DDE topics "system" and "variable". In both cases a DDE link must be opened to the application "citect" and then either a Cicode function can be called using the topic "system" or data can be directly poked in to Tags using the topic "variable". The "system" topic is available at all times, the "variable" topic is only available if the Tag Database is loaded in to memory at startup (This is enabled by default).

In Excel select Insert -> macro -> module and add appropriate VB code to modify Tags.


Below is a Cicode function SetINT1() and an example of a procedure in Excel v7.0a ( Office 95 Pro )

that calls the Cicode function SetINT1() using the "system" topic:


INT1 = Value; // INT1 is a Variable Tag of type INT

Excel Macro:

Dim channelNumber As Variant
Sub SystemDDE()

channelNumber = Application.DDEInitiate(app:="CITECT", topic:="SYSTEM")
Application.DDEExecute channel, "[SetINT1(42)]"
Application.DDETerminate channelNumber

End Sub

This next example is an Excel procedure that uses "poke" to directly change the values of Tags, using the "variable" topic:

Sub VariableDDE()

channelNumber = Application.DDEInitiate(app:="CITECT", topic:="VARIABLE")
Set rangeToPoke = Worksheets("Sheet1").Range("D5")
Application.DDEPoke channelNumber, "INT1", rangeToPoke
Application.DDETerminate channelNumber

End Sub

The last is an example of an Excel procedure to call a Cicode function with string parameters - note the use of double quotes:


    Sub CitectMsg()

    channelNumber =  Application.DDEInitiate(app:="CITECT",

    Application.DDEExecute channelNumber, "[Message(""DDE
    Message"",""Message From DDE"", 0)]"

    Application.DDETerminate channelNumber

    End Sub

For information on using an older version of Excel, see KB article Q1118.

Note that some of the syntax specified in the Excel help for VB functions is misleading. Use the examples provided in the help for accurate function syntax samples. The automatic correction when entering VB macro's is very good and will fix out most syntax errors as they are made.