Marvels of COM .NET interop
I've been lazily browsing the registry on my computer (it seems I tend to do it a lot) when I noticed a familiar name - System.Collections.Queue. Wait a minute. Isn't it a .NET class? Indeed, what I was looking at was a COM registration for a class System.Collections.Queue, pointing to mscoree.dll and mscorlib.dll as its server. It sounded like someone has kindly registered the mscorlib (parts of it anyway) with COM, and it was sitting there ready to be used. To test my hypothesis, I quickly create a simple VB script:
' CollTest.vbsset coll = CreateObject("System.Collections.Queue")coll.Enqueue "Bob"coll.Enqueue "Joe"WScript.Echo coll.Dequeue()WScript.Echo coll.Dequeue()
When I ran it, lo and behold “Bob“ and “Joe“ were the 2 strings printed. When you stop to think about it, of course it should have worked, but nevertheless it felt as a nice surprise. After all the VB Script stock object set is quite limited and getting a free extension (.NET 1.1 is on every machine I work with) was quite welcome.
Of course I went to explore it further. From the System.Collections namespace we apparently have:
Queue
Stack
ArrayList
SortedList
Hashtable
I'd say it makes a rather nice addition to the existing VB script (and javascript as well) toolset. But wait, there is more...
System.IO namespace is represented by two useful classes:
StringWriter
MemoryStream
Finally, there are System.Text.StringBuilder and System.Random classes.