是的,你应该使用一类类,它被称为集合,所以你有一些类似于......
Class Employee
Property Id (a unique numeric identifier)
Property Name
Property Age
Property Position
Property Department
Property Company
Property Wage
Property HoursWorked
Property PayCheck
Method CalculatePayCheck()
End Class
然后是您的员工集合
Class Employees
Property AllEmployees as generic.list(of Employee)
Property ThisEmployee(Id as Long) as Employee
Property ThisEmployee(Name as string) as Employee
Method AddEmployee(Name, Age, Position, Department, Company, Wage, HoursWorked, PayCheck)
Method RemoveEmployee(Name)
End Class
Id 字段的想法是名称可以重复,例如可以使用两个“Steven Smith”
要访问员工,您可以像以前那样做
With ThisEmployee("Bob")
或者
With ThisEmployee(6)
它将提取第七名员工,因为大多数集合都是从零开始的(从零开始)
更新
参考上面的示例代码......是的,JoeB,因为它是一个通用集合,您可以使用 for/next 循环或 for/each 循环或 do/while 循环
就像是...
For Counter = 0 to Employees.Count -1
'print name using the EMPLOYEES collection object
Print AllEmployees(Counter).Name
'print name using the EMPLOYEE object (single employee using the Id property)
Print ThisEmployee(Counter).Name
Next
在某些情况下,您可能需要在使用对象之前对其进行实例化......就像这样......
Dim TmpEmployee as Employee
For Counter = 0 to Employees.Count -1
'get employee from collection
TmpEmployee = AllEmployees(Counter)
'print name using the EMPLOYEE object
Print TmpEmployee.Name
TmpEmployee = nothing
Next