【发布时间】:2016-07-19 17:05:42
【问题描述】:
我有一个员工(对象)的集合,每个员工都有他/她自己的属性(属性),例如 ID、年龄等。 我已经定义了一个类模块(名为 clsemployee),如下所示:
公共 ID 为整数 公共年龄为整数 . .
并且我在一个模块中将 ID、年龄等属性添加到集合中,如下所示:
Public Sub employee_collection() ' this collection saves all of the employees records
Dim employee As Collection
Set employee = New Collection
Dim n As Integer
Dim i As Integer
Dim E1 As Variant
Dim j As Integer
n = 528
Dim a, b As String
For i = 3 To n
a = "A" + CStr(i) ' to get the values from the excel sheet
b = "B" + CStr(i)
Set E1 = New clsEmployee
E1.ID = Sheets("A").Range(a).Value ' save the valus of each employee in the collection
E1.Age = Sheets("A").Range(b).Value
employee.Add E1
Next i
End Sub
我不知道如何在我的其他模块(子)中调用这个集合。我应该按值调用还是按引用调用?我不想在我拥有的每个子中重复定义该员工。
【问题讨论】:
-
要全局访问变量,您可以在标准模块中将其声明为全局/公共。
标签: vba class object collections call