JavaScript Instance tutorial OLE Automation (7)

Source: Internet
Author: User
Tags add array object count key ole advantage
Javascript| tutorial using OLE Automation in JavaScript

7. How to deal with set objects

The automation object has the same structure as some of its JScript objects. It exposes a variety of methods and properties that we can handle. If you have never contacted Visual Basic, you may not be familiar with the set object. A set is a group of related items. The set is used primarily in Visual Basic to keep track of many things, such as loading a form from your program (a form set) or all the controls in the form (control set).

Visual Basci provides a set class, so you can create your own set. Each item in a set object is defined as a variant, which is a 16-byte data type in Visual Basic. OLE Automation sets even if some are exposed through a standard OLE interface. A set object contains four standard elements:

(1) Colobj.add (item[, key][, before]);

The Add () method adds an item to the set. In addition to the data in the province, you can also use the resulting members from the set to specify a key value. Note here that the last parameter cannot be specified by JScript.

(2) Colobj.count

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

(3) Colobj.item (index)

The item () method utilizes this to retrieve items from the collection.

(4) colobj.remove (index);

The Remove () method removes an item from the set since it was selected.


Sets are similar to arrays, but for the following reasons the reaction set is a better choice:


It is awkward to delete an item from the middle of an array. The Remove () method makes it easy for the user to delete any item in the set, depending on its location in the set or the key of the item.


You do not have to redefine a set object, and in Visual Basic you often change the length of the dynamic array. So this will make the results more clear and the code has a good maintenance.

(3) The use of keys, set objects have very fast retrieval capabilities, and the array is not. Even if you don't know where the item is in the center, you can easily find it by key.

Since we're dealing with automation objects, it's important to be familiar with the set. In the script you will find that you are dealing with them, and you will notice the importance of the item () method as follows:

Colworkorders.item ("W050580"). Priority = 4;

The main problem with the JavaScript processing set is that it does not have any functions to iterate through each item in the set. In Visual Basic (or VBScript), you can take advantage of for each. Next structure, but it is not possible to take advantage of JScript. The problem is that you should be able to solve the script when you write it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.