无限量的收藏VBA

时间:2014-11-03 09:40:02

标签: vba collections

这是我的问题的屏幕,它是无限量的集合。 我想将集合添加到对象属性一次。不是这样的:

http://postimg.org/image/o6da95j0f/ (屏幕显示"观看" VBA中的集合

的问题
    Public Sub testCollections()

Dim index As Long
index = 1
    Dim OJsonElement As JsonElement
    Dim newColl As New Collection
    Dim str As String
    Call addColl(OJsonElement, newColl)


    For Each OJsonElement In newColl
    Debug.Print "THE NAME IS:" & OJsonElement.name
    Next OJsonElement

End Sub


Function addColl(obj1 As JsonElement, nextCollection As Collection)
Dim i As Long
Set nextCollection = New Collection
Set obj1 = New JsonElement
Set obj1.valueCollection = nextCollection
obj1.name = "CityName"
obj1.value = "type"
nextCollection.Add obj1


'obj1.ValueType = nextCollection


'nextCollection.Add nextCollection



End Function

Class:
Public name As String
Public nameCollection As Collection
Public value As Variant
Public ValueType As String
Public valueCollection As Collection

1 个答案:

答案 0 :(得分:0)

我不太了解您的代码,但我会限制您解释为什么它会发生在您的观察者身上。这一行:

Set obj1.valueCollection = nextCollection

将新集合添加到obj1属性valueCollection中。然后,两行之后,你说:

nextCollection.Add obj1

这意味着您将obj1添加到其自己的属性中,因此创建了无限的嵌套。我想帮助您,但为此,我需要了解您希望通过代码达到的目标。但坚持你的请求我希望将集合添加到对象属性一次,我建议你删除行nextCollection.Add obj1,这(至少从谁没有&#的角度来看) 39;不知道项目的目的)似乎没有做任何有用的事情,而是无限的嵌套。