Navigation bar
  Home Print document Start Previous page
 41 of 234 
Next page End  

Gravitybox Schedule Primer
Page 39 
1998-2004 Gravitybox Software LLC
first to the last element, each time referencing the Item method of the collection by
index.
Dim i As Long
  For i = 1 To Schedule1.ScheduleItems.Count
    Schedule1.ScheduleItems(i).Id = i
  Next I
The second way to loop through a collection is by creating an object variable, of an
appropriate type, and using it, to set the property values. The object variable is set to a
member of the collection, used, and released. This is much easier to read, but still
rather awkward.
Dim oAppt As CScheduleEl
Dim i As Long
  For i = 1 To Schedule1.ScheduleItems.Count
    Set oAppt = Schedule1.ScheduleItems(i)
    oAppt.MinLength = 60
    oAppt.MaxLength = 120
    Set oAppt = Nothing
  Next I
The third way is the easiest to read. It lets the collection do the loop. There is no loop
counter, as in the other two examples. An object variable is declared and the collection
loops through all of its own items. The following syntax allows the collection to do the
looping work and takes some of the coding away from the developer.
Dim oAppt As CScheduleEl
  For Each oAppt In Schedule1.ScheduleItems
    oAppt.MinLength = 60
    oAppt.MaxLength = 120
  Next
In this code, is can be seen that there is no explicit call the to the Item method of the
collection. The call is implicit. The following two code fragments are equivalent.
Debug.Print ScheduleItems(1).Name
Debug.Print ScheduleItems.Item(1).Name
The Item method is the default method of all collections in GbSchedule. There is no
need to specify a call to this method explicitly. There is also a speed issue to consider
when looping. The third looping example is the fastest way to create a loop. An object
http://www.purepage.com