How to Use DDE Between Visual Basic and FoxPro
ID: Q113477
|
The information in this article applies to:
-
Microsoft Visual Basic Standard and Professional Editions 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
- Start FoxPro for Windows.
- From the FoxPro menu, choose Select Run Application. A dialog box should
appear offering you the FoxPro applications available to run.
- 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 = "<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 query words:
FOXPRO 2.50 Fox Pro 3.00
Keywords :
Version :
Platform :
Issue type :