"Dictionary" Class - Collection of Key-Value Pairs

This section provides a tutorial example on how to use the Dictionary class that represents a collection of pairs of keys. Dictionary class is provided in the Scripting Runtime DLL, scrrun.dll.

Dictionary: A class represents a collection of pairs of keys and values provided by the Scripting Runtime DLL, scrrun.dll. The Dictionary class offers the following methods and properties:

Here is a sample ASP page to show how to use "Dictionary" class:

<script language="vbscript" runat="server">
'  dictrionary_test.asp
'  Copyright (c) 1999 by Dr. Herong Yang
'  This program shows how to use the Dictionary class.
'
   response.write("<html><body>")
   response.write("<b>Tests on dictionary class</b>:<br/>")
   ' Creating a dictionary object
   set user = CreateObject("Scripting.Dictionary")
   ' Adding a pair of key and item
   user.add "FirstName", "Bill"
   user.add "LastName", "Smith"
   user.add "Email", "bill@com.com"
   user.add "Country", "Canada"
   ' Iterating through the dictionary
   n = user.Count
   response.write("Before - Number of keys: " & n & "<br/>")
   keys = user.Keys()
   for i=0 to n-1
      k = keys(i)
      v = user.Item(k)
      response.write(k & ": " & v & "<br/>")
   next
   ' Modifying the dictionary
   user.remove("Country")
   user.Item("Email") = "bill@smith.com"
   user.Item("Phone") = "123-456-7890"
   ' Iterating through the dictionary
   response.write("After - Number of keys: " & n & "<br/>")
   keys = user.Keys()
   for i=0 to n-1
      k = keys(i)
      v = user.Item(k)
      response.write(k & ": " & v & "<br/>")
   next
   response.write("</body></html>")
</script>

Output:

Tests on dictionary class:
Before - Number of keys: 4
FirstName: Bill
LastName: Smith
Email: bill@com.com
Country: Canada
After - Number of keys: 4
FirstName: Bill
LastName: Smith
Email: bill@smith.com
Phone: 123-456-7890

Note that:

Table of Contents

 About This Book

 ASP (Active Server Pages) Introduction

 IIS (Internet Information Services) 5.0

 MS Script Debugger

 VBScript Language

 ASP Built-in Run-time Objects

 ASP Session

 Creating and Managing Cookies

 Managing Sessions with and without Cookies

scrrun.dll - Scripting Runtime DLL

 What Is scrrun.dll?

"Dictionary" Class - Collection of Key-Value Pairs

 "FileSystemObject" Class - File System

 "Drive" Class - Disk Drive

 "Folder" Class - File Folder

 "File" Class - File Folder

 "TextStream" Class - Input or Output Stream

 Managing Response Header Lines

 Calculation Speed and Response Time

 ADO (ActiveX Data Object) DLL

 Working with MS Access Database

 Guest Book Application Example

 References

 Full Version in PDF/EPUB