11

what should be the parameter for create object the following code

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))
Onnesh
  • 1,169
  • 3
  • 15
  • 31
  • Usually you will import like this: CreateObject("library.class"). I guess you had missed one of the parts. – bdhar May 19 '10 at 10:47
  • CreateObject("library.class") - in this which library & class we should provided? - we are lokking for these details.. – Onnesh May 19 '10 at 11:01

3 Answers3

17

how about a Dictionary

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
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Tester101
  • 8,042
  • 13
  • 55
  • 78
8

Here is the code, its powerful:

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
aNirBan
  • 81
  • 1
  • 1
0

for:

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

you can iterate like this:

dim key
for each key in lista.keys
    Wscript.Echo key & " = " & lista.item(key)
next
Krzysztof Gapski
  • 528
  • 6
  • 10