Creating a Multidimensional, Associative Array in VBScript

瘦欲@ 提交于 2019-12-11 02:58:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!