spacer


Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com


home / experts / javascript / column55


OLE Automation in JavaScript

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Collections

An Automation object features the same structure as any other JScript object. It exposes various methods and properties that we can work with. If you've never worked with Visual Basic, you probably aren't familiar with the Collection object. A collection is a way of grouping a set of related items. Collections are used in Visual Basic to keep track of many things, such as the loaded forms in your program (the Forms collection), or all the controls on a form (the Controls collection).


Visual Basic provides the Collection class so you can create your own collections. Each item in a Collection object is declared as a Variant, Visual Basic's generic 16-byte data type. OLE Automation collections are collections that are exposed through a standard OLE interface. A collection object features four standard elements:


colObj.Add(item[, key][, before]);


The Add() method adds an item to the collection. Along with the data itself, you can specify a key value by which the member can retrieved from the collection. Note that the last argument cannot be specified via JScript.


colObj.Count


The Count property returns the number of items in the collection.


colObj.Item(index);


The Item() method retrieves an item from the collection by its index, which can be either the position in the collection, or the item's key.


colObj.Remove(index);


The Remove() method deletes an item from the collection by its index, which can be either the position in the collection, or the item's key.


Collections are very similar to arrays, but in some cases they are a better choice:


  • It is awkward to remove items from the middle of an array. The Remove() method makes it easy to remove any item from a collection based on either its position in the collection, or the item's key.
  • You never have to redim a Collection object (a way of changing a dynamic array's length in Visual Basic), which results in much cleaner, more maintainable code.
  • Collection objects have extremely fast look-ups by key, which arrays do not. Even if you don't know the exact position of an item, you can retrieve it easily by specifying its key.

Now back to our own story. No, Doc JS isn't going to become Doc VB. Since we're dealing with Automation objects, it's important to be familiar with collections. You'll find yourself handling them in your scripts. In particular, you will notice the importance of the Item() method in statements like:


colWorkOrders.Item("W050580").Priority = 4;


JavaScript's main problem with collections, is that it doesn't have any function that loops through a collection's items. In Visual Basic (or VBScript) this can be done with the For Each...Next construct, but it is not possible with JScript. You will have to overcome this problem in your scripts.


 




http://www.internet.com


Produced by Yehuda Shiran and Tomer Shiran

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior


Created: January 10, 2000
Revised: January 10, 2000

URL: http://www.webreference.com/js/column55/collections.html