Creating a Multidimensional, Associative Array in VBScript
Is it possible to create a multidimensional, associative array in开发者_如何学Python 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.
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
精彩评论