Code to Dump Dictionary Values

When you need to create a Dictionary object explicitly (that is, when the object is not created for you by some other Commerce Server 2002 object), use the CreateObject method of the Internet Information Services (IIS) intrinsic Server object, as follows:

Dim oMyDictionary
Set oMyDictionary = Server.CreateObject("Commerce.Dictionary")

After creating the object, you can add elements to it, as follows:

oMyDictionary.first_name = "Steve"

In this example, first_name is a Dictionarykey, and "Steve" becomes the assigned value of this key.

You can extract values from a Dictionary object in several ways. You can place the object.key identifier on the right side of the assignment statement. Such an assignment returns the value of the referenced key:

my_first_name = oMyDictionary.first_name

Or you can use the Value method to get the value of a given key:

my_first_name = oMyDictionary.value("first_name")

You can also use the For Each statement in Microsoft Visual Basic Scripting Edition (VBScript) 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):

' Get the key names.
For Each element in oMyDictionary
    Response.Write element
next

' Get the values.
For Each element in oMyDictionary
    Response.Write oMyDictionary.Value(element)
Next

The following example creates a new Dictionary object, loads values into two keys named first_name and last_name, then writes the element names and element values to the browser:

Set oMyDictionary = Server.CreateObject("Commerce.Dictionary")
oMyDictionary.first_name = "Sam"
oMyDictionary.last_name = "Stone"

' Get the key names.
For Each element in oMyDictionary
    Response.Write "Key = " & element
    Response.Write "    Value = " & oMyDictionary.Value(element)
    Response.Write "<br>"
Next

Copyright © 2005 Microsoft Corporation.
All rights reserved.