(1) Traversing the code of the Contents collection
To traverse the Contents collection, you can use a For each ... Next structure. Each item in the collection can be a simple variant type variable, a Variant array, or a reference to an object. Because each type of value needs to be handled differently, you have to check each one to determine its type.
You can use the VarType function in VBScript to do this work. Here you use the IsObject and IsArray functions instead:
For each objitem in application.contents
If IsObject (application.contents (objitem)) Then
Response.Write "Object Reference: '" & objitem & "'
”
ElseIf IsArray (application.contents (objitem)) Then
Response.Write "Array:" "& objitem &" ' contents are:
”
Vararray = application.contents (objitem)
' note:the following with a one-dimensional array
For intloop = 0 to UBound (vararray)
Response.Write " Index ("& intloop &") = "& _
Vararray (intloop) & "
”
Next
Else
Response.Write "Variable:" "& objitem &" ' = "_
& Application.Contents (objitem) & "
”
End If
Next
Notice how the program retrieves the array from the Application object. Assign it to a local (Variant) variable, using the following statement:
Vararray = application.contents (objitem)
You can use the UBound function to find the size of the array (the number of elements), which can be used as a termination condition for traversal:
For intloop = 0 UBound (vararray)
This example is a one-dimensional array and will only display the contents of such an array. You can edit your code to handle multidimensional arrays as needed, for example:
For intloop = 0 to UBound (vararray)
Intnumberofdimensions = UBound (Vararray, 1)
For intdimension = 0 to Intnumberofdimensions
Response.Write " Index ("& intloop &") = "_
& Vararray (Intloop, intdimension)
Next
Response.Write "
”
Next
(2) Traversing the code of the StaticObjects collection
The StaticObjects collection contains all the object references that are declared using <OBJECT> elements in Global.asa. Because each entry is an object variable, the array can be traversed by simple code. We will output the name of the object (as defined in the id attribute):
For each objitem in application.staticobjects
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