例: GetNthElement method

次のエージェントは、現在 (または最初に) 選択されている文書の Body アイテム内にあるすべての文書リンクの参照先データベースのファイルパスとタイトルを表示します。

Dim session As NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim rti As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtlink As NotesRichTextDocLink
Sub Initialize
  Set session = New NotesSession
  Set db = session.CurrentDatabase
  Set dc = db.UnprocessedDocuments
  Set doc = dc.GetFirstDocument
  Set rti = doc.GetFirstItem("Body")
  Set rtnav = rti.CreateNavigator
  If  Not rtnav.FindFirstElement(RTELEM_TYPE_DOCLINK) Then
    Messagebox "Document contains no links",, "No links"
    Exit Sub
  End If
  count% = 0
  Do
    count% = count% + 1
  Loop While rtnav.FindNextElement
  Dim linkDb As NotesDatabase
  For i% = count% To 1 Step -1
    Set rtlink = rtnav.GetNthElement(RTELEM_TYPE_DOCLINK, i%)
    Set linkDb = New NotesDatabase("", "")
    If linkDb.OpenByReplicaID("", rtlink.DbReplicaID) Then
      Messagebox linkDb.FilePath,, """" & linkDb.Title & """"
    Else
      Messagebox "No local replica",, "Cannot find database"
    End If
    Delete linkDb
  Next
End Sub