O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Dictionary.Item Property

Syntax

The syntax for setting an item is:

                  dictionaryobject.Item(key) = item

The syntax for returning an item is:

                  value = dictionaryobject.Item(key)
dictionaryobject

Use: Required

Data Type: Dictionary object

A reference to a Dictionary object.

key

Use: Required

Data Type: String

A unique string key for this Dictionary object.

item

Use: Optional

Data Type: Any

The data associated with key.

Data Type

Any

Description

Sets or returns the data item to be linked to a specified key in a Dictionary object.

Rules at a Glance

  • The Item property is the default member of the Dictionary object.

  • The data type is that of the item being returned.

  • Unlike the Item property of most objects, the Dictionary object’s Item property is read/write. If you try to set item to a nonexistent key, the key is added to the dictionary, and the item is linked to it as a sort of “implicit add.”

Programming Tips and Gotchas

  • The Dictionary object doesn’t allow you to retrieve an item by its ordinal position.

  • If you provide a nonexistent key when trying to retrieve an item, the dictionary exhibits rather strange behavior: it adds key to the Dictionary object along with a blank item. You should therefore use the Exists method prior to setting or returning an item, as the example shows.

  • If the item to be assigned or retrieved from the Dictionary object is itself an object, be sure to use the Set keyword when assigning it to a variable or to the Dictionary object.

  • The comparison of key with member keys is defined by the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required