Dictionary
Class Dictionary
The Dictionary method provides efficient storage of key-value pairs.
| Method Prototype | Description
|
| Sub Constructor() | initializes a new, empty dictionary
|
| Function Count() As Integer | returns the number of key-value pairs in the Dictionary
|
| Function HasKey( key As Variant ) As Boolean | returns True if the Dictionary contains the given key
|
| Function Keys() As String() | returns an array of all keys in the Dictionary
|
| Function Lookup( key As Variant, defaultValue As Variant ) As Variant | returns a value by its key, or the specified default value if key is not found
|
| Sub Remove( key As Variant ) | removes a key-value pair (does nothing if key is not found)
|
| Function Value( key As Variant ) As Variant | equivalent to Lookup( key, "" )
|
| Sub Value( key As Variant, Assigns newValue As Variant ) | assign a new key-value pair, or change the value for an existing key
|
A Dictionary is an easy and efficient means to store key-value pairs.
Note that unlike in REALbasic, all keys and values are stored internally in string form. In most cases this doesn't matter, since all common types will convert themselves to and from a string automatically. But it does have three implications:
1. You can't store objects in a Dictionary.
2. The Keys() method returns an array of strings, not an array of Variants.
3. If you look at the Type of the Variant you get back out of a dictionary, it will always report 8 (TypeString); there is no way to know what type of data was originally passed in.