Test Design StudioGo to Previous Topic: Define an Enum ListGo to Next Topic: Customizing Auto-Inserted Comment Template

Defining Keys for VBScript Dictionary Object

A useful object exposed by the Microsoft Scripting Runtime library is the Scripting.Dictionary object. This object is used to store collections of information where the data is retrieved using a named key. Test Design Studio makes it easy to use XML comments to define the expected keys for a Dictionary object that is stored in a variable or expected as a parameter to a function call. While the implementation differs, but uses offer two options for specifying the keys: reference an enum or directly list the keys.

Setting Keys for a Variable

The following describes how to define the keys used by a Dictionary object stored in a variable.

Reference an Enum

Use the 'dictionarykeys' attribute of the 'value' tag to indicate the name of the enum list that represents the available keys. This list can be built-in or user-defined.

[VBScript] - Copy Code
''' <value type="Scripting.Dictionary" dictionarykeys="NameOfEnum/>
Dim x"

Directly List Keys

When using an enum is not appropriate, you can directly list the keys to be used. This is done using the 'dictionarykeys' tag. The 'item' tag used to define the dictionary keys is the same as the 'item' tag used to define items in an enum. See Define an Enum List for details on the use of that tag. The example below illustrates directly listing the keys with variations of how the 'item' tag can be implemented.

[VBScript] - Copy Code
''' <value type="Scripting.Dictionary"/>
''' <dictionarykeys>
''' <item><text>Text1</text><description>Description1</description></item>
''' <item><text>Text2</text><description>Description2</description></item>
''' <item><text>Text3</text></item>
''' <item>Text4</item>
''' </dictionarykeys>
Dim x

Setting Keys for a Function Parameter

The following describes how to define the keys used by a Dictionary object expected as a parameter to a function call.

Reference an Enum

Use the 'dictionarykeys' attribute of the 'param' tag to indicate the name of the enum list that represents the available keys. This list can be built-in or user-defined.

[VBScript] - Copy Code
''' <param name="a" type="Scripting.Dictionary" dictionarykeys="NameOfEnum"/>
Public Function MyFunction(ByVal a)
End Function

Directly List Keys

When using an enum is not appropriate, you can directly list the keys to be used. This is done using the 'dictionarykeys' tag. The 'param' tag utilizing the list of keys uses the 'dictionarykeys' attribute to specify the name of the list to use. The 'dictionarykeys' tag must use the 'name' attribute to correspond to the entry in the 'param' tag. The 'item' tag used to define the dictionary keys is the same as the 'item' tag used to define items in an enum. See Define an Enum List for details on the use of that tag. The example below illustrates directly listing the keys with variations of how the 'item' tag can be implemented.

[VBScript] - Copy Code
''' <param name="a" type="Scripting.Dictionary" dictionarykeys="locallist"/>
''' <dictionarykeys name="locallist">
''' <item><text>Text1</text><description>Description1</description></item>
''' <item><text>Text2</text><description>Description2</description></item>
''' <item><text>Text3</text></item>
''' <item>Text4</item>
''' </dictionarykeys>
Public Function MyFunction(ByVal a)
End Function