ID Number: Q74861
1.00
WINDOWS
Summary:
This article outlines the steps necessary to initiate dynamic data
exchange (DDE) between a Microsoft Visual Basic client application and
a Visual Basic server application.
This article demonstrates how to:
- Create a Visual Basic application to function as a server.
- Create a Visual Basic application to function as a client.
- Initiate a cold DDE link (information updated upon request from the
client) between the client application and the server application.
- Use LinkRequest to update information in the client application
from information in the server application.
- Initiate a hot DDE link (information updated automatically from
server to client) between the client application and the server
application.
- Use LinkPoke to send information from the client application to the
server application.
- Change the LinkMode property between hot and cold.
This information applies to Microsoft Visual Basic programming system
version 1.0 for Microsoft Windows.
More Information:
A client application sends commands through DDE to the server
application to establish a link. Through DDE, the server provides data
to the client at the request of the client or accepts information at
the request of the client.
Example
-------
The steps below are an example of how to establish a DDE conversation
between two Visual Basic applications.
First, create the server application in Visual Basic:
1. Start Visual Basic, and Form1 will be created by default.
2. Change the Caption property of Form1 to "Server".
3. Put a Text Box (Text1) on Form1.
4. Save the form and project with the name SERVER.
5. From the File menu, choose Make EXE File. In the Make EXE File
dialog box, choose OK to accept SERVER.EXE as the name of the EXE
file.
Second, create the client application in Visual Basic:
1. From the File menu, choose New Project. Form1 will be created by
default.
2. Change the Caption property of Form1 to "Client".
3. Create the following controls with the following properties on
Form1:
Default Name Caption CtlName
------------ ------- -------
Text1 (Not applicable) Text1
Option1 Cold Link ColdLink
Option2 Hot Link HotLink
Command1 Poke Poke
Command2 Request Request
4. Add the following code to the General Declaration section of Form1:
Const TRUE = -1
Const FALSE = 0
Const HOT = 1
Const COLD = 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 server application that was
'created earlier
z% = Shell("C:\VB\SERVER", 1)
z% = DoEvents() 'Causes Windows to finish
'processing the Shell command.
Text1.LinkMode = NONE 'Clears DDE link if it already exists.
Text1.LinkTopic = "Server|Form1" 'Sets up link with VB server.
Text1.LinkItem = "Text1" 'Set link to text box on server.
Text1.LinkMode = COLD 'Establish a cold DDE link.
ColdLink.Value = TRUE 'Sets appropriate option button.
End Sub
6. Add the following code to the Click event procedure of ColdLink:
Sub ColdLink_Click ()
Request.Visible = TRUE 'Make request button valid.
Text1.LinkMode = NONE 'Clear DDE Link.
Text1.LinkMode = COLD 'Reestablish new LinkMode.
End Sub
7. Add the following code to the Clink event procedure of HotLink:
Sub HotLink_Click ()
Request.Visible = FALSE 'No need for button with hot link.
Text1.LinkMode = NONE 'Clear DDE Link.
Text1.LinkMode = HOT 'Reestablish new LinkMode.
End Sub
8. Add the following code to the Click event procedure of Request:
Sub Request_Click ()
'With a cold DDE link, this button will be visible, and when
'selected it will request an update of information from the server
'application to the client application.
Text1.LinkRequest
End Sub
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 selected, will poke information from the client application
'into the server application.
Text1.LinkPoke
End Sub
You can now run the Visual Basic client 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
below).
1. From the File menu, choose Save and save the form and project with
the name CLIENT.
2. From the File menu, choose Make EXE File with the name CLIENT.EXE.
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 client application will load and the server
application will automatically start.
You can now experiment with DDE between Visual Basic applications:
1. Try typing some text into the server's text box and then click the
Request button. The text appears in the client's text box.
2. Click the Hot Link button and then type some more text into the
server's text box. The text is automatically updated in the
client's text box.
3. Type some text into the client's text box and click the Poke
button. The text is sent to the server's text box.
You can also establish DDE between applications at design time, as
described on page 356 of the "Microsoft Visual Basic: Programmer's
Guide" version 1.0 manual.
For additional information on dynamic data exchange (DDE) between
Visual Basic 1.0 and other Windows applications, query on the
following words:
DDE and Visual Basic
Additional reference words: 1.00