Again you use the name\address combination to quickly find a phone number. The Key in a phone book is the name\address and the Item is the phone number. You don’t read through every item in the Dictionary.Ī second real world example is a phone book(remember those?). When you want to find the definition of a word you go straight to that word. The Keys are the words and the Items are the definition. A real-world dictionary has a list of keys and items. If you are still not clear about a Dictionary then think of it this way. ( Note: Website members have access to the full webinar archive.) ![]() If you are a member of the VBA Vault, then click on the image below to access the webinar and the associated source code. We could use both a Collection and a Dictionary like this ' Add to Dictionary Imagine we are storing the count of different fruit types. Using both types, we can name an item when we add it. For example, we could use them to store a list of customer names, student marks or a list of values from a range of cells.Ī Dictionary is similar to a Collection. In VBA we use Arrays and Collections to store groups of values. Make key non case sensitive (the dictionary must be empty). ![]() Make key case sensitive (the dictionary must be empty). Go through all items (for loop - early and late binding)ĭebug.Print dict.Keys()(i), dict.Items()(i) Go through all items (for loop - early binding only) Get a value from the dictionary using the key Automatically adds if the key does not exist. ![]() Set dict = CreateObject( "Scripting.Dictionary")Ĭhange value at key. (Add using Tools->References from the VB menu) ![]()
0 Comments
Leave a Reply. |