![]() ![]() ![]() ![]() Gravitybox Schedule Primer
Page 37
1998-2004 Gravitybox Software LLC
Chapter 3
Adding Code
So far we have created and application with a schedule in it. We have learned to create
an application with multiple schedules in it and move appointment between those
schedules. However we have not as of yet added any code. Now creating these
schedules are nice, but without code, we can really build nothing but trivial applications.
Chapter 1 showed how to set some other the properties but now we need to learn how
to add code and use some of the events.
Reference Creation
We will begin by looking at the ScheduleItems collection, since this collection is the
most frequently used. The collection has an Add method that allows for the addition of a
new element to the collection. Many properties may be set as parameters in the method
call. There are some exceptions and this is the reason for creating an object reference
to each. In collections, all of the properties of an object may not be set from its parent
Add method. To set all properties would be cumbersome for objects with many
properties and would break compatibility, if more properties were added in future
versions.
There is no parameter in the Add method to set the Id property of a ScheduleItem. An
object reference must be made to set the property contents of the newly added object.
The following code will add an appointment, to the ScheduleItems collection, with the
name of Appt1. It will be scheduled on June 3, 2002 in Room 1 at 8:00 AM. It will
display the text John Doe's Appointment on the screen.
Call Schedule1.ScheduleItems.Add("Appt1", #6/3/2002#, 1, _
#8:00:00 AM#, 60, "John Doe's Appointment")
As can be seen, there is no parameter to set the Id property, in the Add method. The
developer must reference the last added element and set it. This may be done with the
following code. The Count method returns the total number of item in its collection.
Since the object was the last one added, it will be the last one in the collection. The Id
property may then be referenced and its value set.
Schedule1.ScheduleItems(Schedule1.ScheduleItems.Count).Id =
newId
This syntax is rather cumbersome and could get very messy, if several properties
needed to be set. Also, it issues at least 4 object lookups to find the element. When
setting many properties, this syntax would create slow code very quickly, not to mention
|