LOTUSSCRIPT/COM/OLE CLASSES


Examples: Compact method
This agent compacts the Body item of the current or first selected document after a search and replace.

Dim session As NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim body As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtrange As NotesRichTextRange

Sub Initialize
 Set session = New NotesSession
 Set db = session.CurrentDatabase
 Set dc = db.UnprocessedDocuments
 If dc.Count = 0 Then
   Messagebox "No document selected",, "No doc"
   Exit Sub
 End If
 Set doc = dc.GetFirstDocument
 Set body = doc.GetFirstItem("Body")
 Set rtnav = body.CreateNavigator
 Set rtrange = body.CreateRange
 searchString$ = Inputbox$ _
 ("Enter the search string", "Search string")
 If searchString$ = "" Then Exit Sub
 replaceString$ = Inputbox _
 ("Enter the replacement string", "Replacement string")
 If replaceString$ = "" Then Exit Sub
 n% = 0
 Call rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH)
 Call rtrange.SetBegin(rtnav)
 While rtrange.FindAndReplace _
 (searchString$, replaceString$, RT_FIND_CASEINSENSITIVE)
   n% = n% + 1
 Wend
 Messagebox n% & " replacement(s)",, "Find & replace"
 If n% > 0 Then
   Call body.Compact
   Call doc.Save(True, True)
 End If
End Sub

See Also