Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake two Visual Basic program exchange data using DDE
KeywordsDDE, data exchange
CategoriesSoftware Engineering
 
First, make a DDE source program.

  • Set the form's LinkMode property to 1 - Source.
  • Put a TextBox on the form.
  • Compile it into an executable.

    That's all you need to do with the source.

    Second, make a DDE client program.

    • Start the source program or make sure it is already running.
    • Make a TextBox. Set its LinkTopic property to the name of the source program followed by the the name of the source program's form. For example, if the source program is Source.exe and the source form is Form1, then use "Source|Form1".
    • Set the TextBox's LinkItem property to the name of the TextBox on the source form.
    • To make the client automatically copy the source program's text whenever it changes, set the TextBox's LinkMode property to vbLinkAutomatic.
    • To make the client copy the source program's text only when requested, set the TextBox's LinkMode property to vbLinkManual.
    • To manually copy the value from the source program to the client program, invoke the TextBox's LinkRequest method.
    • To send data from the client program back to the source program, invoke the TextBox's LinkPoke method.

    Now you can run the client program and have it exchange data with the source.

    The following code is in the client program. The source program contains no code.

 
Private Sub Form_Load()
Dim app_path As String

    ' Start the Source program.
    app_path = App.Path
    If Right$(app_path, 1) <> "\" Then app_path = app_path _
        & "\"
    Shell app_path & "Source", vbNormalFocus
    DoEvents

    ' Link to Source's Text1 control.
    Text1.LinkTopic = "Source|Form1"
    Text1.LinkItem = "Text1"

    ' Start with a manual link.
    optManual.Value = True
End Sub

' Use an automatic link so we get text from Source
' whenever its text changes.
Private Sub optAutomatic_Click()
    cmdGetText.Visible = False
    Text1.LinkMode = vbLinkNone
    Text1.LinkMode = vbLinkAutomatic
End Sub

' Use a manual link so we only get text from Source
' when the user clicks the Get Text button.
Private Sub optManual_Click()
    cmdGetText.Visible = True
    Text1.LinkMode = vbLinkNone
    Text1.LinkMode = vbLinkManual
End Sub

' Send text to the Source program.
Private Sub cmdSendText_Click()
    Text1.LinkPoke
End Sub

' Get text from the Source program.
Private Sub cmdGetText_Click()
    Text1.LinkRequest
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated