DDEExecute( ) Function

Example   See Also

Sends a command to another application, using dynamic data exchange (DDE).

Syntax

DDEExecute(nChannelNumber, cCommand [, cUDFName])

Returns

Logical

Arguments

nChannelNumber

Specifies the channel number.

cCommand

Specifies the command you want to send to the other application. The format of the command is determined by the application you are sending it to. Consult the application's documentation for the correct syntax.

cUDFName

Allows asynchronous command execution requests. If you omit cUDFName, a client application waits for the period specified with DDESetOption( ). If you specify a user-defined function with cUDFName, client program execution continues immediately after the command execution request is made.

When the server application finishes executing the command, the user-defined function you specify with cUDFName is executed. The user-defined function is passed six parameters in the order shown in the following table.

Parameter Contents
Channel Number The channel number of the server application.
Action XACTCOMPLETE (successful execution).
XACTFAIL (failed command execution).
Item The item name; for example, R1C1 for a Microsoft Excel worksheet cell.
Data The new data (REQUEST) or data passed (POKE or EXECUTED).
Format The data format; for example, CF_TEXT.
Transaction Number The transaction number returned by DDEExecute( ).

Use DDEAbortTrans( ) to cancel an uncompleted transaction. If the transaction fails, you can use DDELastError( ) to determine why it failed.

When you include cUDFName, DDEExecute( ) doesn't return a logical value. Instead, a transaction number is returned; if an error occurs, –1 is returned.

Remarks

The command sent with DDEExecute( ) must be understood by the application. Before you can execute the command, you must establish a channel to the server application with DDEInitiate( ).

For example, Microsoft Excel has an extensive set of macro commands, including DDE commands that let you request data from Visual FoxPro from within Microsoft Excel. If you establish a channel to Microsoft Excel, you can then use DDEExecute( ) to send macro commands to Microsoft Excel from within Visual FoxPro.

If the receiving application successfully executes the command, DDEExecute( ) returns true (.T.). If the receiving application cannot successfully execute the command or if the channel number you include is not valid, DDEExecute( ) returns false (.F.). If the optional asynchronous user-defined function cUDFName is included, a transaction number is returned. If an error occurs, DDEExecute( ) returns –1.