2012-11-01 70 views
0

我的类“联系”有以下字段:类方法返回字典错误

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)和字典场下获取属性:

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

此行'Contact1.Set x,y,z'不能正确。这意味着您的联系人类中有一个名为'Set'的公共子项或函数。 'Set'是一个VBA关键字,因此您不能将其用作过程的名称。 – mwolfe02

+3

在get-dict中,您需要使用Set来返回Dict(因为它是一个对象)。你不需要实例化TempDict(所以删除New),因为你是从你的类中分配的。 –

+0

@ mwolfe02你是对的,这只是一个错字。 – grozhd

回答

0

应该使用:

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

当我们分配的对象引用。