Active Server Pages: Dictionary 

Example: Modify a key

In this example we have change the value "one" to "1".
The resulting page will show the value "uno". 
 
 

translate.asp
<%
SET MyDictionary=CreateObject("Scripting.Dictionary")
MyDictionary.Add "one","uno"
MyDictionary.Add "two","dos"
MyDictionary.Add "three","tres"
MyDictionary.Add "four","cuatro"
MyDictionary.Add "five","cinco"
MyDictionary.Add "six","seis"
MyDictionary.Add "seven","siete"
MyDictionary.Add "eight","ocho"
MyDictionary.Add "nine","nueve"
MyDictionary.Add "ten","diez"

MyDictionary.Key ("one")="1"

EnglishNumber="1"
SpanishNumber=MyDictionary.Item (EnglishNumber)
Response.Write(SpanishNumber)
%>

Example: Modify a item

In this example we have change the value "dos" to "2".
The resulting page will show the value "2". 
 
 

translate.asp
<%
SET MyDictionary=CreateObject("Scripting.Dictionary")
MyDictionary.Add "one","uno"
MyDictionary.Add "two","dos"
MyDictionary.Add "three","tres"
MyDictionary.Add "four","cuatro"
MyDictionary.Add "five","cinco"
MyDictionary.Add "six","seis"
MyDictionary.Add "seven","siete"
MyDictionary.Add "eight","ocho"
MyDictionary.Add "nine","nueve"
MyDictionary.Add "ten","diez"

MyDictionary.Item ("two")="2"

EnglishNumber="two"
SpanishNumber=MyDictionary.Item (EnglishNumber)
Response.Write(SpanishNumber)
%>

Example: Count elements in the dictionary

The value of the response page will be "10"
 
 

translate.asp
<%
SET MyDictionary=CreateObject("Scripting.Dictionary")
MyDictionary.Add "one","uno"
MyDictionary.Add "two","dos"
MyDictionary.Add "three","tres"
MyDictionary.Add "four","cuatro"
MyDictionary.Add "five","cinco"
MyDictionary.Add "six","seis"
MyDictionary.Add "seven","siete"
MyDictionary.Add "eight","ocho"
MyDictionary.Add "nine","nueve"
MyDictionary.Add "ten","diez"
Response.Write(MyDictionary.Count)
%>

Tutorial home page