MyNameIsKhan
MyNameIsKhan

Reputation: 2612

Creating a dictionary-type structure in Access/Excel VBA?

I want to declare something like so:

dictionaryItem = {("Key1", "Value1"}, {"Key2", "Value2"} ... }

But cannot get the syntax right. If not I'd like to make two arrays with initial values (but could not get this working either no matter how I tried to write it).

Upvotes: 2

Views: 1922

Answers (1)

HansUp
HansUp

Reputation: 97111

Seems to me you're describing a Scripting Dictionary. See if this is satisfactory.

Dim dct As Object
Set dct = CreateObject("Scripting.Dictionary")
dct.Add "Key1", "Value1"
dct.Add "Key2", "Value2"
Debug.Print dct.Count
Debug.Print dct("Key1")
Debug.Print dct("Key2")
Set dct = Nothing

Upvotes: 6

Related Questions