.EmpWeeklyHrs = EmpArray(myCount, 4) colEmployees.Add recEmployee End With Next myCount

MsgBox "Number of Employees: " & colEmployees.Count & Chr(10) & _

"Employee(2) Name: " & colEmployees.Item(2).EmpName MsgBox "Tracy's Weekly Pay: $" & colEmployees.Item("1651").EmpWeeklyPay

For Each recEmployee In colEmployees.Items recEmployee.EmpRate = recEmployee.EmpRate * 1.5 Next recEmployee

MsgBox "Tracy's Weekly Pay (after Bonus): $" & colEmployees.Item("1651"). _ EmpWeeklyPay

End Sub

This program isn't that different from the one used with the standard collection, but there are a few key differences. colEmployees is declared as type clsEmployees, the new class module collection, instead of as Collection. The array and collection are filled the same way, but the way the records in the collection are referenced has changed. When referencing a member of the collection, such as employee record 2, the Item property must be used. Compare the syntax of the message boxes in this program to the previous program.

The For Each Next loop goes through each record in the collection and multiplies the EmpRate by 1.5, changing its value. The result of this "Bonus" is shown in a message box (see Figure 20.10).

Figure 20.10

Create custom procedures and methods in a class module collection.

0 0

Post a comment