Using DDE Between Visual Basic and Q+E for Windows

Last reviewed: February 20, 1996
Article ID: Q75090
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

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.

  1. Start Visual Basic for Windows. Form1 will be created by default.

  2. 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.)
    
    

  3. 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.
    
    

  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 = MANUAL         ' Establish a manual DDE link.
        ManualLink.Value = TRUE
    End Sub
    
    

  5. 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
    
    

  6. 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
    
    

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

  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 destination application to the
        ' source application.
        Text1.LinkPoke
    End Sub
    
    
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 "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 for Windows 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 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 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 for Windows 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 the Communicating with Other Applications chapter of the "Microsoft Visual Basic: Programmer's Guide."

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 reference words: 1.00 2.00 3.00
KBCategory: kbinterop kbprg kbcode
KBSubcategory: IAPDDE


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 20, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.