How To Use DDE Between Visual Basic and FoxPro (113477)



The information in this article applies to:

  • Microsoft Visual Basic Standard Edition for Windows 3.0
  • Microsoft Visual Basic Professional Edition for Windows 3.0

This article was previously published under Q113477

SUMMARY

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

  • Prepare and load a sample FoxPro application that will perform DDE.
  • Initiate a manual DDE link.
  • Use LinkRequest to return information generated by the FoxPro application.
NOTE: This article applies to Microsoft Visual FoxPro for Windows 2.6 only. Visual FoxPro for Windows 3.0 and later do not ship with a DDE sample.

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.

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbhowto KB113477