如何在vbscript中创建集合对象?

时间:2010-05-19 10:05:42

标签: collections vbscript

以下代码{/ 1}}的参数应该是什么

create object

3 个答案:

答案 0 :(得分:14)

字典怎么样

Set a = CreateObject("Scripting.Dictionary")
a.Add 0, "5"
a.Add 4, "10"
MsgBox a.Count
MsgBox a.Item(0)
MsgBox a.Item(4)

答案 1 :(得分:2)

以下是代码,功能强大:

Option Explicit

dim list
Set list = CreateObject("System.Collections.ArrayList")
list.Add "Banana"
list.Add "Apple"
list.Add "Pear"

list.Sort
list.Reverse

wscript.echo list.Count                 ' --> 3
wscript.echo list.Item(0)               ' --> Pear
wscript.echo list.IndexOf("Apple", 0)   ' --> 2
wscript.echo join(list.ToArray(), ", ") ' --> Pear, Banana, Apple

答案 2 :(得分:0)

有:

dim lista : set lista = CreateObject("Scripting.Dictionary")

你可以像这样迭代:

dim key
for each key in lista.keys
    Wscript.Echo key & " = " & lista.item(key)
next