The Encyclopedia of Dictionaries

Frequent commenter snb has written a thorough page on the Scripting.Dictionary object. I resisted Dictionaries for the longest time, but lately I’ve been using them in almost every situation where I would have used a Collection object. Here’s the table of contents:

Contents
– What is a dictionary ?
– What is the purpose of a dictionary ?
– Where does the Dictionary derive from ?
– How to create a Dictionary ?
– How to populate a Dictionary ?
– Add or replace ?
– Keys
– When is a key unique ?
– Create unique keys automatically
– A list of unique elements
– Items
– The number of elements in a Dictionary
– Check the existence of a key / item in the Dictionary
– How to retrieve 1 element from the Dictionary ?
– How to use the array .Keys ?
– How to use the array .Items collection ?
– Change the key of an item
– Copy an item inside the Dictionary
– Remove an item from the Dictionary
– Adapt the contents of an item in the Dictionary
– Remove all items from the Dictionary
– Early binding and late binding
– Examples

If you use Dictionaries, you should bookmark this page. If not, you should start.

10 thoughts on “The Encyclopedia of Dictionaries

  1. Check the *existence* of a key / item in the Dictionary

    And yes, that`s all the value I can add to this.

  2. The Dictionary is just about the greatest thing since sliced bread. Except PivotTables. And Power Pivot.

    And many thanks to Jeff Weir for recommending my article in the first comment :)

  3. Patrick, that is a great article you wrote. How come your penname is matthewspatrick?

    Hey, you might be interested in the next post on this blog, “Dictionaries can be rude”, because it points out a couple of pitfalls of using dictionaries. e.g. the trouble with transferring them back to the worksheet if you have more than 65536 items in them, and the fact that they are much faster if your data is sorted. And it also has a table that looks at how dictionaries stack up against some other alternatives for a very simple data set. Some of these points might make a good addition to your article.

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax