ASP 101 - Active Server Pages 101 - Web01
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash





ASP Source Code:
<%
' 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 "<p>All the keys and corresponding items in our " _
	& "dictionary object:</p>" & vbCrLf
Response.Write "<pre>" & vbCrLf
Response.Write "<strong>Key" & vbTab & "Item</strong>" & vbCrLf
For Each strColor In objColorDict.Keys
	Response.Write strColor & vbTab
	Response.Write "<span style=""background-color: " & objColorDict.Item(strColor) & """>"
	Response.Write objColorDict.Item(strColor)
	Response.Write "</span>" & vbCrLf
Next
Response.Write "</pre>" & vbCrLf
' Display the number of pairs in the dictionary
Response.Write "<p>Number of key/item pairs in our dictionary: "
Response.Write objColorDict.Count & "</p>" & vbCrLf
' Check if a key exists
Response.Write "<p>Does a "blue" key exist: "
Response.Write objColorDict.Exists("blue") & "</p>" & vbCrLf
' Display a single item by accessing it via its key
Response.Write "<p>Value of the item corresponding to the "blue" key: "
Response.Write objColorDict.Item("blue") & "</p>" & vbCrLf
' Change the value of an item
Response.Write "<p>Changing the value of the "blue" key's item.  "
objColorDict.Item("blue") = "#000099"
Response.Write "Its value is now: "
Response.Write objColorDict.Item("blue") & "</p>" & vbCrLf
' Change the value of a key
Response.Write "<p>Changing the value of the "blue" key to " _
	& ""dark blue".</p>" & vbCrLf
objColorDict.Key("blue") = "dark blue"
' Display all the keys and items again using different syntax
Response.Write "<p>All the keys and corresponding items in our " _
	& "dictionary object:</p>" & vbCrLf
Response.Write "<table border=""1"">" & vbCrLf
Response.Write "<tr><th>Key</th><th>Item</th></tr>" & vbCrLf
arrKeys = objColorDict.Keys
arrItems = objColorDict.Items
For I = LBound(arrKeys) To UBound(arrKeys)
	Response.Write "<tr>"
	Response.Write "<td>" & arrKeys(I) & "</td>"
	Response.Write "<td bgcolor=""" & arrItems(I) & """>" & arrItems(I) & "</td>"
	Response.Write "</tr>" & vbCrLf
Next
Response.Write "</table>" & vbCrLf
' Remove all key/item pairs and get rid of the object
objColorDict.RemoveAll
Set objColorDict = Nothing
%>

Back the the Sample Output

Back to the Sample Index


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers