The Intervals class is the only creatable class in your custom time interval server. The only job it does is to serve the two time interval objects to the SDK when they are called for. It implements the ITimeIntervals interface.
Open the code window for the Intervals class and add these statements:
'Intervals class Implements PITimeServer.ITimeIntervals
This statement brings all the defined properties and methods of the ITimeIntervals interface into this class.
'Constants Private Const cName As String = "PlantDay-Shift" Private Const cDescription As String = _ "Plant Day and Shift time interval server." Private Const cCount As Long = 2
These constants are used in the code below. We define them at the top of the file so they will be easier to change.
'Member variables Private mIntervals(1 To cCount) As ITimeInterval
This member variable is an array of objects that implement the ITimeInterval interface.
Once you have entered the Implements statement, you should see ITimeIntervals in the left drop-down of the code window, and in the right-hand drop-down, you can select each of its properties.
When you select an item in the right-hand drop-down, VB creates the corresponding routine and places the cursor inside it, so you need only fill in the routine's contents.
Select each property in turn, and insert the following statements.
'TimeIntervals interface implementation Private Property Get ITimeIntervals_Count() As Long ITimeIntervals_Count = cCount End Property Private Property Get ITimeIntervals_Description() As String ITimeIntervals_Description = cDescription End Property Private Property Get ITimeIntervals_Item ( _ ByVal Index1 As Long) As ITimeInterval Set ITimeIntervals_Item = mIntervals(Index1) End Property Private Property Get ITimeIntervals_Name() As String ITimeIntervals_Name = cName End Property
In each of these property routines, we simply return one of the constants, or member variables, defined above. The only remaining step is to initialize the mIntervals array.
On the left-hand drop-down of the code window, select Class. On the right-hand drop-down you will find Initialize and Terminate. Select Initialize, and insert the following statements:
Private Sub Class_Initialize() Set mIntervals(1) = New PlantDay Set mIntervals(2) = New Shift End Sub
No class termination routine is necessary, as the VB runtime cleans up the mIntervals array by itself.