For example, the following lines of code produce a Dictionary object with two elements:
Dim myDict
Set myDict = CreateObject("Scripting.Dictionary")
myDict.Add "SMD", 1
myDict.Add "smd", 2
The object has two keys because it considers "smd" and "SMD" to be different key values. To avoid this problem, consider using the UCase() or Lcase() functions when storing and referencing alphanumeric key values.
Another option is to set the CompareMode property to Text Compare before adding any items to the Dictionary, like so:
myDict.CompareMode = 1 'TextCompare
If you do this, then adding values to the Dictionary that differ only in case will produce a duplicate key error.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.