Microsoft KB Archive/75090

= Using DDE Between Visual Basic and Q+E for Windows =

Article ID: 75090

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 Q75090



SUMMARY
This article describes how to initiate a Dynamic Data Exchange (DDE) conversation between a Microsoft Visual Basic for Windows destination application and a Pioneer Software Q+E for Windows source 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 manual DDE link (information updated upon request from the destination) between Visual Basic for Windows (the destination) and Q+E (the source).
 * 3) Use LinkRequest to update information in Visual Basic for Windows (the destination) based on information contained in Q+E (the source).
 * 4) Initiate a automatic DDE link (information updated automatically from source to destination) between Visual Basic for Windows (the destination) and Q+E (the source).
 * 5) Use LinkPoke to send information from Visual Basic for Windows (the destination) to Q+E (the source).
 * 6) Change the LinkMode property between Automatic and Manual.



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 steps serve as a example of how to establish a DDE conversation between Visual Basic for Windows and Q+E.

First, generate a Q+E database file to act as the source.


 * 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 destination application in Visual Basic for Windows.

The destination is the application that performs the link operations. It prompts the source to send information or informs the source that information is being sent.

 Start Visual Basic for Windows. Form1 will be created by default.  Create the following controls with the following properties on Form1:   Default Name     Caption            Name ---           ---   Text1            (not applicable)   Text1 Option1         Manual Link        ManualLink Option2         Automatic Link     AutomaticLink Command1        Poke               Poke Command2        Request            Request (In Visual Basic version 1.0 for Windows, set the CtlName Property for the above objects instead of the Name property.)   Add the following code to the General Declaration section of Form1: Const AUTOMATIC = 1 Const MANUAL = 2 Const NONE = 0

' Const TRUE = -1  ' In Visual Basic 1.0 for Windows uncomment ' Const FALSE = 0  ' these two lines.   Add the following code to the Load event procedure of Form1: Sub Form_Load        ' This procedure will start Q+E and load the ' file &quot;ADDR.DBF&quot;. z% = Shell(&quot;C:\EXCEL\QE C:\EXCEL\QE\ADDR.DBF&quot;,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 = &quot;QE|QUERY1&quot;  ' Sets up link with Q+E. Text1.LinkItem = &quot;R1C1&quot;        ' Set link to first cell on                                    ' spreadsheet. Text1.LinkMode = MANUAL        ' Establish a manual DDE link. ManualLink.Value = TRUE End Sub   Add the following code to the Click event procedure of the Manual Link button: Sub ManualLink_Click Request.Visible = TRUE      ' Make request button valid. Text1.LinkMode = NONE       ' Clear DDE Link. Text1.LinkMode = MANUAL     ' Reestablish new LinkMode. End Sub   Add the following code to the Click event procedure of the AutomaticLink button: Sub HotLink_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 the Request button: 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 the Poke button: Sub Poke_Click ' With any DDE link this button will be visible and when selected ' it will poke information from the destination application to the ' source application. Text1.LinkPoke End Sub </li></ol>

You can now run the Visual Basic for Windows destination application from the Visual Basic for Windows 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 for Windows.
 * 4) Run the application (from Windows if an .EXE file, or from the Run menu if from the Visual Basic for Windows environment). Form1 of the destination 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 &quot;Q + E,&quot; NOT &quot;Q + E - ADDR.DBF.&quot; 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 for Windows and Q+E for Windows:


 * 1) Try typing some text in R1C1 (the cell that holds the name &quot;Tyler&quot;) in the Q+E spreadsheet and then choose the Request button. The text will appear in the Visual Basic for Windows text box.
 * 2) Choose the Automatic Link button and then type some more text in R1C1 of the Q+E spreadsheet. The text is automatically updated in the Visual Basic for Windows text box.
 * 3) Type some text in the text box in the Visual Basic for Windows application and choose the Poke button. The text is sent to R1C1 in the Q+E spreadsheet.

NOTE: 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 for Windows when the Allow Editing option is not chosen will cause the program to crash and result in a &quot;Foreign application won't perform DDE method or operation&quot; error message. Attempting to change the contents of the spreadsheet from Q+E will result in a &quot;Use the allow editing command before making changes&quot; 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 the Communicating with Other Applications chapter of the &quot;Microsoft Visual Basic: Programmer's Guide.&quot;

For additional information on DDE between Microsoft Visual Basic for Windows 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: kbcode KB75090

-

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

© Microsoft Corporation. All rights reserved.