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

Gravitybox Schedule Primer
Page 38 
1998-2004 Gravitybox Software LLC
code that is difficult to read. An alternative is to get a set an object variable to the newly
added object and set its properties. The following code declares an object variable to
point to the newly added ScheduleItem.
Dim oAppt As CScheduleEl
  
  Set oAppt = Schedule1.ScheduleItems.Add("Appt1", _
              #6/3/2002#, 1, _
         #8:00:00 AM#, 60, "John Doe's Appointment")
  oAppt.Id = newId
  oAppt.ReadOnly = True
  Set oAppt = Nothing
Clearly, the code is much easier to read. This code will also, in theory, run faster. I say
“in theory”, because with this amount of code, no difference will be noticed in speed.
The object variable was not declared with the “New” keyword because a new object
variable of this type may not be created, nor does one ever need to do so. The Add
method of the ScheduleItems collection will create the object, add it to the collection,
and returns a reference. This reference may be used to manipulate the new object’s
properties.
Collection Looping
The same philosophy may be applied to the other collections as well. A Room object
may be added to the Rooms collection in must the same way. A reference to it will be
returned that may be used to manipulate its properties. A Room object has an Id
property that is not defined in the Add method of the Rooms collection. The only way to
set it is after it has been added.
Dim oRoom As CRoomEl
  
  Set oRoom = Schedule1.Rooms.Add("Green Room")
  oRoom.Id = 57
  Set oRoom = Nothing
This Rooms collection will create a Room object and return a reference to the object.
The object reference is stored it in the “oRoom” object variable. Its “Id” property may
then be set.
This syntax may be used for all the collections of GbSchedule. An object variable for
each collection element type can be created and used to jockey the property values.
Alternately, object variables may be used in loops. This is by far the easiest way to set
property values of objects. 
Many times an object’s properties will need to be set using loops. There are three ways
to loop through a collection. The first has been discussed, referencing an object with an
index. An integer, looping variable is declared and a loop is constructed to walk from the
http://www.purepage.com