例: WriteText method

次のエージェントは、ファイル名に対して選択された文書の Subject アイテムを使用してファイルを作成し、そのファイルに選択された文書の Body アイテムを書き込みます。

Sub Initialize
  Dim session As NotesSession
  Dim db As NotesDatabase
  Dim dc As NotesDocumentCollection
  Dim doc As NotesDocument
  Dim stream As NotesStream
  Dim pathname As String
  pathname = "c:¥StreamFiles¥"
  Set session = New NotesSession
  Set db = session.CurrentDatabase
  Set dc = db.UnprocessedDocuments
  Set doc = dc.GetFirstDocument
  Set stream = session.CreateStream
  pathname = pathname & doc.GetItemValue("Subject")(0) & ".txt"
  If Not stream.Open(pathname, "ASCII") Then
    Messagebox pathname,, "Open failed"
    Exit Sub
  End If
  If stream.Bytes <> 0 Then
    Messagebox pathname,, "File already exists and has content"
    Exit Sub
  End If
  Call stream.WriteText(doc.GetItemValue("Body")(0), EOL_CRLF)
  Call stream.Close
End Sub