|
APGen Object Reference |
|
See Also: |
The Collection object provides access to a collection of name-value pairs.
| oCollection | A Collection object. |
| key | A unique string key representing a location in the collection. String keys are case insensitive, thus Script("val") and Script("Val") refer to the same object in the collection. |
| index | A zero-based index to the collection. |
| Count | Integer | Returns the number of objects in the collection. |
| Item | Variant | Sets/returns an item in the collection. |
| Remove() | Removes an item from the collection. |
| RemoveAll() | Empties the collection. |
Collection objects are returned from Script.Values, APGScript.Values, and APGen.Values.
If an item is set or retrieved from the collection using an index argument, and the index does not exist in the collection, an error is raised. Items cannot be added to the collection using an index argument, but item values can be read and replaced using an index argument. Setting and retrieving items from the collection using string key arguments will not raise an error if the item doesn't exist. This behavior is consistent with the ASP collections.
You can use an iterating control structure to loop through the keys of the Values collection. In VBScript, this is the For ... Each loop. The following example loops through the Script.Values collection in VBScript:
<%# @LANGUAGE="VBScript" #%>
<%#
Option Explicit
Output.Filename = "output.txt"
' Store values in the Script collection
Script("Author") = "WebGecko"
Script("Today") = Date
Script("Timestamp") = Now
Script("y2k") = "Year 2000 AD"
' Enumerate the Script collection
Output.Write "--Values stored in Script object" & vbCRLF
Dim key
For Each key In Script.Values
Output.Write key & ": " & Script.Values(key) & vbCRLF
Next
#%>
Equivalent code in JScript uses the Enumerator object to loop through the
Script.Values collection:
<%# @LANGUAGE="JScript" #%>
<%#
Output.Filename = "output.txt";
// Store values in the Script collection
Script("Author") = "WebGecko";
var dtNow = new Date();
Script("Today") = dtNow.getMonth()+1 + "/" +
dtNow.getDate() + "/" + dtNow.getYear();
Script("Timestamp") = dtNow
Script("y2k") = "Year 2000 AD"
// Enumerate the Script collection
Output.Write("--Values stored in Script object\r\n");
var key, e;
e = new Enumerator(Script.Values);
for (;!e.atEnd();e.moveNext())
{
key = e.item();
Output.Write(key + ": " + Script.Values(key) + "\r\n");
}
#%>