Attribute VB_Name = "modPT" Option Explicit ' The clsProjects class will hold all of ' the project classes and in turn will reference ' all of the task and developer classes. Public clsProjects As New Projects ' Subroutine to delete a developer Public Sub DeleteDeveloper() Dim intResult As Integer ' Use the With statement to shorten calls' ' to objects on the form With frmProjects ' Ensure a project is selected If .cboProjects.ListIndex <> -1 Then If .cboTasks.ListIndex <> -1 Then If .lstDevelopers.ListIndex <> -1 Then ' Ask the user if they are sure they want to ' delete the developer intResult = MsgBox("Are you sure?", vbYesNo) ' Check for a yes answer If intResult = vbYes Then ' Call the RemoveDeveloper method of the ' task object for the currently selected ' project clsProjects(.cboProjects.ListIndex + 1). _ ItemTask(.cboTasks.ListIndex + 1).RemoveDeveloper .lstDevelopers.ListIndex + 1 ' Load the developers list LoadDevelopers End If End If End If End If End With End Sub ' Load the developers Public Sub LoadDevelopers() ' Declare our variables Dim intCnt As Integer Dim strFirstName As String Dim strLastName As String Dim strRole As String Dim intTaskHours As Integer Dim intIndexProject As Integer Dim intIndexTask As Integer ' Use the With statement to shorten calls' ' to objects on the form With frmProjects ' Retrieve the project and task indexes intIndexProject = .cboProjects.ListIndex + 1 intIndexTask = .cboTasks.ListIndex + 1 ' Clear the list of developers .lstDevelopers.Clear ' Loop through the number developers for the task For intCnt = 1 To clsProjects(intIndexProject). _ ItemTask(intIndexTask).CountDeveloper ' Retrieve the first name from the first developer strFirstName = clsProjects(intIndexProject). _ ItemTask(intIndexTask). _ ItemDeveloper(intCnt).FirstName ' Retrieve the last name from the first developer strLastName = clsProjects(intIndexProject). _ ItemTask(intIndexTask). _ ItemDeveloper(intCnt).LastName ' Retrieve the task hours for the developer intTaskHours = clsProjects(intIndexProject). _ ItemTask(intIndexTask). _ ItemDeveloper(intCnt).TaskHours strRole = clsProjects(intIndexProject). _ ItemTask(intIndexTask).ItemDeveloper(intCnt).Role .lstDevelopers.AddItem strFirstName & " " & strLastName & _ Chr(9) & intTaskHours & Chr(9) & strRole .lstDevelopers.ItemData(.lstDevelopers.NewIndex) = _ clsProjects(intIndexProject). _ ItemTask(intIndexTask).ItemDeveloper(intCnt).idDeveloper Next End With End Sub ' Load the tasks for the current project Public Sub LoadTasks() ' Declare our variables Dim intCnt As Integer Dim intIndexProject As Integer Dim intIndexTask As Integer ' Use the With statement to shorten calls' ' to objects on the form With frmProjects ' Retrieve our project index intIndexProject = .cboProjects.ListIndex + 1 ' Clear the tasks list box .cboTasks.Clear ' Loop through the tasks for the current project For intCnt = 1 To clsProjects(intIndexProject).CountTask ' Retrieve the task name .cboTasks.AddItem clsProjects.Item(intIndexProject). _ ItemTask(intCnt).TaskName ' Add the id of the task to the item data field .cboTasks.ItemData(.cboTasks.NewIndex) = _ clsProjects.Item(intIndexProject).ItemTask(intCnt).idTask Next End With End Sub ' Load the projects Public Sub LoadProjects() ' Declare the developer and taskrole classes Dim clsDev As New Developer Dim clsTaskRole As New TaskRole Dim colTaskRole As Collection ' Two collections for our developers and task roles Dim colDev As New Collection Dim ColTaskRol As New Collection ' Two variables for looping through the collections Dim CD Dim CTR Dim intCnt As Integer ' Use the With statement to shorten calls' ' to objects on the form With frmProjects ' Clear all of the list boxes .cboProjects.Clear .cboDevelopers.Clear .cboTaskDevelopers.Clear ' Loop through the projects in the projects class For intCnt = 1 To clsProjects.Count ' add the project name to the projects list box .cboProjects.AddItem clsProjects.Item(intCnt).ProjectName Next intCnt ' Retrieve the class of developers using the ' retrieve developers meta method of the developers ' class Set colDev = clsDev.RetrieveDevelopers ' Loop through the developers For Each CD In colDev ' Add the first name and last name to the developers ' list box .cboDevelopers.AddItem CD.FirstName & " " & CD.LastName ' Add the id of the developer to the item data property .cboDevelopers.ItemData(.cboDevelopers.NewIndex) = CD.idDeveloper ' Add the first name and last name to the task developers ' list box .cboTaskDevelopers.AddItem CD.FirstName & " " & CD.LastName ' Add the id of the developer to the item data property .cboTaskDevelopers.ItemData(.cboDevelopers.NewIndex) = CD.idDeveloper Next ' Retrieve the collection of task roles Set colTaskRole = clsTaskRole.RetrieveTaskRoles ' Loop through the task roles For Each CTR In colTaskRole ' Add the task role to the roles list box .cboRoles.AddItem CTR.RoleName ' Set the id of the role to the item data property .cboRoles.ItemData(.cboRoles.NewIndex) = CTR.idTaskRole Next End With End Sub ' Delete the current task Public Sub DeleteTask() ' Declare our variables Dim intResult As Integer Dim intCnt As Integer ' Use the With statement to shorten calls' ' to objects on the form With frmProjects ' Query the user intResult = MsgBox("Are you sure?", vbYesNo) ' Check the result If intResult = vbYes Then ' Loop through the developers and delete each one For intCnt = 1 To clsProjects(.cboProjects.ListIndex + 1). _ ItemTask(.cboTasks.ListIndex + 1).CountDeveloper ' Remove the developer clsProjects(.cboProjects.ListIndex + 1). _ ItemTask(intCnt).RemoveDeveloper intCnt Next intCnt ' Remove the task clsProjects(.cboProjects.ListIndex + 1).RemoveTask .cboTasks.ListIndex + 1 End If ' Clear the task fields .ClearTaskFields ' Reload the tasks LoadTasks End With End Sub ' Delete the project Public Sub DeleteProject() ' Declare our variables Dim intResult As Integer Dim intCnt As Integer Dim intCnt2 As Integer ' Use the With statement to shorten calls' ' to objects on the form With frmProjects ' Ensure the user wants to delete the ' project intResult = MsgBox("Are you sure?", vbYesNo) ' If yes If intResult = vbYes Then ' Loop through the tasks For intCnt = 1 To clsProjects(.cboProjects.ListIndex + 1).CountTask ' Loop through the developers For intCnt2 = 1 To clsProjects(.cboProjects.ListIndex + 1). _ ItemTask(intCnt).CountDeveloper ' Delete the developers clsProjects(.cboProjects.ListIndex + 1). _ ItemTask(intCnt).RemoveDeveloper intCnt2 Next intCnt2 ' Delete the task clsProjects(.cboProjects.ListIndex + 1).RemoveTask intCnt Next intCnt ' Remove the project clsProjects.Remove .cboProjects.ListIndex + 1 End If ' Clear the project and task fields .ClearProjectFields .ClearTaskFields ' Load the projects list box LoadProjects End With End Sub ' Save the project Public Sub SaveProject() ' Declare our variables Dim intIndexProject As Integer ' Use the With statement to shorten calls' ' to objects on the form With frmProjects ' Get the project index intIndexProject = .cboProjects.ListIndex + 1 ' Set the project description, end date and start date clsProjects(intIndexProject).Description = .txtDescription.Text clsProjects(intIndexProject).EndDate = .txtEndDate.Text clsProjects(intIndexProject).StartDate = .txtStartDate.Text ' Check to see if a manager has been selected If .cboDevelopers.ListIndex <> -1 Then ' Set the id of the manager to the id of the developer ' selected. clsProjects(intIndexProject).idManager = _ .cboDevelopers.ItemData(.cboDevelopers.ListIndex) End If ' Set the status of the project clsProjects(intIndexProject).status = .txtStatus.Text ' Set the percent complete clsProjects(intIndexProject).PercentComplete = _ .txtPercentComplete.Text ' Set the project name clsProjects(intIndexProject).ProjectName = _ .txtProjectName.Text ' Save the project clsProjects(intIndexProject).StoreProject End With End Sub ' Save the task Public Sub SaveTask() ' Declare our variables Dim intIndexProject As Integer Dim intIndexTask As Integer ' Use the With statement to shorten calls' ' to objects on the form With frmProjects If .cboTasks.ListIndex <> -1 Then ' Get the project and task indexes intIndexProject = .cboProjects.ListIndex + 1 intIndexTask = .cboTasks.ListIndex + 1 ' Set the task notes clsProjects(intIndexProject). _ ItemTask(intIndexTask).TaskNotes = _ .txtTaskNotes.Text ' Set the end date clsProjects(intIndexProject). _ ItemTask(intIndexTask).EndDate = _ FormatDateTime(.txtTaskEndDate.Text, vbShortDate) ' Set the end date clsProjects(intIndexProject). _ ItemTask(intIndexTask).ProjectedEndDate = _ FormatDateTime(.txtTaskProjectedEndDate.Text, vbShortDate) ' Set the task name clsProjects(intIndexProject). _ ItemTask(intIndexTask).TaskName = _ .txtTaskName.Text ' Set the start date clsProjects(intIndexProject). _ ItemTask(intIndexTask).StartDate = _ FormatDateTime(.txtTaskStartDate.Text, vbShortDate) ' Set the task status clsProjects(intIndexProject). _ ItemTask(intIndexTask).status = .txtTaskStatus.Text ' Set the task hours completed clsProjects(intIndexProject). _ ItemTask(intIndexTask).HoursCompleted = .txtHoursComplete.Text ' set the projected hours to complete clsProjects(intIndexProject). _ ItemTask(intIndexTask).ProjectedHours = _ .txtProjectedHoursComplete.Text ' Store the task clsProjects(intIndexProject). _ ItemTask(intIndexTask).StoreTask End If End With End Sub