DDEAdvise( ) Function Example

The following example demonstrates how you can establish a DDE channel to a Microsoft Excel worksheet named Sheet1. DDEAdvise( ) is used to establish two links to data in two worksheet cells (R1C1 and R1C2). The user-defined function NEWDATA is executed when data in either of the cells changes. The user-defined function tests the item and advise parameters to determine which item changed and what kind of link has been established.

PUBLIC mchannum
mchannum = DDEInitiate('Excel', 'Sheet1')
IF mchannum != -1
   = DDEAdvise(mchannum, 'R1C1', 'newdata', 1)     && Notify link
   = DDEAdvise(mchannum, 'R1C2', 'newdata', 2)     && Automatic link
   WAIT WINDOW 'Enter data in first two cells in Excel.'
ENDIF
PROCEDURE newdata
PARAMETERS channel, action, item, data, format, advise
IF action = 'ADVISE'
   DO CASE
      CASE item = 'R1C1'   && Notify link
         newvalue = DDERequest(channel, item)
         ? 'R1C1 notify link: ' + newvalue
      CASE item = 'R1C2'   && Automatic link
         newvalue = data
         ? 'R1C2 automatic link: ' + newvalue
   ENDCASE
ELSE
   IF action != "TERMINATE"
      = DDETerminate(mchannum)
 ENDIF
ENDIF