Microsoft KB Archive/74861

= Example of Client-Server DDE Between Visual Basic Applications =

Article ID: 74861

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 1.0 Standard Edition

-



This article was previously published under Q74861



SUMMARY
This article outlines the steps necessary to initiate dynamic data exchange (DDE) between a Microsoft Visual Basic destination application and a Visual Basic source application.

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 application.
 * 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 source application.
 * Use LinkPoke to send information from the destination application to the source application.
 * Change the LinkMode property between automatic and manual.



MORE INFORMATION
This information is included with the Help file provided with Microsoft Professional Toolkit for Visual Basic version 1.0, Microsoft Visual Basic version 2.0, and Microsoft Visual Basic version 3.0.

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.

Step-by-Step Example
The steps below show how to establish a DDE conversation between two Visual Basic applications.

STEP ONE: Create the Source Application in Visual Basic

 * 1) Start a new project in Visual Basic. Form1 is created by default.
 * 2) Change the Caption property of Form1 to Source.
 * 3) Change the Form1 LinkMode property to 1 - Source.
 * 4) Put a Text Box (Text1) on Form1.
 * 5) Save the form and project with the name SOURCE.
 * 6) 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 file.

STEP TWO: Create the Destination Application in Visual Basic
 From the File menu, choose New Project. Form1 is created by default. Change the Caption property of Form1 to Destination.  Add the following controls to Form1, and give them the properties indicated:   Default Name   Caption            Name -  Text1          (Not applicable)   Text1 Option1       Manual Link        ManualLink Option2       Automatic Link     AutomaticLink Command1      Poke               Poke Command2      Request            Request

  Add the following code to the General Declaration section of Form1: Const AUTOMATIC= 1 Const MANUAL = 2 Const NONE = 0

'(NOTE: For Visual Basic version 1.0, also add the following   '        constants:   'Const True = -1   'Const False = 0

  Add the following code to the Load event procedure of Form1: Sub Form_Load 'This procedure will start the VB source application.

z% = Shell(&quot;SOURCE&quot;, 1)

z% = DoEvents  'Causes Windows to finish processing Shell command.

Text1.LinkMode = NONE  'Clears DDE link if it already exists.

Text1.LinkTopic = &quot;Source|Form1&quot;  'Sets up link with VB source. Text1.LinkItem = &quot;Text1&quot;          'Set link to text box on source. Text1.LinkMode = MANUAL           'Establish a manual DDE link. ManualLink.Value = TRUE           'Sets appropriate option button. End Sub

  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. End Sub

</li>  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. End Sub

</li>  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. Text1.LinkRequest End Sub

</li>  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. Text1.LinkPoke End Sub

</li></ol>

STEP THREE: Run the Visual Basic Destination Application
Choose one of these options:


 * Run the Visual Basic destination application from the VB.EXE environment by skipping to step 4 below.
 * Save the application. Then create an .EXE file and run it from Windows by beginning with step 1 below.


 * 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, and give it the name DEST.EXE.
 * 3) Exit the Visual Basic environment (VB.EXE).
 * 4) Run the application from Windows if it's an .EXE file or from the VB.EXE environment.
 * 5) Form1 of the destination application will load and the source application will automatically start.

STEP FOUR: Experiment with DDE Between Visual Basic Applications

 * 1) Try typing some text into the source application's text box. Then click the Request button. The text appears in the destination application's text box.
 * 2) Click the Automatic Link button and then type some more text into the source application's text box. The text is automatically updated in the destination application's text box.
 * 3) Type some text into the destination application's text box. Then click the Poke button to send the text to the source application's text box.

For additional information on dynamic data exchange (DDE) between Visual Basic and other Windows-based applications, query on the following words in the Microsoft Knowledge Base:

DDE and Visual Basic

Additional query words: 2.00 3.00

Keywords: KB74861

-

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

© Microsoft Corporation. All rights reserved.