Reputation: 177
I created dictionary by this way:
Dim d : Set d = CreateObject("Scripting.Dictionary")
This is ordinary dictionary. It is looks like
key1 value1
key2 value2
After that I added this code:
Dim var
var = "test"
Set d(var) = CreateObject("Scripting.Dictionary")
d(var).Add "x", "ValueX"
WScript.Echo d(var).Item("x")
And got "ValueX"
What is this d(var)? How it relates to the dictionary d?
Upvotes: 0
Views: 976
Reputation: 200283
Your dictionary d
contains a nested dictionary in the key test
to which you add a key x
with the value ValueX
. It probably becomes clearer when you visualize the data structure (you can use my helper function DumpData()
for that):
>>> import "C:\Temp\DataDumper.vbs"
>>> Set d = CreateObject("Scripting.Dictionary")
>>> WScript.Echo DumpData(d)
{}
>>> var = "test"
>>> Set d(var) = CreateObject("Scripting.Dictionary")
>>> WScript.Echo DumpData(d)
{
"test" => {}
}
>>> d(var).Add "x", "ValueX"
>>> WScript.Echo DumpData(d)
{
"test" => {
"x" => "ValueX"
}
}
Upvotes: 2
Reputation: 38745
d
is a dictionary. It contains a key ("test") - value (d("test")
/d.Item("test")
) pair. The value of this pair happens to be a dictionary too. That contains a pair "x" - "ValueX".
Upvotes: 1