Examples: FindNextString method

This agent finds the next string that matches user input in the Body item of the current or first selected document.

Dim session As NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim body As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtrange As NotesRichTextRange

Sub Initialize
  Set session = New NotesSession
  Set db = session.CurrentDatabase
  Set dc = db.UnprocessedDocuments
  If dc.Count = 0 Then
    Messagebox "No document selected",, "No doc"
    Exit Sub
  End If
  Set doc = dc.GetFirstDocument
  Set body = doc.GetFirstItem("Body")
  Set rtnav = body.CreateNavigator
  Set rtrange = body.CreateRange
  searchString$ = Inputbox$("Enter the search string", _
  "Search string")
  If searchString$ = "" Then Exit Sub
  If rtnav.FindFirstString(searchString$, _
  RT_FIND_CASEINSENSITIVE) Then
    Do
      Call rtrange.SetBegin(rtnav)
      Messagebox rtrange.TextRun,, searchString$
    Loop While rtnav.FindNextString(searchString$, _
    RT_FIND_CASEINSENSITIVE)
  Else
    Messagebox searchString$,, "String not found"
  End If
End Sub