Examples: EndSection method

This agent begins and ends sections at the end of a rich text item. The sections contain the contents of files. The section titles are the file names.

%INCLUDE "lserr.lss"
Sub Initialize
  On Error ErrFileNotFound Goto handler
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Set db = session.CurrentDatabase
  Dim dc As NotesDocumentCollection
  Set dc = db.UnprocessedDocuments
  Dim doc As NotesDocument
  Set doc = dc.GetFirstDocument
  Dim rti As NotesRichTextItem
  Set rti = doc.GetFirstItem("Body")
  Dim stream As NotesStream
  Set stream = session.CreateStream
  Dim rtstyle As NotesRichTextStyle
  Set rtstyle = session.CreateRichTextStyle
  rtstyle.Bold = True
  Dim colorObject As NotesColorObject
  Set colorObject = session.CreateColorObject
  colorObject.NotesColor = COLOR_RED
  filename$ = Inputbox$("Full path name of file", "File name")
  While filename$ <> ""
    v = Getfileattr(filename$) ' error if file does not exist
    If Not stream.Open(filename$) Then
      Messagebox "Could not open stream",, "Error"
      Exit Sub
    End If
    Call rti.BeginSection(filename$, rtstyle, colorObject, _
    Call rti.AppendText(stream.ReadText)
    Call rti.EndSection
    Call stream.Close
    filename$ = Inputbox$("Full path name of file", _
    "File name")
  Call doc.Save(True, True)
  Exit Sub
  filename$ = Inputbox$("Bad file name - try again", _
  "File name")
  If filename$ = "" Then
    Call doc.Save(True, True)
    Exit Sub
    Resume 0
  End If
End Sub