Saturday 5 September 2015

VBScript » Objects » Dictionary


VBScript » Objects » Dictionary

VBScript » Objects » Dictionary

Version: 2.0
The Dictionary object stores name/value pairs (referred to as the key and item respectively) in an array. The key is a unique identifier for the corresponding item and cannot be used for any other item in the same Dictionary object.

Examples

Code:
<% 
Dim cars 
Set cars = CreateObject("Scripting.Dictionary") 
cars.Add "a", "Alvis" 
cars.Add "b", "Buick" 
cars.Add "c", "Cadillac" 
Response.Write "The value corresponding to the key 'b' is " 
cars.Item("b") 
%> 
Output:
"The value corresponding to the key 'b' is Buick"
Explanation:
This code creates a Dictionary object called "cars", adds some key/item pairs, retrieves the item value for the key 'b' using the Item property and then outputs the resulting string to the browser.

Properties

CompareMode
Syntax: object.CompareMode[ = comparison_mode]
The CompareMode property is used to set and return the key's string comparison mode which determines how keys are matched while looking up or searching. Syntax: object. Count Property Syntax: object.
Count
Syntax: object.Count
The Count property is used to determine the number of key/item pairs in the Dictionary object.
Item
Syntax: object.(key) [ = itemvalue]
The Item property allows us to retreive the value of an item in the collection designated by the specified key argument and also to set that value by using itemvalue.
Key
Syntax: object.Key(keyvalue) = newkeyvalue
The Key property lets us change the key value of an existing key/item pair.

Methods

Add
Syntax: object.Add keyvalue, itemvalue
The Add method is used to add a new key/item pair to a Dictionary object.
Exists
Syntax: object.Exists (keyvalue)
The Exists method is used to determine whether a key already exists in the specified Dictionary. Returns True if it does and False otherwise.
Items
Syntax: [arrayname = ] object. Items
The Items method is used to retreive all of the items in a particular Dictionary object and store them in an array.
Keys
Syntax: object.Keys
The Keys method is used to retreive all of the keys in a particular Dictionary object and store them in an array.
Remove
Syntax: object.Remove(keyvalue)
The Remove method is used to remove a single key/item pair from the specified Dictionary object.
RemoveAll
Syntax: object.RemoveAll
The RemoveAll method is used to remove all the key/item pairs from the specified Dictionary object.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.

Blog Archive