类方法返回字典错误

时间:2012-11-01 15:01:16

标签: class vba

我的班级“联系”包含以下字段:

Private Name As String
Private CurDate As Date
Private Dict As Dictionary

Private Sub Class_Initialize()
    Set Dict = New Dictionary
End Sub
Private Sub Class_Terminate()
    Set Dict = Nothing
End Sub

(这应该在constuctor Set Dict = New Dictionary吗?)并且跟随字典字段的get属性:

Public Property Get Get_Dict() As Dictionary
    Get_Dict = Dict
End Property

现在我的代码中有:

Dim Contact1 As New Contact
Contact1.Set_Contact x, y, z

Dim TempDic As New Dictionary
Set TempDict = Contact1.Get_Dict

它不编译:“参数不是可选的”。如果我在Get_Dict属性中明显没有参数,那怎么可能呢?

1 个答案:

答案 0 :(得分:0)

应该使用:

Public Property Get Get_Dict() As Dictionary
   Set Get_Dict = Dict
End Property

当我们为对象分配引用时。