O'Reilly logo

VB & VBA in a Nutshell: The Language by Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dictionary Object (VB6)

Reference

Microsoft Scripting Runtime (../ SYSTEM32/SCRRUN.DLL)

Description

The Dictionary object is another new feature of VB6 that has found its way into wider use from its humble beginnings in Version 2 of the VBScript scripting runtime. The Dictionary object is similar to a Collection object, except that it's loosely based on the Perl associative array. Like an array or a Collection object, the Dictionary object holds elements, which are called items or members, containing data. A Dictionary object can contain any data whatsoever, including objects and other Dictionary objects. You access the value of these dictionary items by using unique keys (or named values) that are stored along with the data, rather than by using an item's ordinal position, as you do with an array. This makes the Dictionary object ideal when you need to access data that is associated with a particular unique named value.

So if you're happily using Collection objects throughout your VB programs, why should you want to change? Here are some of the advantages afforded by the Dictionary object over a Collection object:

  • A Dictionary object returns an array of all its keys using one simple method.

  • A Dictionary object returns an array of all its members using one simple method.

  • A Dictionary object lets you determine if a given key exists in the Dictionary.

  • A Dictionary object gives you the ability to overwrite a member value.

  • A Dictionary object lets you change a key value.

If that's not ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required