#################################################################
#
# This program is a sample DDE client that initiates a single DDE
# conversation with Microsoft Excel. The conversation consists
# of a single request for a copy of row 1 from the spreadsheet
# "sheet1.xls". It assumes that Excel is already running, and
# that "sheet1.xls" is open. If the initial value of the
# AppName_SV variable in this program is changed to "ESL", the
# sample server program on the following page can be used
# in place of Excel as a server.
include esldde.inc # DDE stimulus definitions
###################################
# Stimulus and Variable definitions
stimulus DDE "esldde" # DDE stimulus declaration
integer variable ConvID_IV # Conversation ID, supplied
# by DDE DLL
Status_IV # Conversation status flags
ErrorID_IV # ID of last error which
# occurred
boolean variable LocalTermination_BV is false # Which partner
# terminates first
string variable AppName_SV is "Excel" # Partner application name,
# change this to "ESL" to
# connect to the sample
# server program.
Topic_SV is "sheet1.xls" # Conversation topic
ItemName_SV is "r1" # Item name for data
# exchange
Format_SV is DDEFMT_TEXT # Format of exchanged
# data
###################################
# Primary Region Definition
enabled visible color 26 primary textual region PrimaryWindow_TR
size 500 200 at position 8 50
black foreground
title bar "Sample Easel DDE Client"
border
system menu
minimize button
maximize button
###################################
# Response Definitions
# Attempt to start a conversation as a client with the server
# (Excel), which must be running, on the topic "sheet1.xls". If
# successful, request a copy of row 1 (ItemName_SV = "r1")
response to start
copy DDEInitiate (AppName_SV, Topic_SV) to ConvID_IV
if (ConvID_IV = 0) then # Excel did not respond, or
add to PrimaryWindow_TR # cannot converse on the
# specified topic
insert "ERROR: No response from " AppName_SV " on "
Topic_SV "\n"
end if
response to stimulus DDE DDE_INITIATEACK # The initiate as been accepted
add to PrimaryWindow_TR insert
"Connected..Requesting.."
call DDERequest (ConvID_IV, ItemName_SV, Format_SV,
Status_IV)
response to stimulus DDE DDE_DATA # The data has arrived
add to PrimaryWindow_TR insert
"\nDATA: " DDEGetStringData (ConvID_IV) "\n"
copy true to LocalTermination_BV
call DDETerminate (ConvID_IV)
response to stimulus DDE DDE_NACK # Partner cannot supply
# the data
add to PrimaryWindow_TR insert
"\nERROR: " ItemName_SV
"not available;terminating conversation\n"
copy true to LocalTermination_BV
call DDETerminate (ConvID_IV)
# For a conversation termination event, check to see if the
# termination was initiated locally, or by the partner. If partner
# generated, acknowledge, (although the DDE DLL would do this by
# default anyway). Otherwise this is just the partner
# acknowledging the LOCAL request for termination.
response to stimulus DDE DDE_TERMINATE
if (LocalTermination_BV = false) then
call DDETerminate (ConvID_IV)
end if
add to PrimaryWindow_TR insert
"Conversation terminated\n"
# Simply report errors to the screen, and terminate. response to stimulus DDE DDE_ERROR
if (not (eventparam_IV = 0)) then
copy DDEGetErrorID (eventparam_IV) to ErrorID_IV
add to PrimaryWindow_TR insert
"ERROR: " DDEGetErrorString (ErrorID_IV)
"; terminating conversation\n"
else
copy "ERROR: (Null Conversation ID Returned)
; terminating conversation\n"
end if
copy true to LocalTermination_BV
call DDETerminate (ConvID_IV)
# When the user closes the application, make sure all
# conversations are terminated.
response to PrimaryWindow_TR
on close
call DDETerminateAll ()
exit