Code Snippets


Collections

Dim colEmployees As New Collection 

Public Sub CreateNewEmployees()
Dim oEmployee As class_Employee

   Call RemoveAll

   Set oEmployee = New class_Employee
   oEmployee.Name = "Russell"
   oEmployee.Department = "Research"
   oEmployee.HourlyRate = 12.75
   oEmployee.HoursPerWeek = 35
   Call colEmployees.Add(Item:=oEmployee, key:=oEmployee.Name)

   Set oEmployee = New class_Employee
   oEmployee.Name = "Matthew"
   oEmployee.Department = "Sales"
   oEmployee.HourlyRate = 15
   oEmployee.HoursPerWeek = 45
   Call colEmployees.Add(Item:=oEmployee, key:=oEmployee.Name)

   Call MsgBox("Total Number of Employees is : " & colEmployees.Count)
   Call MsgBox("Employee(2) earns £" & colEmployees(2).WeeklyPay & " a week")
   Call MsgBox("Employee 'Matthew' earns £" & colEmployees.Item("Matthew").WeeklyPay & " a week")
   
   For Each oEmployee In colEmployees
      Call MsgBox("Employee '" & oEmployee.Name & " earns £" & oEmployee.WeeklyPay & " a week")
   Next objEmployee

   Set oEmployee = Nothing
End Sub

Private Sub RemoveAll
   Dim lcount As Long
   For lcount = 1 to colEmployees.Count
      ColEmployees.Remove 1
   Next lcount
End Sub


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrev