4th Dimension as DDE Client

4D - Documentation   Français   English   German   DDE_Tools, Contents   DDE_Tools, Index   Back   Previous   Next

version 6.0


This section details several examples that show how 4D works as a DDE client.

Before we start, remember to follow this rule at all times:

Every communication must be initialized, and must be closed once the exchange is completed. The functions that enable you to perform these operations are:

DDE_Initiate

DDE_Terminate

Note: Also, the DDE_TERMINEALL command closes all previously established connections.

Receiving Data

In this example, we want to obtain the contents of the "Sales" cell in the Excel document SPREAD.XLS and assign it to the 4D variable vSales. Before you start, verify that the Excel application is launched and that the SPREAD.XLS document is open. When your exchanges are completed, you must close the channel using the DDE_Terminate function.

You can enter the following code, for example, in the script of a button:

   Channel:= DDE_Initiate("Excel";"C:\SPREAD.XLS")
   Err:= DDE_Request(Channel;"Sales";vSales)
   Err:= DDE_Terminate (Channel)
   ALERT("Sales read from Excel : "+vSales)

Of course, the Sales cell must be present in the document. To identify any cell, use the format "R2C3", for example, indicating the second row, third column.

Sending Data

Now we set the value of the Sales cell within the Excel spreadsheet:

   Channel:= DDE_Initiate("Excel";"C:\SPREAD.XLS")
   vSales:=Request("Sales to send to Excel ?")
   Err:= DDE_Poke(Channel;"Sales";vSales)
   Err:= DDE_Terminate (Channel)

Requesting an Execution through a Channel

Now, we ask Excel to create a new document:

   Channel:= DDE_Initiate("Excel";"SYSTEM")
   Err:= DDE_Execute(Channel;"[New()]")
   Err:= DDE_Terminate (Channel)

The DDE protocol specifies that commands are to be written between brackets. In this way, you can send several commands sequentially in one request.

See Also

4th Dimension as DDE Server.


4D - Documentation   Français   English   German   DDE_Tools, Contents   DDE_Tools, Index   Back   Previous   Next