Shashank Chouhan
Shashank Chouhan

Reputation: 1

Dictionary in VBScript How key is recognized by dictionary object in VBSCript

How key is recognized by dictionary object in VBSCript, I mean to say it consider "ABC" and "BCA" as a same Key...?? means I am trying this it is giving me an error that this key already exists so anyone can please give some details about it.

Upvotes: 0

Views: 4065

Answers (2)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

Not an answer, but I need formatting to point out a pecularity of VBScript's dictionary/dispute AutomatedChaos' claim. A Scripting.Dictionary accepts keys of all simple/scalar data types and even objects. So having two keys 42 and "42" is no problem:

>> set dic = CreateObject("Scripting.Dictionary")
>> dic.Add "42", 1
>> dic.Add 42, 2
>>
>> WScript.Echo Join(dic.Keys)
>>
42 42

Upvotes: 1

Rich
Rich

Reputation: 4170

The dictionary.key is the indicator for a stored item under the Dictionary object.

Microsoft Dictionary.Key Example:

'Dictionary.Item("{key}") returns the item information.
'Dictionary.Key("{oldkey}") = "{newkey}" stores a new key for a Dictionary entry. 
Function DictDemo
   Dim d   ' Create some variables.
   Set d = CreateObject("Scripting.Dictionary")
   d.Add "a", "Athens"   ' Add some keys and items, "a" = key, "Athens" = item
   d.Add "b", "Belgrade"
   d.Add "c", "Cairo"
   d.Key("c") = "d"   ' Set key for "c" to "d".
   DictDemo = d.Item("d")   ' Return associate item.
End Function

How to discover which keys you have populated

Function DictDemo
   Dim a, d, i   ' Create some variables.
   Set d = CreateObject("Scripting.Dictionary")
   d.Add "a", "Athens"   ' Add some keys and items.
   d.Add "b", "Belgrade"
   d.Add "c", "Cairo"

   a = d.Keys   ' Get the keys.

   For i = 0 To d.Count -1 ' Iterate the array.
      s = s & a(i) & "<BR>" ' Return results.
   Next
   DictDemo = s
End Function

Upvotes: 0

Related Questions