A Commerce Server Dictionary object is a collection object that supports the creation, storage, and retrieval of name/value pairs in memory. Every element in a Dictionary object is a Variant, which means you can create a Dictionary object that consists of almost any kind of values (including other Dictionary objects), and that you can store any combination of Variant types in the same Dictionary object.
The Commerce Server architecture uses the Dictionary object for a number of specialized purposes, including the Site and PipeContext objects. However, because a Dictionary object is designed to be a general purpose collection, you can use it for almost anything that its internal structure supports.
When you need to create a Dictionary object explicitly (that is, when the object is not created for you by some other Commerce Server object), use the Active Server Pages (ASP) Server object’s CreateObject method, as follows:
set my_dictionary = Server.CreateObject("Commerce.Dictionary")
After creating the object, you can add elements to it, as follows:
my_dictionary.first_name = "Steve"
my_dictionary.last_name = "DeBroux"
In this example, first
_name
and last
_name
are Dictionary keys, and "Steve"
and "DeBroux"
become the assigned values of these keys. Each statement actually accomplishes three functions: declaring the Dictionary key, adding that key to the Dictionary object, and setting the key to a value.
You can extract values from a Dictionary object in several ways. You can simply place the object.key identifier on the right side of the assignment statement. Such an assignment returns the referenced key’s value:
my_first_name = my_dictionary.first_name
Or you can use the Value method to get the value of a given key:
my_last_name = my_dictionary.value("last_name")
You can also use the Microsoft® Visual Basic® Scripting Edition (VBScript) For Each statement to enumerate through either the keys or the values of a Dictionary object as follows (this example assumes that every value in the dictionary contains text):
REM Get the key names
for each element in my_dictionary
response.write element
next
REM Get the values
for each element in my_dictionary
response.write my_dictionary.Value(element)
next
The data in a Dictionary object can be saved in a database table by using the DBStorage object, or it can be saved in a structured storage file by using the FileDocument object.
Commerce Server sites use implementations of the Dictionary object to store sets of data that are required by various other objects and pipeline components.
For information about the implementations of the Dictionary object, see Dictionary Implementations.
The Dictionary object supports the following properties.
Property | Description |
---|---|
Count | Read-only number that identifies the number of elements in the Dictionary object. |
Prefix | String used as a filter when the contents of the Dictionary object are saved. |
The Dictionary object supports the following method.
Property | Description |
---|---|
Value | Returns the value associated with a given Dictionary key. |