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

Collections 如何在vbscript中创建集合对象?,collections,vbscript,Collections,Vbscript,以下代码的create object参数应该是什么 dim a set a=CreateObject("Collection") //getting a runtime error saying ActiveX //component can't create object: 'Collection a.add(CreateObject("Collection")) a.Items(0).Add(1) MsgBox(a.Items(0).count) MsgBox(a.Items(0).Ite

以下代码的
create object
参数应该是什么

dim a
set a=CreateObject("Collection") //getting a runtime error saying ActiveX 
//component can't create object: 'Collection
a.add(CreateObject("Collection"))
a.Items(0).Add(1)
MsgBox(a.Items(0).count)
MsgBox(a.Items(0).Item(0))
字典怎么样

Set coll = CreateObject("Scripting.Dictionary")
coll.Add 0, "5"
coll.Add 4, "10"
coll.Add "textkey", "15"
MsgBox coll.Count
MsgBox coll.Item(0)
MsgBox coll.Item(4)
wholeColl = ""
for each key in coll.Keys
  wholeColl = wholeColl & key & " = " & coll.Item(key) & ", "
next
MsgBox wholeColl
用于:

您可以这样迭代:

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

下面是代码,它的强大功能:

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

通常您会这样导入:CreateObject(“library.class”)。我猜您错过了其中的一个部分。CreateObject(“library.class”)——我们应该在其中提供哪个库和类我们正在寻找这些细节。合并到Tester101应答中这促使我安装.NET,但这样做效果很好。
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