Microsoft KB Archive/106238

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


Article ID: 106238

Article Last Modified on 12/9/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



This article was previously published under Q106238

SUMMARY

Visual Basic programs can provide an Edit Copy command that puts text onto the Clipboard along with the information needed to make a DDE link to that text. Likewise, you can provide an Edit Paste command that extracts the text and an Edit Paste Link command that extracts the DDE link information, and then initiates a DDE conversation to the source text. You can implement these clipboard operations using the GetText and SetText format CF_LINK (&HBF00) with a string of the format:

Application|Topic!Item

The Visual Basic manuals and Help menu do not describe how to use the Clipboard format CF_LINK.

NOTE: Visual Basic only supports Clipboard DDE operations for text.

MORE INFORMATION

When a Visual Basic DDE source program uses SetText with format CF_LINK, the format of the string is exe|topic!item.

  • exe is the value of App.EXEName.
  • topic is a form's LinkTopic value.
  • item is the Name of a control.

For example:

   Project1|Form1!Text1
                

Step-by-Step Example

  1. Start Visual Basic or from the File menu, choose Open Project (ALT, F, O) if Visual Basic is already running. Form1 is created.
  2. Change the form property LinkMode to 1 - Source.
  3. Place a text box named Text1 on the form.
  4. From the Window menu, choose Menu Design and create the following menu structure.

       Caption     Name        Indent Level
       ------------------------------------
       Edit        mEdit         0
       Copy        mCopy         1
       Paste       mPaste        1
       Paste Link  mPasteLink    1
                            
  5. Enter the following code in the general declarations section:

       Const CF_TEXT = 1
       Const CF_LINK = &HBF00
                            
  6. Enter the following code into the form:

       Sub mEdit_Click ()
          mCopy.Enabled = Text1.SelLength > 0
          mPaste.Enabled = Clipboard.GetFormat(CF_TEXT)
          mPasteLink.Enabled = Clipboard.GetFormat(CF_LINK)
       End Sub
    
       Sub mCopy_Click ()
          Clipboard.Clear
          Clipboard.SetText Text1.SelText, CF_TEXT
          Clipboard.SetText "Project1|Form1!Text1", CF_LINK
       End Sub
    
       Sub mPaste_Click ()
          Text1.LinkMode = 0  ' discontinue previous link
          Text1.SelText = Clipboard.GetText(CF_TEXT)
       End Sub
    
       Sub mPasteLink_Click ()
          Dim topic As String  ' app|topic!item
          Dim bang As Integer  ' index of ! within topic
    
          topic = Clipboard.GetText(CF_LINK)
          bang = InStr(topic, "!")
          If bang <> 0 Then
             Text1.LinkMode = 0
             Text1.LinkTopic = Mid$(topic, 1, bang - 1)
             Text1.LinkItem = Mid$(topic, bang + 1)
             On Error Resume Next
             Text1.LinkMode = 1  ' automatic
             If Err <> 0 Then
                MsgBox "Cannot paste link"
             End If
          End If
       End Sub
                            
  7. From the File menu, choose Make EXE and click OK. This creates PROJECT1.EXE.
  8. Launch PROJECT1.EXE twice so that two instances are running. Position them so that you can see them both at the same time. In the first instance, select the text in the text box, then from the Edit menu choose copy. Switch to the second instance and from the Edit menu choose Paste Link. Switch back to the first instance and change the contents of the text box. These changes appear immediately in the second instance.



Additional query words: docerr 3.00

Keywords: KB106238