<% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com/ * '* * '* This code is made available as a service to our * '* visitors and is provided strictly for the * '* purpose of illustration. * '* * '* http://www.asp101.com/samples/license.asp * '* * '* Please direct all inquiries to webmaster@asp101.com * '******************************************************* %> <% ' Declare our variables Dim objColorDict ' the dictionary object Dim strColor ' stores color names for looping Dim I ' loop index variable Dim arrKeys, arrItems ' arrays of keys and items ' Create a Dictionary object to hold our color information Set objColorDict = Server.CreateObject("Scripting.Dictionary") ' Add some keys and items objColorDict.Add "black", "#000000" objColorDict.Add "red", "#FF0000" objColorDict.Add "yellow", "#FFFF00" objColorDict.Add "green", "#00FF00" objColorDict.Add "aqua", "#00FFFF" objColorDict.Add "blue", "#0000FF" objColorDict.Add "fuschia", "#FF00FF" objColorDict.Add "white", "#FFFFFF" ' Display all the keys and items Response.Write "

All the keys and corresponding items in our " _ & "dictionary object:

" & vbCrLf Response.Write "
" & vbCrLf
Response.Write "Key" & vbTab & "Item" & vbCrLf
For Each strColor In objColorDict.Keys
	Response.Write strColor & vbTab
	Response.Write ""
	Response.Write objColorDict.Item(strColor)
	Response.Write "" & vbCrLf
Next
Response.Write "
" & vbCrLf ' Display the number of pairs in the dictionary Response.Write "

Number of key/item pairs in our dictionary: " Response.Write objColorDict.Count & "

" & vbCrLf ' Check if a key exists Response.Write "

Does a "blue" key exist: " Response.Write objColorDict.Exists("blue") & "

" & vbCrLf ' Display a single item by accessing it via its key Response.Write "

Value of the item corresponding to the "blue" key: " Response.Write objColorDict.Item("blue") & "

" & vbCrLf ' Change the value of an item Response.Write "

Changing the value of the "blue" key's item. " objColorDict.Item("blue") = "#000099" Response.Write "Its value is now: " Response.Write objColorDict.Item("blue") & "

" & vbCrLf ' Change the value of a key Response.Write "

Changing the value of the "blue" key to " _ & ""dark blue".

" & vbCrLf objColorDict.Key("blue") = "dark blue" ' Display all the keys and items again using different syntax Response.Write "

All the keys and corresponding items in our " _ & "dictionary object:

" & vbCrLf Response.Write "" & vbCrLf Response.Write "" & vbCrLf arrKeys = objColorDict.Keys arrItems = objColorDict.Items For I = LBound(arrKeys) To UBound(arrKeys) Response.Write "" Response.Write "" Response.Write "" Response.Write "" & vbCrLf Next Response.Write "
KeyItem
" & arrKeys(I) & "" & arrItems(I) & "
" & vbCrLf ' Remove all key/item pairs and get rid of the object objColorDict.RemoveAll Set objColorDict = Nothing %>