I'm reading the source code of VBA-JSON, which is located at:
https://github.com/VBA-tools/VBA-JSON/blob/master/JsonConverter.bas
In the function that dumps JSON objects (starting with "{" char) into memory:
Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As Dictionary
Dim json_Key As String
Dim json_NextChar As String
Set json_ParseObject = New Dictionary
json_SkipSpaces json_String, json_Index
If VBA.Mid$(json_String, json_Index, 1) <> "{" Then
Err.Raise 10001, "JSONConverter", json_ParseErrorMessage(json_String, json_Index, "Expecting '{'")
Else
json_Index = json_Index + 1
Do
json_SkipSpaces json_String, json_Index
If VBA.Mid$(json_String, json_Index, 1) = "}" Then
json_Index = json_Index + 1
Exit Function
ElseIf VBA.Mid$(json_String, json_Index, 1) = "," Then
json_Index = json_Index + 1
json_SkipSpaces json_String, json_Index
End If
json_Key = json_ParseKey(json_String, json_Index)
json_NextChar = json_Peek(json_String, json_Index)
If json_NextChar = "[" Or json_NextChar = "{" Then
Set json_ParseObject.Item(json_Key) = json_ParseValue(json_String, json_Index)
Else
json_ParseObject.Item(json_Key) = json_ParseValue(json_String, json_Index)
End If
Loop
End If
End Function
What is the difference between:
Set json_ParseObject.Item(json_Key) = json_ParseValue(json_String, json_Index)
And the following one:
json_ParseObject.Item(json_Key) = json_ParseValue(json_String, json_Index)
I searched in SO and found this post, which does not dispel the confusion:
What does the keyword Set actually do in VBA?
From reading the code, I understand that if the parser reads a "{" or "[", then it needs to use a Dictionary to hold whatever between "{" and "}", and a Collection to hold whatever between "[" and "]", and if the parser reads something other than those two, then it is just a value, could be Boolean or String or Integer, etc.
What I don't get is the difference between Set and Assignment. "Set" will copy the address of the return variable of json_ParseValue, and assignment simply makes another copy of the return variable. Is it because that in the first case, there is further requirement to modify the returned object so it has to be passed by address (like in C++ we use &)?