问题
Is it possible to create a multidimensional, associative array in VBScript?
I'm trying to recreate the following JScript code in VBScript:
names["teachers"] = ["Helen","Judy","Carol"];
names["students"] = ["George","John","Katie"];
For (var i=0; i<names["teachers"].length; i++) {
Response.Write(names["teachers"][i]);
}
My attempted VBScript:
dim names
SET names = CreateObject("Scripting.Dictionary")
names.Add "teachers", Array("Helen","Judy","Carol")
names.Add "students", Array("George","John","Katie")
There doesn't seem to be an error creating the object, but I'm unable to figure out how I can loop through the arrays in VBScript.
回答1:
There's no real trick to iterating through this data structure. You do it just how you would expect to.
For Each key In names
For i = 0 To UBound(names(key))
WScript.Echo "names(" & key & ")(" & i & ") = " & names(key)(i)
Next
Next
来源:https://stackoverflow.com/questions/4588469/creating-a-multidimensional-associative-array-in-vbscript