无限量收集VBA

无限量收集VBA,vba,collections,Vba,Collections,这是我的问题的屏幕,它是无限量的集合。 我希望集合只添加到对象属性一次。不是这样的: (显示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, ne

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

(显示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

我不太理解您的代码,但我将仅解释为什么它会发生在您在watcher中看到的情况下。行:

Set obj1.valueCollection = nextCollection
正在将新集合添加到
obj1
属性
valueCollection
。然后,在两行之后,您说:

nextCollection.Add obj1
这意味着您正在将
obj1
添加到它自己的属性中,因此创建了一个无限嵌套。我很想帮助您,但为此,我需要了解您希望通过代码实现什么。但是,按照您的请求,我希望只将集合添加到object属性一次,我建议您删除行
nextCo添加obj1
,它(至少从不知道项目目的的人的角度来看)除了无限嵌套之外似乎没有任何用处