LOTUSSCRIPT/COM/OLE CLASSES


Examples: SetPositionAtEnd method
This agents gets a requested range of paragraphs from the Body item of the current document. The user specifies the numbers of the first and last paragraphs. The code uses SetBegin to mark the first paragraph in the range, and SetPositionAtEnd followed by SetEnd to mark and include the last paragraph in the range.

Sub Initialize
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim dc As NotesDocumentCollection
 Dim doc As NotesDocument
 Dim body As NotesRichTextItem
 Dim rtnavBody As NotesRichTextNavigator
 Dim rtrangePara As NotesRichTextRange
 Dim rtnavPara As NotesRichTextNavigator
 Dim rtrangePara2 As NotesRichTextRange
 Dim stringPara As String
 Dim firstPara As Integer
 Dim lastPara As Integer
 Dim counter As Integer
 Set db = session.CurrentDatabase
 Set dc = db.UnprocessedDocuments
 Set doc = dc.GetFirstDocument
 Set body = doc.GetFirstItem("Body")
 REM Create navigator
 Set rtnavBody = body.CreateNavigator
 REM Get first paragraph user wants and set range
 stringPara = Inputbox("Number of first paragraph","First paragraph")
 If stringPara = "" Then Exit Sub
 If Not Isnumeric(stringPara) Then Exit Sub
 firstPara = Cint(stringPara)
 If Not rtnavBody.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH, firstPara) Then
   Messagebox "Body item does not have this paragraph",, _
   "Paragraph " & firstPara
   Exit Sub
 End If
 Set rtrangePara = body.CreateRange
 '*** Set the beginning of the subrange at the beginning of this paragraph***
 Call rtrangePara.SetBegin(rtnavBody)
 REM Get last paragraph user wants and set range
 stringPara = Inputbox("Number of last paragraph","Last paragraph")
 If stringPara = "" Then Exit Sub
 If Not Isnumeric(stringPara) Then Exit Sub
 lastPara = Cint(stringPara)
 If lastPara < firstPara Then Exit Sub
 If Not rtnavBody.FindNthElement(RTELEM_TYPE_TEXTPARAGRAPH, lastPara) Then
   Messagebox "Body item does not have this paragraph",, _
   "Paragraph " & lastPara
   Exit Sub
 End If
 '***Move the navigator position to the end of the paragraph***
 Call rtnavBody.SetPositionAtEnd(rtnavBody)
 '***Set the end of the subrange at the end of this paragraph***
 Call rtrangePara.SetEnd(rtnavBody)
 REM Navigate through range and get paragraphs
 Set rtnavPara = rtrangePara.Navigator
 Set rtrangePara2 = body.CreateRange
 Call rtnavPara.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH)
 counter = firstPara
 Do
   Call rtrangePara2.SetBegin(rtnavPara)
   Messagebox rtrangePara2.TextParagraph,, "Paragraph " & counter
   counter = counter + 1
 Loop While rtnavPara.FindNextElement(RTELEM_TYPE_TEXTPARAGRAPH)
End Sub

See Also