I've recently worked a lot on ASP arrays. One thing that is rarely used in ASP is the dictionary object which is similar to an array but has some useful methods and properties, making it easier to manage.
The dictionary object can store information in pairs: key and item. Every key refers to an item. When we build a dictionary object we create a relation between a key and an item, so we can recall an item by its key.
An exampleTo create a dictionary object we simply do the following:
Now our object is ready to accept keys and items. In order to add them we use the .add method:
set dicObj = Server.CreateObject("Scripting.Dictionary")
and so on.
We can recall an item, by referring to its key:
which will output:
response.write ("Item of key 'one' is " & dicObj.Item("one"))
Item of key 'one' is firstItem
PropertiesThe dictionary object has 4 properties.
CompareMode is used to compare objects in the dictonary object.
Count returns the number of items in the object.
Item returns the item.
Key sets a new key value for an already existing key.
MethodsLet's now see the methods for the dictionary object.
Add adds a new pair (as seen in the example).
Exists returns a boolean value indicating if a key exists in the object.
Items returns the array of items.
Keys returns the array of keys.
Remove removes a key/item pair from the object.
RemoveAll removes all the pairs from the object.
I hope you've found the post interesting.