Your slogan here

The Dictionary Object - Please Consider

Alright, I'll concede I'm somewhat of an enthusiast of the Cluster. You either love or loathe a Cluster. Individuals who disdain the Cluster will frequently decide on a Gathering. Different dialects do give a truly cool article called a Dictionary or Hash Table. This resembles an Accumulation that acts like a Gathering joined with a Cluster with some additional helpful strategies. VBA does not have this but rather VBScript provides a Dictionary object, which is cool, and we can utilize this article inside our VBA condition. To assemble a dictionary object do the accompanying: 
Diminish my_dictionary as Article 
Set my_dictionary = CreateObject("Scripting.Dictionary") 
Voila! We have a dictionary. What would we be able to do with it? We can include things, check for the presence of things, return a variety of keys, return a variety of things, set how a dictionary looks at keys and get the tally, etc. A precedent: 
'First make the Dictionary Article 
Diminish my_dictionary as Article 
Set my_dictionary = CreateObject("Scripting.Dictionary") 
'While increasing the value of a dictionary you put the key first and the real esteem or item second. The key is compulsory and you can't include things without it. 
my_dictionary.Add "Key 1", "Esteem 1" 
my_dictionary.Add "Key 2", "Esteem 2" 
my_dictionary.Add "Key 3", "Esteem 3" 
my_dictionary.Add "Key 4", "Esteem 4" 
So now we've added four qualities to the dictionary. We should do a few things we can't do neatly or at all with an Accumulation. Let's assume we need to supplant "Esteem 3" with the name "Zebra". Excessively simple! 
my_dictionary.Item("Key 3") = "Zebra" 
You couldn't do that with a gathering! In a gathering you would need to evacuate one thing and include another, in this manner losing the request or your things. A dictionary acts like an Exhibit in this regard. Imagine a scenario where we didn't know there was a key called "Key 3" inside the dictionary and needed to maintain a strategic distance from a blunder. Once more, simple, we simply utilize the Exists strategy for the dictionary object: 
on the off chance that my_dictionary.Exists("Key 3") at that point 
my_dictionary.Item("Key 3") = "Zebra" 
my_dictionary.Add "Key 3", "Zebra" 
end if 
We should need to realize what number of things are in the dictionary, simply utilize the Check strategy which is equivalent to the one of every a gathering. 
MsgBox my_dictionary.Count 
On the off chance that you need to emphasize through the things in a dictionary, you can't utilize a number counter as you would a Cluster or Gathering yet you can utilize two techniques to do as such: 
'You can simply snatch the things from the dictionary like so: 
Diminish things as Variation 
things = my_dictionary.Items 
'Emphasize through the variety of things. These things can incorporate items also. 
Diminish separate_item as Variation 
For Each separate_item in things 
MsgBox separate_item 
Next separate_item 
'Or on the other hand you can separate the keys and emphasize through the things (which is another favorable position over a Gathering that does not give you it's keys or told you what they are) 
Diminish keys as Variation 
keys = my_dictionary.Keys 
'Emphasize through the variety of things. These things can incorporate items also. 
Diminish key as Variation 
For Each key in keys 
MsgBox my_dictionary.Item(key) 
Next key 
Excessively simple! To expel a thing or all things you can utilize Evacuate and RemoveAll individually: 
my_dictionary.Remove("Key 2") 
Or on the other hand 
These are the essentials. I'll take a gander at the CompareMode technique in un minuto. The Dictionary object is a genuine preferred standpoint when we have to manufacture an Accumulation of Accumulations or a Class Gathering. For instance; say we needed to gather information on spys and their present missions. Typically we would need to make a Class Item considered Government operative and hold a Private or Open Accumulation inside the class to which we would include their missions. One class too much (A Gathering is a Class)! How about we utilize a Dictionary... 
Diminish my_dictionary As Article 
Diminish missions As Accumulation 
Diminish spy_name As String 
Diminish keys, key As Variation 
Set my_dictionary = CreateObject("Scripting.Dictionary") 
'Include three loads of government operatives. 
Set missions = New Gathering 
spy_name = "Alexander Poligraphovich" 
missions.Add "Vladivostok" 
missions.Add "Ukraine" 
missions.Add "Beijing" 
my_dictionary.Add spy_name, missions 
spy_name = "Mohammed Ramadan" 
Set missions = New Gathering 
missions.Add "Munich" 
missions.Add "Tehran" 
missions.Add "Sydney" 
my_dictionary.Add spy_name, missions 
spy_name = "Sri FitzPatrick" 
Set missions = New Gathering 
missions.Add "Dublin" 
missions.Add "San Francisco" 
my_dictionary.Add spy_name, missions 
keys = my_dictionary.Keys 
For Each key In Keys 
MsgBox key and vbCrLf and _ 
my_dictionary(key).item(1) and vbCrLf and _ 
my_dictionary(key).item(2) and vbCrLf and _ 
Next key 
The CompareMode technique gives you a chance to set how the dictionary thinks about it's keys when searching for copies and so forth. There are four look at modes vbBinaryCompare, vbTextCompare, vbDatabaseCompare (for MS Access just) and vbUseCompareOption (which utilizes the setting in the Alternative Analyze articulation at the highest point of a module). How might we utilize this? Let's assume we include two qualities with the Keys of monkey and MONKEY' one in all lowercase and the other in all capitalized. 
my_dictionary.Add "monkey", "Giraffe" 
my_dictionary.Add "MONKEY", "Elephant" 
MsgBox my_dictionary.Count 
The MsgBox will demonstrate a thing check of 2, in light of the fact that the two keys are basically unique. The dictionary is playing out a double examination upon the keys so you can include more than one 'monkey' as long as they have some distinction in character case. Imagine a scenario where we needed the word monkey in every last bit of it's structures to be thought about by name and not content. As such we don't need more than one 'monkey' in the dictionary. We use CompareMode vbTextCompare: 
my_dictionary.CompareMode = vbTextCompare 
my_dictionary.Add "monkey", "Giraffe" 
my_dictionary.Add "MONKEY", "Elephant" 
MsgBox my_dictionary.Count 
On this model we don't get to the Msgbox, rather we get a mistake expressing "This Key is as of now connected with a component of this accumulation.". This stops two keys being included that have a similar name. vbBinaryCompare acts a similar path as the primary model does (it is the default) and vbDatabaseCompare....Well I read what it did once and never needed to recall it again! You can discover clarifications for these, though extremely brief, inside the MS Help in Access, or better still Google it.

For more information click my website :
This website was created for free with Would you also like to have your own website?
Sign up for free