See Also Example
Applies To
Form, label
Description
For a destination You use LinkTopic with the LinkItem property to specify the complete data link.
For a source formdetermines the topic that the source form responds to in a DDE conversation.
Usage
[form.][label.|picturebox.|textbox.]LinkTopic[ = link ]
Remarks
The LinkTopic property consists of a string that supplies part of the information necessary to set up either a destination link or source link. The string you use depends on whether you're working with a destination control or a source form. Each string corresponds to one or more elements of standard DDE syntaxapplication, topic, and item.
Destination control To set LinkTopic for a destination control, use a string with the syntax application|topic, as follows:
application is the name of the application from which data is requested, usually the executable file name without any extensionfor example, "Excel" (for Microsoft Excel).
The "pipe" character (|, or character code 124) separates the application from the topic.
topic is the fundamental data grouping used in that applicationfor example, a worksheet in Microsoft Excel.
In addition, for a destination control only, you need to set the related LinkItem property to specify the item element for the link. A cell reference such as "R1C1," for example, would correspond to an item in a Microsoft Excel worksheet.
Source form To set LinkTopic for a source, change the default string, FormN, to an appropriate identifier for the form. A destination application uses this string as the topic argument when establishing a DDE link with the form. Although this string is all you need to set LinkTopic within Visual Basic for a source form, the destination application itself also needs to specify:
The application element that the destination application uses, which is either the Visual Basic project name without the .MAK extension (if you are running your application in the Visual Basic development environment), or the Visual Basic application name without the .EXE extension (if you are running your application as a stand-alone executable file ). The EXEName property of the App object provides this string in your Visual Basic code unless the file name was changed by the user. (App.EXEName always returns the actual file name of the application on disk, whereas DDE always uses the original name that was specified in the Make EXE dialog.)
The item element that the destination application uses, which corresponds to the Name property for the label, picture box, or text box on the source form.
An example of a valid reference from Microsoft Excel to a Visual Basic application acting as a source is: =VizBasicApplication|FormN!TextBox1. You would enter this reference for a destination cell in the Microsoft Excel formula bar.
Strings and syntax While the standard definition for a DDE link includes the application, topic, and item elements, the actual syntax used within applications for a destination link to a source application may vary slightly. For example, within Microsoft Excel, you use the syntax application|topic!item. Within Microsoft Word for Windows, you use application topic item (no pipe character or exclamation mark). Within a Visual Basic application, you use application|topic; the exclamation mark (!) for topic is implicit.
Activating and maintaining data links To activate the data link set with LinkTopic, set the LinkMode property to the appropriate nonzero value to specify the type of link you want. As a general rule, you should set LinkMode after you specify LinkTopic. For a destination control, changing LinkTopic breaks an existing link and terminates the DDE conversation. For a source form, changing LinkTopic breaks all destination links that are using that topic. For these reasons, you should always set the LinkMode property to 0 before changing LinkTopic. After changing LinkTopic for a destination control, you must set LinkMode to 1 (Automatic), 2 (Manual), or 3 (Notify) to establish a conversation with the new topic.
Note Setting a permanent data link at design time with the Paste Link command from the Edit menu also sets the LinkMode, LinkTopic, and LinkItem properties. This creates a link that is saved with the form. Each time the form is loaded, Visual Basic attempts to reestablish the conversation.
Data Type
String
Help:
Creating a DDE Source or Destination Link
LinkClose Event
LinkError Event
LinkItem Property
LinkMode Property
LinkOpen Event
LinkSend Method
Using DDE
Programmer's Guide:
Chapter 20, "Communicating with Other Applications"
LinkItem, LInkMode, LinkTopic Properties Example
In the example, each mouse click causes a cell in a Microsoft Excel worksheet to update the contents of a Visual Basic text box. To try this example, start Microsoft Excel, open a new worksheet named Sheet1, and put some data in the first column. Then in Visual Basic, create a form with a text box. Paste the code into the Declarations section and press F5 to run the program.
Sub Form_Click ()
Dim CurRow As String
Static Row ' Worksheet row number.
Row = Row + 1 ' Increment Row.
If Row = 1 Then ' First time only.
' Make sure the link is not active.
Text1.LinkMode = 0
' Set the application name and topic name.
Text1.LinkTopic = "Excel|Sheet1"
Text1.LinkItem = "R1C1" ' Set the LinkItem.
Text1.LinkMode = 1 ' Activate the link to ' Automatic.
Else
' Update the Row in the data item.
CurRow = "R" & Row & "C1"
Text1.LinkItem = CurRow ' Set the LinkItem.
End If
End Sub