(使用的解决方法)Excel VBA:使用第二个类中的字典替换一个类中的字典项会导致Excel崩溃

时间:2017-06-09 08:25:53

标签: excel vba class dictionary

我遇到的问题是将现有字典项替换为从单独的类中提取的另一个字典。

这是主要的代码行。每当我尝试使用此代码时,Excel都会崩溃。

Call fileList.Items(i).updbrList(branchInfo)

fileList是一个字典,用于存储类fileInfo的实例。

从代码的多个步骤开始,我认为这是因为我无法正确传递connList字典,因为branch.connListupdbrList中仍为空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

0 个答案:

没有答案