I’m trying to return a dictionary from a function. I believe the function is working correctly, but I’m not sure how to utilize the returned dictionary.
Here is the relevant part of my function:
Function GetSomeStuff() ' ' Get a recordset... ' Dim stuff Set stuff = CreateObject('Scripting.Dictionary') rs.MoveFirst Do Until rs.EOF stuff.Add rs.Fields('FieldA').Value, rs.Fields('FieldB').Value rs.MoveNext Loop GetSomeStuff = stuff End Function
How do I call this function and use the returned dictionary?
EDIT: I’ve tried this:
Dim someStuff someStuff = GetSomeStuff
and
Dim someStuff Set someStuff = GetSomeStuff
When I try to access someStuff, I get an error:
Microsoft VBScript runtime error: Object required: 'GetSomeStuff'
EDIT 2: Trying this in the function:
Set GetSomeStuff = stuff
Results in this error:
Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment.
I wasn’t too sure of what was your problem, so I experimented a bit.
It appears that you just missed that to assign a reference to an object, you have to use
set, even for a return value: