Determining the Number of Key-Item Pairs in a Dictionary

Microsoft® Windows® 2000 Scripting Guide

Like most collections, the Dictionary object has a Count property that returns the number of key-item pairs in the collection. The script in Listing 4.46 creates an instance of the Dictionary object, adds three key-item pairs, and then echoes the value of the Count property.

Listing 4.46 Determining the Number of Key-Item Pairs in a Dictionary

  
1
2
3
4
5
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Printer 1", "Printing"
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"
Wscript.Echo objDictionary.Count

When this script runs, the value 3 (the number of key-item pairs in the collection) will be echoed to the screen.