Bookmarks

Visual Basic User's Guide > Using Marked Text Fields

This example shows you how to use Text Control's marked text fields to create bookmarks. The first version will reference the bookmarks simply by their field numbers. The source code for this example is contained in the Samples\vb6\Field2 sample source directory.

The sample application has a Bookmark menu with two items which are named Insert and Go to.... Clicking Insert creates a marked text field at the current caret position. If a text selection exists, the selected text is converted into a field. If not, the character next to the caret is selected.

[Visual Basic 6]
Private Sub mnuBookmark_Insert_Click()
   If TXTextControl1.Text = "" Then
   MsgBox "Cannot insert bookmark if control is empty."
   Else
      If TXTextControl1.SelLength = 0 Then _
         TXTextControl1.SelLength = 1
      TXTextControl1.FieldInsert ""
   End If
End Sub 

After typing in some text and inserting a few bookmarks, select the Go To... menu item. This will launch a dialog box which allows you to enter the number of the bookmark to jump to. There is no error processing in this example, so if you enter the number of a non-existent field, nothing will happen.

Clicking the OK button executes the following procedure:

[Visual Basic 6]
Private Sub cmdOk_Click()
   Form1.TXTextControl1.FieldCurrent = Text1.Text
   Form1.TXTextControl1.SelStart = _
      Form1.TXTextControl1.FieldStart - 1
   Form1.TXTextControl1.SelLength = _
      Form1.TXTextControl1.FieldEnd - _
      Form1.TXTextControl1.FieldStart + 1
   Unload Me
End Sub 

The number which has been entered in the dialog box is taken as a value for the FieldCurrent property.