Examples: NotesRichTextRange class

  1. This agent uses the default range to set the size of all elements in an item.
    Dim session As NotesSession
    Dim db As NotesDatabase
    Dim dc As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim body As NotesRichTextItem
    Dim rtrange As NotesRichTextRange
    Dim rtstyle As NotesRichTextStyle
    
    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 rtrange = body.CreateRange
      Set rtstyle = session.CreateRichTextStyle
      fontSizeString$ = Inputbox$("Size 8 - 24", "Font size")
      If Not Isnumeric(fontSizeString$) Then
        Messagebox "Size must be an integer 8 - 24",, _
        "Not numeric"
        Exit Sub
      End If
      fontSize% = Cint(fontSizeString$)
      If fontSize% < 8 Then fontSize% = 8
      If fontSize% > 24 Then fontSize% = 24
      rtstyle.FontSize = fontSize%
      Call rtrange.SetStyle(rtstyle)
      Call doc.Save(True, True)
    End Sub
  2. This agent displays the range properties for each element in a rich text item, getting the elements in order by type.
    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
      Call DisplayRange(RTELEM_TYPE_TEXTPARAGRAPH, _
      "Text paragraph")
      Call DisplayRange(RTELEM_TYPE_TEXTRUN, _
      "Text run")
      Call DisplayRange(RTELEM_TYPE_DOCLINK, _
      "Doc link")
      Call DisplayRange(RTELEM_TYPE_FILEATTACHMENT, _
      "File attachment")
      Call DisplayRange(RTELEM_TYPE_OLE, _
      "OLE object")
      Call DisplayRange(RTELEM_TYPE_SECTION, _
      "Section")
      Call DisplayRange(RTELEM_TYPE_TABLE, _
      "Table")
      Call DisplayRange(RTELEM_TYPE_TABLECELL, _
      "Table cell")
    End Sub
    
    Sub DisplayRange(elemType As Integer, elemTypeStr)
      If rtnav.FindFirstElement(elemType) Then
        count% = 0
        Do
          count% = count% + 1
          Call rtrange.SetBegin(rtnav)
          If elemType = RTELEM_TYPE_TABLECELL Or _
          elemType = RTELEM_TYPE_TEXTPARAGRAPH Or _
          elemType = RTELEM_TYPE_TEXTRUN Then
            Messagebox _
            "Type: " & rtrange.Type & Chr(13) & _
            "Text run: " & rtrange.TextRun & Chr(13) & _
            "Text paragraph: " & rtrange.TextParagraph _
            ,, elemTypeStr & " " & count%
          Else
            Messagebox _
            "Type: " & rtrange.Type & Chr(13) _
            ,, elemTypeStr & " " & count%
          End If
       Loop While rtnav.FindNextElement(elemType)
      Else
        Messagebox "No element of this type in Body",, _
        "No " & elemTypeStr
      End If
    End Sub