LOTUSSCRIPT 言語


例:ForAll ステートメント
例 1

Dim myStats List As Variant
myStats("Name") = "Ian"
myStats("Age") = 29
ForAll x In myStats
  Print ListTag(x); " = "; x  
End ForAll
' Output:
' Name = Ian
' Age =  29

例 2

Dim minima(5) As Integer
minima%(0) = 5
minima%(1) = 10
minima%(2) = 15
' Set all elements of array minima to 0.
ForAll x In minima%
  x = 0
End ForAll

例 3

Freelance では、Application オブジェクトは DocumentCollection オブジェクトを含んでいます。DocumentCollection オブジェクトは、Document オブジェクトのコレクションを含み、各 Document オブジェクトは PageCollection オブジェクトを含んでいます。さらに、各 PageCollection オブジェクトは多数の Page オブジェクトを含み、各 Page オブジェクトは ObjectCollection オブジェクトを含んでいます。ObjectCollection は外部コレクションで、TextBox オブジェクトを含むことがあります。

For ループだけでなく、ForAll ループを使用するか、索引を付けて、コレクションクラスの個々のメンバにアクセスできます。次の例では、ネストした 3 つの ForAll ループを使用して、コレクション内で繰り返します。このスクリプトは、個々の TextBlock オブジェクト内で索引を使用して、各 TextBox オブジェクトのレベル 2 から 5 までのリストエントリを Italic に設定します。

Dim level As Integer
ForAll doc In [Freelance].Documents
    ForAll pg In Doc.Pages
       ForAll obj In Pg.Objects
     ' If the object is a TextBlock, set the font to Garamond,      
     ' and set list entries at levels 2 through 5 to Italic.
        If obj.IsText Then
           obj.Font.FontName = "Garamond"
           For level% = 2 To 5
              obj.TextProperties(level%).Font.Italic = TRUE
           Next level%
        End If
     End ForAll
  End ForAll
End ForAll

Application クラスの Documents プロパティは、DocumentCollection クラスのインスタンスを返します。コレクション内の各要素は文書 (Document クラスのインスタンス) です。

Document クラスの Pages プロパティは、PageCollection クラスのインスタンスを返します。コレクション内の各要素はページ (Page クラスのインスタンス) です。

Page Objects プロパティは、ObjectCollection クラスのインスタンスを返します。このコレクションの要素の一部はテキストブロック (TextBox クラスのインスタンス) です。

関連項目