JavaScript Editor js editor     Web development 

Main Page

Requests data from a server application in a dynamic data exchange (DDE) conversation.

DDERequest(nChannelNumber, cItemName [, cDataFormat [, cUDFName]])



Specifies the channel number of the server application.

Specifies the item name. The item name is application-specific and must be understood by the application. For example, Microsoft Excel uses row and column notation to refer to cells in a worksheet. The item name R1C1 designates the cell in the first row and first column of the worksheet.

Specifies a format for the data requested. The default format is CF_TEXT. In this format, fields are delimited with tabs and records are delimited with a carriage return and a line feed.

Allows an asynchronous data transfer. If you omit cUDFName, Visual FoxPro waits for the data from the server for the period specified with DDESetOption(В ). If you specify the name of a user-defined function with cUDFName, Visual FoxPro continues program execution immediately after the request is made. When the data is available from the server application, the user-defined function specified with cUDFName is executed. The user-defined function is passed six parameters in this order:

Parameter Contents

Channel Number

The channel number of the server application.


XACTCOMPLETE (successful transaction).XACTFAIL (failed transaction).


The item name; for example, R1C1 for a Microsoft Excel worksheet cell.


The new data (REQUEST) or data passed (POKE or EXECUTED).


The data format; for example, CF_TEXT.

Transaction Number

The transaction number returned by DDERequest(В ).

Use DDEAbortTrans( ) to cancel an uncompleted transaction. If the transaction fails, you can use DDELastError( ) to determine why it failed. When you include cUDFName, DDERequest( ) returns a transaction number equal to or greater than 0 if successful, or –1 if an error occurs.

Return Value



Before you can request data using DDERequest(В ), you must establish a channel to the server application with DDEInitiate(В ).

If the request for data is successful, DDERequest( ) returns the data as a character string. If the request fails, DDERequest( ) returns an empty string and DDELastError( ) returns a nonzero value. If you include the asynchronous user-defined function cUDFName, DDERequest( ) returns a transaction number if successful, or –1 if an error occurs.


The following example uses DDEInitiate(В ) to establish a DDE channel between Visual FoxPro and a Microsoft Excel worksheet named Sheet1. 'Excel' is the service name, and 'Sheet1' is the topic name. The channel number is stored to the memory variable mchannum for use in subsequent DDE functions.

DDERequest(В ) requests the item name R1C1, the data in the first row and column of the Sheet1 spreadsheet.

В Copy Code
mchannum = DDEInitiate('Excel', 'Sheet1')
IF mchannum != -1
   mrequest = DDERequest(mchannum, 'R1C1')
   IF !EMPTY(mrequest) AND DDELastError( ) = 0      && Successful
      WAIT WINDOW 'R1C1 contents: ' + mrequest
   = DDETerminate(mchannum)            && Close the channel

See Also

JavaScript Editor js editor     Web development