我遇到的问题是将现有字典项替换为从单独的类中提取的另一个字典。
这是主要的代码行。每当我尝试使用此代码时,Excel都会崩溃。
Call fileList.Items(i).updbrList(branchInfo)
fileList
是一个字典,用于存储类fileInfo
的实例。
从代码的多个步骤开始,我认为这是因为我无法正确传递connList
字典,因为branch.connList
在updbrList
中仍为空sub,即使在完成Property Get
之后。
方法updbrList
如下所示。它从另一个类branchID
的实例中收集字符串connList
和字典branch
。我正在尝试用branch.brConn
替换当前字典项branch.connList
。
'Class Module: File_Info
Private pbranchList As Scripting.Dictionary`
Private Sub Class_Initialize()
Set pbranchList = New Scripting.Dictionary
End Sub
Public Sub addBranch(branch As Branch_Info)
pbranchList.Add branch.branchID, branch.brConn
End Sub
Public Sub updbrList(branch As Branch_Info)
pbranchList.Item(branch.branchID) = branch.connList
End Sub
connList
的属性如下所示:
'Class Module: Branch_Info
Private pconnList As Scripting.Dictionary
'Declare variantcopy subroutine
Private Declare Sub VariantCopy Lib "OleAut32" (pvarDest As Any, pvargSrc As Any)
Private Function GetByRefVariant(ByRef var As Variant) As Variant
VariantCopy GetByRefVariant, var
End Function
Private Sub Class_Initialize()
Set pconnList = New Scripting.Dictionary
End Sub
Public Property Let connList(pconnListi As Variant)
Set pconnList = pconnListi
End Property
Public Property Get connList() As Variant
connList = GetByRefVariant(pconnList)
End Property
非常感谢任何有关此问题的帮助。 如果需要,请询问其他信息。
亲切的问候,
Eeshwar