Using a Dictionary as an Array
A dictionary is a type of collection known as an associative array. With it, you can manage arrays of named values. Let's look at how we can use this instead of VBScript's dynamic arrays. There are two distinct approaches, depending on whether the data we collect has duplicate values. For general background information about the dictionary (as well as another approach to using it instead of a VBScript array), see "The Scripting Dictionary Makes It Easy" (August 2003, InstantDoc ID 39312).
Listing 3 demonstrates using a dictionary to collect data that might contain duplicate items. Instead of creating an Ips array as we did in Listing 2, we create a dictionary instance, as shown at callout A in Listing 3.
Every time we find a new IP address, we add a new entry as shown at callout B in Listing 3. The Count property represents the number of elements in the dictionary, so on its first pass, the statement at callout B reduces to
Ips(0) = Ip
This is much simpler. If we want to use a VBScript array function such as Join on the information after we're done, we will need to extract the array of values, but we can do this in one line as well, shown at callout C in Listing 3. The Items collection is a native VBScript array. . . .