例: NotesRichTextRange class

  1. 次のエージェントは、デフォルトの範囲を使用して、アイテム内におけるすべての要素のサイズを設定します。
    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. 次のエージェントは、リッチテキストアイテム内の各要素の範囲プロパティを表示します。これらの要素はタイプ別の順序で取得されています。
    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