INFO: How to Use DDE in Visual Basic to Communicate with Other Windows Programs
This article was previously published under Q189498
This article has been archived. It is offered "as is" and will no longer be updated.
This article describes how to use Dynamic Data Exchange (DDE) from a Visual Basic program. Although Visual Basic offers more powerful, robust and reliable intercommunication between programs by using OLE, it still supports the older DDE technology. You can use DDE to link to and share data between programs.
Using OLE to communicate with other programs is better than using DDE with Visual Basic. OLE offers you better performance than DDE does. If a program supports OLE automation, it exposes an "Object Model" you can use to manipulate the program (through code) to complete actions for you. DDE is more useful in communicating with older programs that might not support OLE but do support DDE, and many 16-bit programs fall into this category.
Microsoft recommends that you use OLE rather than DDE to communicate with another program when you are developing your Visual Basic program. However, because there are times when you may need or want to use DDE, this article describes how to use DDE from a Visual Basic program.
Visual Basic can exchange data, such as information, commands or keystrokes, with any program that supports DDE. A DDE link requires the following three things:
- Program name
Specific to Visual Basic, the LinkTopic property supplies a combination of the program name and topic parameters. The LinkTopic property is available for Label, PictureBox, or TextBox controls which can share data through a DDE connection. The program name and topic parameters are combined by using the pipe character (|) as the separator. For example, to create a DDE link with Microsoft Word as the source program and by using the System topic. the LinkTopic property of a textbox would be:
Text1.LinkTopic="WinWord|System"When Visual Basic is the source program for the DDE link, the LinkTopic of the form which contains the control to be shared is set to a known name. This known name is used in the LinkTopic of the Visual Basic destination program as the topic information. For example, to access data from a form with a LinkTopic that is set to "DDELink", a Visual Basic destination program would have a matching control with a LinkTopic set to "program name|DDELink".
The LinkItem property corresponds to the item parameter in a DDE connection, and this property is set to a corresponding item in the source program, for example, the "Total" cell in an Excel spreadsheet. The LinkItem property is set for the control that is used as in a destination program. When a Visual Basic form is the source in a DDE connection, the name of the control on the form can be the item argument in the program|topic|item string that is used by the destination program. When Visual Basic is used as both the source and destination program, the LinkItem property of the destination program would be set to the name of the control in the Visual Basic source program. For example, with Visual Basic used as both the source and destination program and a text box that is named txtSource as the item in the source program, a corresponding txtData text box in the destination program would have its LinkItem property set to txtSource:
txtData.LinkItem = "txtSource"Before a connection can be established, the mechanism to update the information needs to be set. In a DDE connection, there are three types of links:
Once a DDE link has been established, there are several methods and events in Visual Basic that can be used to control how data is sent between the source and the destination program.
MethodsLinkRequest: Asks the source program to update the contents of a destination item.
LinkExecute: Sends a command string to the source program.
LinkPoke: Transfers the contents of the item control to the source program. Typically, information in a DDE conversation flows from the source to the destination. However, LinkPoke provides a destination object with the ability to supply data to the source.
LinkSend: Transfers the contents of a PictureBox control to the destination program in a DDE conversation.
EventsLinkOpen: Occurs when a DDE link is being initiated.
LinkClose: Occurs when a DDE link terminates. Either program in a DDE conversation may terminate a link at any time.
LinkError: Occurs when there is an error during a DDE conversation. This event is recognized only as the result of a DDE-related error that occurs when no Visual Basic code is being executed. The error number is passed as an argument.
LinkExecute: Occurs when a command string is sent by a destination program in a DDE conversation. The destination program expects the source program to perform the operation described by the string.
LinkNotify: Occurs when the source has changed the data that is defined by the DDE link if the LinkMode property of the destination control is set to Notify.
For additional information about how to create DDE connections from Visual Basic to other applications like Visual Basic, Word or Excel, click the article numbers below to view the articles in the Microsoft Knowledge Base:
74861 Example of Client-Server DDE Between Visual Basic Applications
74862 DDE Example Between Visual Basic and Word for Windows
75089 DDE from Visual Basic for Windows to Excel for WindowsMSDN contains documentation about DDE methods, properties, and events that are supported in Visual Basic 6.0. In MSDN, set the "Active Subset" to "Visual Basic Documentation," click the Index tab, and then type DDE. The topics that are available are applicable to Visual Basic 6.0.
In Visual Basic 5.0, click Books Online on the Help menu. When Books Online appears, click Index on the View menu. When the Index search browser appears, type DDE.
not grayed out greyed applications
Article ID: 189498 - Last Review: 12/05/2015 08:57:32 - Revision: 2.0
Microsoft Visual Basic 5.0 Learning Edition, Microsoft Visual Basic 6.0 Learning Edition, Microsoft Visual Basic 5.0 Professional Edition, Microsoft Visual Basic 6.0 Professional Edition, Microsoft Visual Basic 5.0 Enterprise Edition, Microsoft Visual Basic 6.0 Enterprise Edition
- kbnosurvey kbarchive kbhowto kbenv KB189498