ASP collection

Source: Internet
Author: User
Most ASP built-in objects support collections. A set is a place where strings, numbers, objects, and other values are stored. Besides
When a project is stored or retrieved, the set is automatically extended and searched, and the set is very similar to the array. Unlike arrays,
After the set is modified, the position of the project is moved. You can use the name, index, or
To traverse all projects.
Access a project by name and index
You can use the project name to access specific projects in the set. For example, the Contents set has
All the variables saved in the object. It also has all objects created by Server. CreateObject. Hypothesis
The following user information is stored in the Session object:
You can access the project by the name associated with the project stored in the collection. For example, the following expression returns a string
"Sam ":
You can also access the project by using the index or number associated with the project. For example, the following expression search is stored in
The information in the second storage slot of the Session object and "Woo" is returned ":
The ASP set starts from 1. When a project is added or deleted in a collection, the index associated with the project changes.
Therefore, you cannot consider that the index of the project remains unchanged. As described in the following topic
Access is generally used to traverse a set or to access a project in a read-only set.
You can access the project by using the shorthand name. ASP searches for the set associated with the object in a specific order. If
If a project with a specific name appears only once in an object set, the name of the set can be eliminated:
When accessing a project stored in an Application or Session object, it is generally safe to remove the set name.
However, for a Request object, it is best to specify the set name, because the set may contain duplicate names.
Traverse a set
You can traverse all the items in the set to learn about the items stored in the set or modify the items. Required when traversing a set
Provide the set name. For example, you can use the For... Each statement in VBScript to access
Project in the object:
You can use the For... Next statement in VBScript to traverse the set. For example, to list
The following statements can be used for three items in a Session.
Because the number of projects stored in the set is generally unknown, ASP supports the Count attribute of the set. This attribute is returned
Number of items in the returned collection. You can use the Count attribute to specify the end value of a counter.
You can use the for statement in the script to loop in the set. Use Count in the for statement of JScript
To achieve better results, you should allocate the Count value to the local variable and use this variable to set the Count.
Terminal value. In this way, the script engine does not need to query the Count value for each loop. The following example shows
Tips:

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.