Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Arrays: Resources Online
     [next Lesson]  Subroutine: Working with Dates #1

Dictionary objects by Charles Carroll

Dictionary objects are an elegant object to use in your coding. The dictionary items can be removed individually (without leaving holes) unlike array elements. Read up on http://www.learnasp.com/advice/threadsafe.asp if you want to use it at session or application level. The base documentation is at:
http://www.learnasp.com/iishelp/VBScript/htm/vbs388.htm.

A clever moderately complex practical dictionary example is @
http://www.4guysfromrolla.com/webtech/072899-1.shtml

This is how to create and place items into a dictionary objects and display the contents:

   filename=/learn/test/dictionarybasics.asp

<Test Script Below>


<html><head>
<title>dictionarybasics.asp</title>
</head><body bgcolor="#FFFFFF">
<%
set mysample=server.CreateObject("Scripting.Dictionary")

mysample.Add "haircolor", "brown" 
mysample.add "eyecolor" , "blue" 
mysample.add "dateofbirth", "5/13/64"

for each whatever in mysample 
    response.write whatever & "=" 
    response.write mysample.item(whatever) & "<br>" 
next
set mysample=nothing
%>
</body></html>

This is a sample of how to make an array of dictionary objects.

   filename=/learn/test/dictionaryarrays.asp

<Test Script Below>


<html><head>
<title>dictionaryarrays.asp</title>
</head><body bgcolor="#FFFFFF">
<%
dim people(3) 

Set people(0) = server.CreateObject("Scripting.Dictionary") 
people(0).Add "fname", "Jane" 
people(0).Add "lname", "Doe" 
people(0).Add "haircolor", "brown" 
people(0).add "eyecolor" , "blue" 
people(0).add "dateofbirth", "1/10/60"

Set people(1) = server.CreateObject("Scripting.Dictionary") 
people(1).Add "fname", "Reginald" 
people(1).Add "mname", "Elton" 
people(1).Add "lname", "Dwight" 
people(1).Add "haircolor", "red" 
people(1).add "eyecolor" , "dusty" 
people(1).add "dateofbirth", "1/10/60"

Set people(2) = server.CreateObject("Scripting.Dictionary") 
people(2).Add "fname", "Hitoshi" 
people(2).Add "lname", "Yoshitsugu" 

' print out one item
for each whatever in people(1)
    response.write whatever & "=" 
    response.write people(1).item(whatever) & "<br>" 
next

for counter=0 to 2
    set people(counter)=nothing
next
%>
</body></html>

Send Us a Holiday Gift!. Charles celebrates Christmas, Jewish holidays, Kwanza, Chinese New Year, Japanese Holidays, Secretary Day, High Muslim Holy Days, Pagan & Wicca holidays, and many more! - send a gift any HOLIDAY. 2004 gift gallery & 2005 gift gallery