APGen Documentation Previous Topic: APGScript.RunArgs() Next Topic: Collection.Count Parent Topic: APGen Object Reference    APGen Object Reference
Collection Object
See Also:

The Collection object provides access to a collection of name-value pairs.

Syntax

oCollection[ (key | index) | .property | .method ]

Object

oCollection A Collection object.

Collection Parameters

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.

Properties

Count Integer Returns the number of objects in the collection.
Item Variant Sets/returns an item in the collection.

Methods

Remove() Removes an item from the collection.
RemoveAll() Empties the collection.

Notes

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");
     }
#%>