Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find size of dictionary object in VBA

What is the simplest way in VBA to determine the size (i.e., number of keys) in a dictionary object?

like image 782
Gershwyn Avatar asked Apr 15 '10 15:04

Gershwyn


People also ask

What is dictionary object in VBA?

A Dictionary object is the equivalent of a PERL associative array. Items, which can be any form of data, are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array.

How do you check if a key exists in a dictionary VBA?

The . exists() function checks if a key exists. You are searching for an item so you will need to use a loop and check each item in the dictionary.

What is scripting dictionary VBA?

The scripting dictionary is a way to store unique items via a key and item (Keys and Items are terms in the dictionary. It is a fantastic tool to store data based on a unique key. It is powerful in that it the keys can be used to store and consolidate data.

What is the difference between collection and dictionary in VBA?

You can assign a Key to an Item when you add the Item to the Collection, but you cannot retrieve the Key associated with an Item nor can you determine (directly) whether a key exists in a Collection. Dictionaries are much friendly and open with their keys. Dictionaries are also considerably faster than Collections.


2 Answers

As in a Scripting.Dictionary? just use its .Count property.

like image 94
Alex K. Avatar answered Oct 16 '22 14:10

Alex K.


For the number of keys (not items) you should use .Keys property, via UBound(Dictionary.Keys) since its an array

like image 31
Bernardo Dal Corno Avatar answered Oct 16 '22 14:10

Bernardo Dal Corno