Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
One of the major advantages the Dictionary object has over an array or a standard collection is that you can quickly verify the existence of a particular key. For example, suppose you have a list of files installed on a computer and want to search that list to ensure that a particular set of DLLs has been installed. With either a collection or an array, there is no way to verify the existence of any one file without methodically looping through the entire set and checking each item individually.
With a Dictionary, however, you can use the Exists method to verify the existence of any given key. The Exists method takes a single parameter (the name of the key) and then returns a Boolean value: True if the key is in the Dictionary, False if it is not.
For example, the script in Listing 4.48 creates a Dictionary object and adds three elements: Printer 1, Printer 2, and Printer 3. The script then checks for the existence of a key named Printer 4 and echoes back the results of that check.
Listing 4.48 Verifying the Existence of a Dictionary Key
|
|
When this script runs, the message "Printer 4 is not in the Dictionary" is echoed to the screen.
Send us your feedback | « Previous | Next » |