在VBScript中创建多维关联数组 [英] Creating a Multidimensional, Associative Array in VBScript

查看:91
本文介绍了在VBScript中创建多维关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在VBScript中创建多维关联数组?

Is it possible to create a multidimensional, associative array in VBScript?

我正在尝试在VBScript中重新创建以下JScript代码:

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]);

}

我尝试过的VBScript:

My attempted VBScript:

dim names

SET names = CreateObject("Scripting.Dictionary")

names.Add "teachers", Array("Helen","Judy","Carol")
names.Add "students", Array("George","John","Katie")

创建对象似乎没有错误,但是我无法弄清楚如何在VBScript中遍历数组.

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

这篇关于在VBScript中创建多维关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆