0

I am sending data from Excel to the dashing.io dashboard via JSON. The data which I am sending consist of several touples of data like

[{"Group":"Interface","progress";"10"},{"Group":"HMI","progress";"20"}]

Right now I am using several dictionary objects progress1, progress2 to hold the data like:

DIM progress1 as new Dictionary
DIM progress2 as new Dictionary
progress1.add "Group", "Interface"
progress1.add "Progress", 10
progress2.add "Group", "HMI"
progress2.add "Progress", 20

And finally for creating the JSON object, the two progress dictionaries are added to one object:

Dim body as new Dictionary
body.add Array(progress1, progress2)

As there are more than just two progress items, I wanted to create a for-loop to add data to a dictionary and then add that dictionary item to an array like

for i=1 to 10
  progress.add "Group", Range(i,1)
  progress.add "progress", Range (i,2)
next i
overall_progress.add (progress)

It seems that I am adding the object as reference, instead of the values of the object. If the loop runs 10 times, I end up having ten times the same entry.

Any idea how to add the values of a dictionary to an array, instead of the reference?

1 Answer 1

1

Creating objects in a loop is easier to manage if you use a "factory" function.

E.g:

Sub Tester()

    Dim body As New Collection, i As Long

    For i = 1 To 10
        body.Add Progress(Cells(i, 1), Cells(i, 2))
    Next i

End Sub

Function Progress(grp, prog) As Object
    Dim rv As New scripting.dictionary
    rv.Add "Group", grp
    rv.Add "Progress", prog
    Set Progress = rv
End Function
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, great! I had to use "Dim rv as New Dictionary" but apart from that, it now works great. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.