Share via


Searching a Dictionary

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Strictly speaking, a Dictionary object is not an array, but it is similar. Both are data structures that can store multiple values. The Dictionary object has certain advantages over an array: you can use object programming constructs such as For Each…Next and With…End With statements to work with it, and you do not have to worry about sizing it, as you do an array.

If you use a Dictionary object instead of an array to store a set of data, you can check whether a particular item exists in the dictionary by calling the Exists method of the Dictionary object and passing it the key for the item you want. However, the Exists method does not provide any information regarding where the item is within the dictionary or how many times it occurs.

An advantage of using the Exists method with a Dictionary object, rather than using the Filter function with an array, is that the Exists method returns a Boolean value, while the Filter function returns another array. If you are not required to know how many times the search item occurs, using the Dictionary object might simplify your code.

See Also

Understanding Arrays | Creating Arrays | Arrays and Variants | Assigning One Array to Another | Returning an Array from a Function | Passing an Array to a Procedure | Sorting Arrays | Using the Filter Function to Search String Arrays | Using a Binary Search Function to Search Numeric Arrays