DDE Advise Loops - Automatic Data Transfer

 

The preceding examples all required specific commands to be executed to transfer data from an application to DADiSP. DDE also supports a very powerful feature called advise loops or hot links that automatically transfer data whenever the data changes. For example, to transfer the first 100 rows of an Excel worksheet into the current Window of DADiSP:

 

chan = ddeinit("Excel", "Sheet1")
ddeadvise(chan, "R1C1:R100C1")

 

 

Whenever data in any cell within the first 100 rows of the first column changes, the entire column of data is transferred into the DADiSP Window where the DDEADVISE function was first executed. New data is automatically appended to past advise data.

To stop the update, use DDEUNADVISE

 

ddeunadvise(chan, "R1C1:R100C1")

 

The item (R1C1:R100C1 in this example) must be specified since a single channel could have several hot links established. The collected data is preserved and the DDE channel is still valid even though the advise loop is terminated.

 

DDELINK essentially combines DDEINIT and DDEADVISE into a single function so the hot link can be established in one step.

 

ddelink("Excel", "Sheet1", "R1C1:R100C1")

 

performs the same operations as DDEADVISE example. Like DDEINIT, DDELINK also accepts app, topic and item strings in app|topic!item format.

 

ddelink("Excel|Sheet1!R1C1:R100C1")

 

In fact, the DDELINK function in this form is exactly what the Paste Link menu accomplishes when DADiSP is the link destination.

DDEADVISE or DDELINK operations can be assigned to DADiSP hot variables.

 

hotvar := ddelink("Excel|Sheet1!R1C1:R100C1")

 

The hot variable hotvar automatically receives and appends data from Excel whenever the data changes. See SPL Functions for more information on DADiSP hot variables.

 

DDEUNLINK terminates the DDELINK operation.

 

ddeunlink("Excel|Sheet1!R1C1:R100C1")

 

Like DDEUNADVISE, the data is preserved.

The DDE functions can be combined with standard DADiSP functions. For example, to create a simple real-time strip chart:

 

ddelink("Excel|Sheet1!R1C1");setx(length-10, length+1)

 

Each time cell A1 changes, the data is transferred to DADiSP and the Window automatically scrolls to display the last 10 data points.