例: SetEnd method

次のエージェントは、現在の文書の Body アイテムから、要求された範囲の段落を取得します。ユーザーは最初と最後の段落の数を指定します。コードは SetBegin を使用して範囲内の最初の段落をマークし、SetPositionAtEnd に続けて SetEnd を使用して範囲内の最後の段落をマークして含めます。

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 subrange at beginning of 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