LOTUSSCRIPT/COM/OLE CLASSES


Examples: IsDefault property
This agent builds a document from user input. The user can set the style for a Body paragraph to bold or italic. After writing a paragraph, the code clears bold and italic to the default settings if the style is not already in the default state.

Sub Initialize
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Set db = session.CurrentDatabase
 Dim doc As New NotesDocument(db)
 Call doc.AppendItemValue("From", session.UserName)
 Call doc.AppendItemValue _
 ("Subject", Inputbox("Subject?"))
 Call doc.AppendItemValue _
 ("Categories", Inputbox("Category?"))
 Dim rts As NotesRichTextStyle
 Set rts = session.CreateRichTextStyle
 Dim rti As New NotesRichTextItem(doc, "Body")
 newPara = Inputbox("Enter paragraph of text")
 firstPara = True
 While newPara <> ""
   If firstPara Then
     firstPara = False
   Else
     Call rti.AddNewLine(2)
   End If
   Call SetAttributes(rts)
   Call rti.AppendStyle(rts)
   Call rti.AppendText(newPara)
   If Not rts.IsDefault Then Call ClearAttributes(rts)
   newPara = Inputbox("Enter paragraph of text")
 Wend
 Call doc.Save(True, False)
End Sub

Sub SetAttributes(style As NotesRichTextStyle)
 attribs = Lcase(Inputbox( _
 "Attributes (bold - italic - nobold -  noitalic)?"))
 If Instr(attribs, "bold") <> 0 Then
   style.Bold = True
 End If
 If Instr(attribs, "italic") <> 0 Then
   style.Italic = True
 End If
 If Instr(attribs, "nobold") <> 0 Then
   style.Bold = False
 End If
 If Instr(attribs, "noitalic") <> 0 Then
   style.Italic = False
 End If
End Sub

Sub ClearAttributes(style As NotesRichTextStyle)
 style.Bold = STYLE_NO_CHANGE
 style.Italic = STYLE_NO_CHANGE
End Sub

See Also