kunmateo
kunmateo

Reputation: 3

Vba Add Collection into object property

How can I add collection into the object.property ? It keeps giving me an error. What am I doing wrong? I wanna get a tree structure, I mean inside one property(for example value) would be a collection which has another objects with collections...

Option Explicit

Public name As String
Public value As Variant
Public ValueType As String
Public valueHelp As Collection

Function addColl()

    Dim i As Long
    For i = 1 To 5
        Dim nextCollection As Collection
        Set nextCollection = New Collection
        Dim obj1 As JsonElement
        Set obj1 = New JsonElement


        obj1.name = "City" & i
        obj1.value = "type"
        obj1.ValueType = nextCollection
        nextCollection.Add obj1
        'obj1.valueHelp = nextCollection
        'nextCollection.Add nextCollection

    Next

End Function

Upvotes: 0

Views: 212

Answers (1)

Matteo NNZ
Matteo NNZ

Reputation: 12655

I guess you just have to replace this line:

obj1.ValueType = nextCollection

with this line:

Set obj1.ValueType = nextCollection

since the object type of the property you are trying to store a value in (type Collection) cannot implicitly call the Set keyword as it does with strings or integers.

Upvotes: 1

Related Questions