Microsoft KB Archive/113477

= How To Use DDE Between Visual Basic and FoxPro =

Article ID: 113477

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



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
 Start a new project in Visual Basic. Form1 is created by default. Add a Text box (Text1) to Form1.  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 = "|; " 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 query words: FOXPRO 2.50 Fox Pro 3.00

Keywords: kbhowto KB113477

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.