VERSION 1.0 CLASS
BEGIN
  MultiUse = 0  'False
END
Attribute VB_PredeclaredId = False
Attribute VB_Creatable = True
Attribute VB_Exposed = True
Attribute VB_GlobalNameSpace = True
Attribute VB_Name = "mpxTasks"
' MPX-Tasks-X5.cls
' ================
' Tasks collection class

' Copyright (c) Mindjet LLC 2002

Option Explicit
'#uses "MPX-Task-X5.Cls" ' Task object Class module

Dim i_TaskCount As Integer ' Tasks count
Dim o_Tasks() As mpxTask ' Tasks array

Private Sub Class_Initialize()
	i_TaskCount = 0
	Erase o_Tasks
End Sub

Private Sub Class_Terminate()
' Destroy tasks collection
Dim i_1 As Integer
	For i_1 = 1 To i_TaskCount
		Set o_Tasks(i_1) = Nothing ' destroy task object
	Next i_1
	Erase o_Tasks
	i_TaskCount = 0
End Sub

Property Get Count() As Integer
' Return number of tasks in the tasks collection
	Count = i_TaskCount
End Property

Property Get Item(ByVal i_index As Integer) As mpxTask
' Return a task object from collection
	If (i_index < 1) Or (i_index > i_TaskCount) Then
		Err.Raise(1000,,"Invalid Tasks collection index",,)
	Else
		Set Item = o_Tasks(i_index)
	End If
End Property

Function Add(ByVal s_Name As String) As Integer
' Add a new task to the task table
' If the ID parameter is present and non-zero then it is stored, else the internal index is used
' Returns the index number of the task added
' Returns 0 if the task is not named and cannot be added

	If Len(s_Name) = 0 Then
		Add = 0 ' cannot add this task
	Else ' Add a new task to the task table
		i_TaskCount = i_TaskCount + 1
		ReDim Preserve o_Tasks(1 To i_TaskCount)
		Set o_Tasks(i_TaskCount) =  New mpxTask ' initialise task
		With o_Tasks(i_TaskCount) ' with new task
			.ID = i_TaskCount ' ID defaults to internal 1-based index number
			.Name = s_Name
		End With
		Add = i_TaskCount ' return index number of newly added task
	End If

End Function
