ASP Dictionary Object

## ASP Tutorial

ASP HOME ASP Introduction ASP Install ASP Syntax ASP Variables ASP Procedures ASP Forms ASP Cookies ASP Session ASP Application ASP #include ASP Global.asa ASP Send e-mail

## ASP Objects

ASP Response ASP Request ASP Application ASP Session ASP Server ASP Error ASP FileSystem ASP TextStream ASP Drive ASP File ASP Folder ASP Dictionary ASP ADO

## ASP Components

ASP AdRotator ASP BrowserCap ASP Content Linking ASP Content Rotator

## ASP and AJAX

AJAX Intro AJAX ASP AJAX Database

## ASP Summary

ASP Quick Ref ASP Summary

## ASP Examples

ASP Examples ASP Quiz ASP Certificate

# ASP Dictionary Object

« Previous
Next Chapter »

The Dictionary object stores information in name/value pairs.

## Try it Yourself - Examples

Does a specified key exist?
How to create a Dictionary object, and then use the Exists method to check if a specified key exists.

Return an array of all items
How to use the Items method to return an array of all the items.

Return an array of all keys
How to use the Keys method to return an array of all the keys.

Return the value of an item
How to use the Item property to return the value of an item.

Set a key
How to use the Key property to set a key in a Dictionary object.

Return the number of key/item pairs
How to use the Count property to return the number of key/item pairs.

## The Dictionary Object

The Dictionary object is used to store information in name/value pairs (referred to as key and item). The Dictionary object might seem similar to Arrays, however, the Dictionary object is a more desirable solution to manipulate related data.

Comparing Dictionaries and Arrays:

- Keys are used to identify the items in a Dictionary object
- You do not have to call ReDim to change the size of the Dictionary object
- When deleting an item from a Dictionary, the remaining items will automatically shift up
- Dictionaries cannot be multidimensional, Arrays can
- Dictionaries have more built-in functions than Arrays
- Dictionaries work better than arrays on accessing random elements frequently
- Dictionaries work better than arrays on locating items by their content

The following example creates a Dictionary object, adds some key/item pairs to it, and retrieves the item value for the key gr:

<%
Dim d
Set d=Server.CreateObject("Scripting.Dictionary")
d.Add "re","Red"
d.Add "gr","Green"
d.Add "bl","Blue"
d.Add "pi","Pink"
Response.Write("The value of key gr is: " & d.Item("gr"))
%>
Output:
The value of key gr is: Green

The Dictionary object's properties and methods are described below:

### Properties

Property | Description
--- | ---
CompareMode | Sets or returns the comparison mode for comparing keys in a Dictionary object
Count | Returns the number of key/item pairs in a Dictionary object
Item | Sets or returns the value of an item in a Dictionary object
Key | Sets a new key value for an existing key value in a Dictionary object

### Methods

Method | Description
--- | ---
Add | Adds a new key/item pair to a Dictionary object
Exists | Returns a Boolean value that indicates whether a specified key exists in the Dictionary object
Items | Returns an array of all the items in a Dictionary object
Keys | Returns an array of all the keys in a Dictionary object
Remove | Removes one specified key/item pair from the Dictionary object
RemoveAll | Removes all the key/item pairs in the Dictionary object

« Previous
Next Chapter »

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE