.. highlightlang:: us .. index:: Overview DDE, DDE .. _overview-dde: Overview DDE ============ DDE is the abbreviation for Dynamic Data Exchange. DDE is a method of interprocess communication between programs to exchange data or control another program. Examples for DDE are querying a database, or sending data to a spreadsheet program. The application that intiates the conversation is the DDE client application; the application that responds to the client is the DDE server application. UniPlot can be used as a DDE server or client. UniPlot as a Client ------------------- UniScript provides the following 6 functions for the client side. The user must define the functions. .. us.indexlist UniPlotasaClientDdeInitiateDdeExecuteDde,UniPlot as a Client,DdeInitiate,DdeExecute,DdePoke,DdeRequest,DdeTerminate,DdeTerminateAll, .. include:: ../ftab/UniPlotasaClientDdeInitiateDdeExecuteDde.ftab .. us.example **Example** Here is an example for UniPlot as client. The server is Excel: :: system("c:/msoffice/excel/excel.exe", SW_HIDE, 1); hConv = DdeInitiate("Excel", "System"); ssFile = GetRootDirectory() + "samples\map-data.xls"; DdeExecute(hConv, "[OPEN(\"" + ssFile + "\")]") hConvTab = DdeInitiate("Excel", "map-data.xls"); ssData = DdeRequest(hConvTab, "z1s1:z16384s255"); DdeExecute(hConv, "[QUIT()]"); DdeTerminateAll(); hedit = EdCreate(); EdSetText(hedit, ssData); The program excutes the following commands: * Excel will be started. * Excel will load the :file:`Samples\\map-data.xls` file. * Excel will send the sheet data to a UniPlot variable. * Teh content will be displayed in an UniPlot editor. .. _uniplot-als-server: UniPlot as a Server ------------------- UniScript provides the following 6 functions calls for the server side. The user must define the functions. .. us.indexlist UniPlotasaServerDdeCallback_ConnectDdeCa,UniPlot as a Server,DdeCallback_Connect,DdeCallback_ConnectConfirm,DdeCallback_Execute,DdeCallback_Poke,DdeCallback_Request,DdeCallback_Disconnect, .. include:: ../ftab/UniPlotasaServerDdeCallback_ConnectDdeCa.ftab .. us.example **Example** As an example we will write a Basic program for Microsoft Word. The Basic program will be used to create plots with UniPlot. Lets start with the UniPlot side (Server). Copy the following code into a program editor in UniPlot and save the file on your computer. Press F4 to compile the function. :: def DdeCallback_Poke(hConv, ssItem, ssTopic, ssData) { ss = strtok(ssData, ","); rvData = strtod(ss); plot(1:len(rvData), rvData); return TRUE; } To keep the function short we have not checked and function parameters or return values. Now lets start on the client side. Start Word and type in the following macro (Execute: **Tools=>Macro=>Create Makro**): :: Sub Main chan = DDEInitiate("UniPlotSL", "xydata") DDEPoke chan, "xydata", "1, 5, 3, 4, 8, 12" DDETerminate(chan) End Sub If you execute the Basic function ``Main`` in Word, UniPlot will create a plot. .. seealso:: :ref:`functions-by-categories` :sub:`id-1535155`