Sends a command to another application, using dynamic data exchange (DDE).
DDEExecute(nChannelNumber, cCommand [, cUDFName])
- Specifies the channel number.
- 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.
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.
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(В ) does not return a logical value. Instead, a transaction number is returned; if an error occurs, вЂ“1 is returned.
The channel number of the server application.
XACTCOMPLETE (successful execution).XACTFAIL (failed command execution).
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.
The transaction number returned by DDEExecute(В ).
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 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.
The following example uses DDEInitiate(В ) to establish a DDE channel between Visual FoxPro and the Microsoft Excel worksheet Sheet1. DDEExecute(В ) is used to execute a Microsoft Excel command that maximizes the Microsoft Excel window.
gnChanNum = DDEInitiate('Excel', 'Sheet1') IF gnChanNum != -1 glExecute = DDEExecute(gnChanNum, '[App.Maximize]') IF glExecute != .F. WAIT WINDOW 'EXCEL window has been zoomed out.' ENDIF = DDETerminate(gnChanNum) && Close the channel ENDIF