Take the 2-minute tour ×

Is it possible to set a dictionary object as a property of a class in classic ASP? I can't seem to get the syntax right. I have a function that I want to return a dictionary object, and assign the dictionary object that is returned by the function to the class property, but I keep getting a type mismatch error?

If I can't use the dictionary object, can I use an array?

I'm newish to classic ASP but I know C#/.NET pretty well.

share|improve this question
"...assign it to the class property" - what is "it" in this case? The function, the dictionary object returned by the function, something else? –  Martha Nov 10 '09 at 15:37
Make sure you are using the Set keyword properly. –  Tester101 Nov 10 '09 at 15:40
Thank you Tester101, that was my problem. I was doing this "m_objCategories = GetStaffCategories(m_intPhysicianID)" and I needed to do "Set m_objCategories = GetStaffCategories(m_intPhysicianID)" Sorry for the stupid question. –  pinniger Nov 10 '09 at 15:51
There are no stupid questions, only stupid answers. –  Tester101 Nov 10 '09 at 15:57

2 Answers 2

up vote 7 down vote accepted

Here is a simple example

Class TestClass
    private testDictionary

    public property get TestDict
        Set TestDict = testDictionary
    end property
    public property let TestDict(byval value)
        Set testDictionary = value
    end property
    public property set TestDict(byval value)
        Set testDictionary = value
    end property
    public function getValue(index)
        getValue = testDictionary.Item(index)
    end function
end class

'Create a Dictionary and add an entry
Set newDict = CreateObject("Scripting.Dictionary")
newDict.Add 1, "This is a test"

'Assign the dictionary to the custom object
Set mynewClass = new TestClass
mynewClass.TestDict = newDict
Set newDict = Nothing

wscript.echo mynewClass.getValue(1)

Set mynewClass = Nothing

Just remember to use Set when working with objects.

share|improve this answer

You should also use the Set keyword when assigning a property in the class.

Class DictionaryClass
    Private m_Dictionary

    Public Sub Class_Initialize()
        Set m_Dictionary = Server.CreateObject("Scripting.Dictionary")
    End Sub

    Public Property Get Dictionary()
        Set Dictionary = m_Dictionary
    End Property

    Public Property Set Dictionary(value)
        Set m_Dictionary = value
    End Property
End Class

Function GetDictionary()
    Dim dictionary : Set dictionary = Server.CreateObject("Scripting.Dictionary")
    'some magic'
    Set GetDictionary = dictionary
End Function

Dim oDictionaryClass : Set oDictionaryClass = New DictionaryClass
Set oDictionaryClass.Dictionary = GetDictionary()
share|improve this answer

Your Answer


