Examples: Navigating in rich text items in LotusScript® classes

This agent counts all the elements in the Body item of a document.

Sub Initialize
  Dim session As NotesSession
  Dim db As NotesDatabase
  Dim dc As NotesDocumentCollection
  Dim doc As NotesDocument
  Dim body As NotesRichTextItem
  Dim rtnav As NotesRichTextNavigator
  Set session = New NotesSession
  Set db = session.CurrentDatabase
  Set dc = db.UnprocessedDocuments
  Set doc = dc.GetFirstDocument
  Set body = doc.GetFirstItem("Body")
  Set rtnav = body.CreateNavigator
  REM Get count of doclinks
  count% = GetElementCount(rtnav, RTELEM_TYPE_DOCLINK)
  msg$ = msg$ & "Doclinks:" & Chr(9) & Chr(9) & count% & Chr(10)
  REM Get count of file attachments
  count% = GetElementCount(rtnav, RTELEM_TYPE_FILEATTACHMENT)
  msg$ = msg$ & "File attachments:" & Chr(9) & count% & Chr(10)
  REM Get count of embedded objects
  count% = GetElementCount(rtnav, RTELEM_TYPE_OLE)
  msg$ = msg$ & "Embedded objects:" & Chr(9) & count% & Chr(10)
  REM Get count of sections
  count% = GetElementCount(rtnav, RTELEM_TYPE_SECTION)
  msg$ = msg$ & "Sections:" & Chr(9)  & Chr(9) & count% & Chr(10)
  REM Get count of tables
  count% = GetElementCount(rtnav, RTELEM_TYPE_TABLE)
  msg$ = msg$ & "Tables:" & Chr(9)  & Chr(9) & count% & Chr(10)
  REM Get count of tables
  count% = GetElementCount(rtnav, RTELEM_TYPE_TABLE)
  msg$ = msg$ & "Tables:" & Chr(9)  & Chr(9) & count% & Chr(10)
  REM Get count of text paragraphs
  count% = GetElementCount(rtnav, RTELEM_TYPE_TEXTPARAGRAPH)
  msg$ = msg$ & "Text paragraphs:" & Chr(9)  & count% & Chr(10)
  REM Get count of text runs
  count% = GetElementCount(rtnav, RTELEM_TYPE_TEXTRUN)
  msg$ = msg$ & "Text runs:" & Chr(9)  & Chr(9)  & count% & Chr(10)
  REM Display counts
  Messagebox msg$,, doc.Subject(0)
End Sub

Function GetElementCount(rtnav As NotesRichTextNavigator, eType As Integer) As Integer
  GetElementCount = 0
  If rtnav.FindFirstElement(eType) Then
    Do
      GetElementCount = GetElementCount + 1
    Loop While rtnav.FindNextElement()
  End If
End Function