Example of Client/Server DDE Between Visual Basic Applications
This article is reprinted from the Microsoft Knowledge Base. To view the article, maximize your help window. This information applies to Visual Basic for Windows, versions 2.0 and 3.0.
This article outlines the steps necessary to initiate dynamic data
exchange (DDE) between a Microsoft Visual Basic destination application and a Visual Basic source
This article demonstrates how to:
- Create a Visual Basic application to function as a DDE source.
- Create a Visual Basic application to function as a DDE destination.
- Initiate a manual DDE link (information updated upon request from the
destination) between the destination application and the source
- Use LinkRequest to update information in the destination application
from information in the source application.
- Initiate a automatic DDE link (information updated automatically from
source to destination) between the destination application and the
- Use LinkPoke to send information from the destination application to
the source application.
- Change the LinkMode property between automatic and manual.
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
The steps below are an example of how to establish a DDE conversation
between two Visual Basic applications.
First, create the source application in Visual Basic:
1. Start Visual Basic, and Form1 will be created by default.
2. Change the Caption property of Form1 to "Source".
3. Put a Text Box (Text1) on Form1.
4. Save the form and project with the name SOURCE.
5. From the File menu, choose Make EXE File. In the Make EXE File
dialog box, choose OK to accept SOURCE.EXE as the name of the EXE
Second, create the destination application in Visual Basic:
1. From the File menu, choose New Project. Form1 will be created by
2. Change the Caption property of Form1 to "Destination".
3. Create the following controls with the following properties on
Default Name Caption Name
------------ ------- -------
Text1 (Not applicable) Text1
Option1 Manual Link ManualLink
Option2 Automatic Link AutomaticLink
Command1 Poke Poke
Command2 Request Request
4. Add the following code to the General Declaration section of Form1:
Const AUTOMATIC= 1
Const MANUAL = 2
Const NONE = 0
5. Add the following code to the Load event procedure of Form1:
Sub Form_Load ()
'This procedure will start the VB source application that was
z% = Shell("SOURCE", 1)
z% = DoEvents() 'Causes Windows to finish
'processing the Shell command.
Text1.LinkMode = NONE 'Clears DDE link if it already
Text1.LinkTopic = "Source|Form1" 'Sets up link with VB source.
Text1.LinkItem = "Text1" 'Set link to text box on source.
Text1.LinkMode = MANUAL 'Establish a manual DDE link.
ManualLink.Value = TRUE 'Sets appropriate option button.
6. Add the following code to the Click event procedure of ManualLink:
Sub ManualLink_Click ()
Request.Visible = TRUE 'Make request button valid.
Text1.LinkMode = NONE 'Clear DDE Link.
Text1.LinkMode = MANUAL 'Reestablish new LinkMode.
7. Add the following code to the Clink event procedure of AutomaticLink:
Sub AutomaticLink_Click ()
Request.Visible = FALSE 'No need for button with automatic link.
Text1.LinkMode = NONE 'Clear DDE Link.
Text1.LinkMode = AUTOMATIC 'Reestablish new LinkMode.
8. Add the following code to the Click event procedure of Request:
Sub Request_Click ()
'With a manual DDE link, this button will be visible, and when
'selected it will request an update of information from the source
'application to the destination application.
9. Add the following code to the Click event procedure of Poke:
Sub Poke_Click ()
'With any DDE link, this button will be visible, and when it's
'selected, will poke information from the destination application
'into the source application.
You can now run the Visual Basic destination application from the VB.EXE
environment (skip to step 4 below) or you can save the application and
create an .EXE file and run that from Windows (continue to step 1
1. From the File menu, choose Save and save the form and project with
the name DEST.
2. From the File menu, choose Make EXE File with the name
3. Exit the Visual Basic environment (VB.EXE).
4. Run the application (from Windows if an .EXE file, or from the Run
menu if from the VB.EXE environment.)
5. Form1 of the destination application will load and the source
application will automatically start.
You can now experiment with DDE between Visual Basic applications:
1. Try typing some text into the source's text box and then click the
Request button. The text appears in the destination's text box.
2. Click the Automatic Link button and then type some more text into the
source's text box. The text is automatically updated in the
destination's text box.
3. Type some text into the destination's text box and click the Poke
button. The text is sent to the source's text box.