VBScript の多次元配列で For Each は配列を返さない

多次元配列に対する For Each は、配列が返ってくると思ったら違った。

test.vbs

dim test(1,1)

test(0,0) = "name1"
test(0,1) = "value1"
test(1,0) = "name2"
test(1,1) = "value2"

For Each hoge In test
  WScript.echo hoge
Next
> cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

name1
name2
value1
value2

連想配列が使えるらしいので、こちらにしよう。

dict.vbs

dim test

set test = CreateObject("Scripting.Dictionary")
test.add "name1", "value1"
test.add "name2", "value2"

For Each hoge in test
  WScript.echo hoge
  WScript.echo test(hoge)
Next
> cscript dict.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

name1
value1
name2
value2