Examples: FindNthElement method

This agent displays each paragraph in the Body item of the current or first selected document in reverse order.

Sub Initialize
  Dim session As New 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
  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
  If rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Then
    count% = 0
    Do
      count% = count% + 1
    Loop While rtnav.FindNextElement
  Else
    Messagebox "No text in Body",, "No text"
    Exit Sub
  End If
  Set rtrange = body.CreateRange
  For i% = count% To 1 Step -1
    If Not rtnav.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH, _
    i%) Then
      Messagebox "Element " & count%,, "Cannot find element"
      Exit Sub
    End If
    Call rtrange.SetBegin(rtnav)
    Messagebox rtrange.TextParagraph,, "Paragraph " & i%    
  Next
End Sub