Examples: ForAll statement

Example 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

Example 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

Example 3

In Freelance Graphics®, an Application object contains a DocumentCollection object. The DocumentCollection object contains a collection of Document objects. Each Document object contains a PageCollection object. Each PageCollection object contains a number of Page objects. Each Page object contains an ObjectCollection object. ObjectCollection is a heterogenous collection that may include TextBox objects.

In addition to For loops, you can use ForAll loops or indexing to access individual members of a collection class. This example uses three nested ForAll loops to iterate through the collections. Within individual TextBlock objects, the script uses indexing to set list entries at levels 2 through 5 in each TextBox object to 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

The Application class Documents property returns an instance of the DocumentCollection class. Each element in the collection is a document, an instance of the Document class.

The Document class Pages property returns an instance of the PageCollection class. Each element in the collection is a page, an instance of the Page class.

The Page Objects property returns an instance of the ObjectCollection class. Some of the elements in this collection may be text blocks, instances of the TextBox class.