开发者

Creating a Multidimensional, Associative Array in VBScript

开发者 https://www.devze.com 2023-02-02 12:15 出处:网络
Is it possible to create a multidimensional, associative array in开发者_如何学Python VBScript? I\'m trying to recreate the following JScript code 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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号