How to Use DDE Between Visual Basic and FoxPro

Last reviewed: June 21, 1995
Article ID: Q113477
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, version 3.0

SUMMARY

This article outlines the steps necessary to initiate dynamic data exchange (DDE) between a FoxPro Macro and a Visual Basic application at run time. Specifically, this article demonstrates how to:

  • Prepare and load a sample FoxPro Macro that will perform DDE.
  • Initiate a manual DDE link.
  • Use LinkRequest to return information generated by the FoxPro application.

MORE INFORMATION

A destination application sends commands through DDE to the source application to establish a link. Through DDE, the source provides data to the destination at the request of the destination or accepts information at the request of the destination.

The following example shows how to establish a DDE conversation between a FoxPro application and a Visual Basic application.

Preparing FoxPro for DDE

  1. Start FoxPro for Windows.

  2. From the FoxPro menu, choose Select Run Application. A dialog box should appear offering you the FoxPro applications available to run.

  3. Locate \FoxPro\Sample\DDE\DDEData.Prg. Double-click the application name or click to select the application, and choose the Run button. This starts and runs a FoxPro application that will respond to the DDE commands from Visual Basic. This code sets up the equivalent of a Visual Basic Select Case to identify the commands sent and determine which' portion of the code to run. Examine the FoxPro code for more detail on how this is accomplished with FoxPro.

Preparing Visual Basic for DDE

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add a Text box (Text1) to Form1.

  3. Add the following code in the Form_Click event of the form:

       Sub Form_Click ()
          Text1.LinkMode = 0           ' Disable any existing links.
          ' Enter the following two lines as one, single line of code:
          Text1.LinkTopic =
             "ddedata|c:\foxpro\sample\organize\dbfs;TABLE personal"
    
          ' This sets your link to : foxapp|databasename;TABLE tablename
          Text1.LinkMode = 2           ' Set cold link.
          Text1.LinkItem = "FirstRow"
          ' This link item is a defined word that the foxapp searches on.
          Text1.LinkRequest            ' Ask for the return value from FoxPro.
       End Sub
    
    
This code initiates a manual DDE link from Visual Basic for Windows to FoxPro for Windows. It then uses LinkRequest to request the FirstRow of information from FoxPro, which is returned in Text1.Text.

The syntax for a more generic example would be:

Text1.LinkMode = 0 Text1.LinkTopic = "<FoxAppName>|<PathToDB>;<FoxsDataParam> <FoxsItemParam>"

FoxPro handles all of the recognized actions in a Do Case statement, which is equivalent to a Visual Basic Select Case statement. In this case, the action triggered is an INITIATE, which recognizes only certain sData, sItem combinations. INITIATE expected data is: the keyword TABLE and the name of the table (tablename). The next action triggered is REQUEST, which recognizes only keywords in a nested Do Case statement.


Additional reference words: FOXPRO 2.50 Fox Pro 3.00
KBCategory: kbinterop kbcode
KBSubCategory: IAPDDE


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: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.