2010-05-19 13 views
7

jaka powinna być parametrem create object następujący kodJak utworzyć obiekt kolekcji w vbscript?

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)) 
+0

Zazwyczaj można importować tak: CreateObject ("library.class"). Chyba przegapiłeś jedną z części. – bdhar

+0

CreateObject ("library.class") - w jakiej bibliotece i klasie powinniśmy podać? - szukamy tych szczegółów .. – Onnesh

Odpowiedz

13

jak o Słowniku

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

dla:

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

można iteracyjne tak:

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

Oto kod, jego potężny:

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