Pages

Tuesday, July 19, 2011

How to create a multi-dimensional dictionary object (VBScript 4.0)

You can easily create multi-dimensional Dictionary objects if you first create a Dictionary object and then create a second Dictionary object and assign it to a value in the First Dictionary. Consider the following code:

Dim myDict
Set myDict = CreateObject("Scripting.Dictionary")

myDict.Add 1, CreateObject("Scripting.Dictionary")
myDict.Add 2, CreateObject("Scripting.Dictionary")

Here, we've created 2 keys in the first level of the myDict Dictionary object. Then, we paired each key with a new Dictionary object, essentially creating a second dimension. You can use code similar to the following to populate the second dimension of the Dictionary and output the values to the browser:

myDict(1).Add 1, "Element"
myDict(2)(1) = "K"

response.write myDict(1)(1) & "<br>"
response.write myDict.Item(2).Item(2) & "<br>"


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.