How to Use Variables in a DDEExecute() Command

Last reviewed: April 29, 1996
Article ID: Q96351
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, versions 2.5 and 2.5a

SUMMARY

When you are using dynamic data exchange (DDE), variables used in the DDEExecute() command must be concatenated because all the characters between the single quotation marks are sent to the application for interpretation.

MORE INFORMATION

The following command opens the spreadsheet TEST.XLS if Microsoft Excel is already open:

   =DDEExecute(chan,'[Open("test.xls")]')

However, the following DDEExecute() command will not work:

   filename= "test.xls"
   =DDEExecute(chan,'[Open(filename)]')

This command can be made to work by issuing the following DDEExecute() command:

   =DDEExecute(chan,'[Open('+'"'+filename+'")]')

The above command encloses the double quotation marks expected by Microsoft Excel in single quotation marks.

Concatenation of the quotation marks must be done in the command itself since DDEExecute() is sending the entire string between the single quotation marks to Microsoft Excel.

Another alternative is to concatenate the entire command before the DDEExecute() command, and use macro substitution as follows:

   testname= "test.xls"
   ddecomm=  "'[Open("+CHR(34)+"d:\excel4\"+testname+CHR(34)+")]'"
   =DDEExecute(chan,&ddecomm)

NOTE: CHR(34) provides the double quotation marks required by the Microsoft Excel Open command.


Additional reference words: VFoxWin 3.00 FoxWin 2.50 2.50a quotes
KBCategory: kbinterop kbprg
KBSubcategory: FxinteropDde


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.