ID Number: Q75090
1.00
WINDOWS
Summary:
This article describes how to initiate a dynamic data exchange (DDE)
conversation between a Visual Basic client application and a Pioneer
Software Q+E for Windows server application. (Q+E is a database query
tool.)
This article demonstrates how to:
1. Prepare a Q+E database file for active DDE.
2. Initiate a cold DDE link (information updated upon request from the
client) between Visual Basic (the client) and Q+E (the server).
3. Use LinkRequest to update information in Visual Basic (the client)
based on information contained in Q+E (the server).
4. Initiate a hot DDE link (information updated automatically from
server to client) between Visual Basic (the client) and Q+E (the
server).
5. Use LinkPoke to send information from Visual Basic (the client) to
Q+E (the server).
6. Change the LinkMode property between hot and cold.
This information applies to Microsoft Visual Basic programming system
version 1.0 for Windows and to Pioneer Software Q+E.
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.
The following steps serve as a example of how to establish a DDE
conversation between Visual Basic and Q+E.
First, generate a Q+E database file to act as the server.
1. Create a database (.DBF) file (see the Q+E manuals for the
procedure). For this example, you will use one of the default
files, ADDR.DBF, that is provided with Microsoft Excel for Windows.
2. If Q+E is already running, exit Q+E. For this example to work
properly, Q+E must not be loaded and running.
Next, create the client application in Visual Basic.
The client is the application that performs the link operations. It
prompts the server to send information or informs the server that
information is being sent.
1. Start Visual Basic. Form1 will be created by default.
2. 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
3. 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
4. Add the following code to the Load event procedure of Form1:
Sub Form_Load () 'This procedure will start Q+E and load the
'file "ADDR.DBF"
z% = Shell("C:\EXCEL\QE C:\EXCEL\QE\ADDR.DBF",1)
z% = DoEvents () 'Process Windows events. This
'ensures that Q+E will be
'executed before any attempt is
'made to perform DDE with it.
Text1.LinkMode = NONE 'Clears DDE link if it already
'exists.
Text1.LinkTopic = "QE|QUERY1" 'Sets up link with Q+E.
Text1.LinkItem = "R1C1" 'Set link to first cell on
'spreadsheet.
Text1.LinkMode = COLD 'Establish a cold DDE link.
ColdLink.Value = TRUE
End Sub
5. Add the following code to the Click event procedure of the
Cold Link button:
Sub ColdLink_Click ()
Request.Visible = TRUE 'Make request button valid.
Text1.LinkMode = NONE 'Clear DDE Link.
Text1.LinkMode = COLD 'Reestablish new LinkMode.
End Sub
6. Add the following code to the Clink event procedure of the
Hot Link button:
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
7. Add the following code to the Click event procedure of the
Request button:
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
8. Add the following code to the Click event procedure of the Poke
button:
Sub Poke_Click ()
'With any DDE link this button will be visible and when selected
'it will poke information from the client application to the
'server application.
Text1.LinkPoke
End Sub
You can now run the Visual Basic client application from the Visual
Basic environment (skip to step 4) 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, save the Form and Project using the name
CLIENT.
2. From the File menu, choose Make an EXE File, and name it
CLIENT.EXE.
3. Exit Visual Basic.
4. Run the application (from Windows if an .EXE file or from the Run
menu if from the Visual Basic environment). Form1 of the client
application will be loaded and Q+E will automatically be started
with the database file ADDR.DBF loaded.
5. Make sure that the main title bar in Q+E reads "Q + E," NOT
"Q + E - ADDR.DBF." If the title bar is incorrect, then from the
Window menu of Q+E, choose Arrange All.
You can now experiment with DDE between Visual Basic and Q+E for
Windows:
1. Try typing some text in R1C1 (the cell that holds the name
"Tyler") in the Q+E spreadsheet and then choose the Request button.
The text will appear in the Visual Basic text box.
2. Choose the Hot Link button and then type some more text in R1C1 of
the Q+E spreadsheet. The text is automatically updated in the Visual
Basic text box.
3. Type some text in the text box in the Visual Basic application and
choose the Poke button. The text is sent to R1C1 in the Q+E
spreadsheet.
Note that if you do not have the Allow Editing option checked on
the Edit menu in Q+E, you will not be able to change the contents of
the Q+E spreadsheet. This may prevent some DDE operations. For
example, attempting to LinkPoke to Q+E from Visual Basic when the
Allow Editing option is not chosen will cause the program to crash
and result in a "Foreign application won't perform DDE method or
operation" error message. Attempting to change the contents of the
spreadsheet from Q+E will result in a "Use the allow editing command
before making changes" error message. From the Edit menu of Q+E,
choose Allow Editing to enable this option. When viewed from the Edit
menu, Allow Editing should have a check mark next to it when enabled.
You can also establish DDE between applications at design time. For
more information, see page 356 of the "Microsoft Visual Basic:
Programmer's Guide" version 1.0 manual.
For additional information on dynamic data exchange (DDE) between
Microsoft Visual Basic version 1.0 and other Windows applications,
query on the following words:
DDE and Visual Basic
Additional reference words: 1.00