Such assignments look like they are assigning an object variable to a value type on the surface, but they are actually assigning that object's default member, implicitly.
Rubberduck (an OSS VBIDE add-in project I manage) has a code inspection that locates implicit default member assignments in early-bound code:
The confusion stems from implicit default member calls, which make the code say something, and actually do something else. The two instructions look different only because one has a Set keyword and the other doesn't, however the real difference is an implicit member call to a hidden property named, that has a VB_UserMemId = 0 attribute which makes that member the class' default member. R = ActiveSheet.Range("A1") 'implicit call to ActiveSheet.Range("A1"). It's exactly the same as when you're assigning a cell value in Excel VBA: Dim r As Range It's impossible to tell without looking at the implementation details and seeing exactly what is being returned, but it's also possible that a Let assignment could be assigning to a default member - and that default member call is implicit, and bloody confusing indeed. Is that because json_ParseValue returns a Variant that can hold anything including an object reference or a simple value, then it needs to use the Set keyword when assigning a reference, and leave it out (or use the Let keyword) when assigning a value. The difference between this: Set json_ParseObject.Item(json_Key) = json_ParseValue(json_String, json_Index)Īnd this: json_ParseObject.Item(json_Key) = json_ParseValue(json_String, json_Index) Set mSomething = value ' value is an object reference Public Property Set Something(ByVal value As Variant) MSomething = value ' value is a primitive Public Property Let Something(ByVal value As Variant) This is why you have these keywords in property mutator definitions though: Private mSomething As Variant The Let keyword can be used to assign values, but the Let keyword is pretty much obsolete/redundant. 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 &)?Īs the linked Q&A says, Set is used in VBA to assign an object reference. "Set" will copy the address of the return variable of json_ParseValue, and assignment simply makes another copy of the return variable. What I don't get is the difference between Set and Assignment.
In the function that dumps JSON objects (starting with "", and a Collection to hold whatever between "", and if the parser reads something other than those two, then it is just a value, could be Boolean or String or Integer, etc. I'm reading the source code of VBA-JSON, which is located at: