Page 235 - DCAP408_WEB_PROGRAMMING
P. 235
Unit 9: ASP Objects
You can create Application variables in “Global.asa” like this: Notes
<script language=”vbscript” runat=”server”>
Sub Application_OnStart
application(“vartime”)=””
application(“users”)=1
End Sub
</script>
In the example above we have created two Application variables: “vartime” and “users”.
You can access the value of an Application variable like this:
There are
<%
Response.Write(Application(“users”))
%>
active connections.
Loop Through the Contents Collection
The Contents collection contains all application variables. You can loop through the Contents
collection, to see what’s stored in it:
<%
dim i
For Each i in Application.Contents
Response.Write(i & “<br />”)
Next
%>
If you do not know the number of items in the Contents collection, you can use the Count
property:
<%
dim i
dim j
j=Application.Contents.Count
For i=1 to j
Response.Write(Application.Contents(i) & “<br />”)
Next
%>
Loop Through the StaticObjects Collection
You can loop through the StaticObjects collection, to see the values of all objects stored in the
Application object:
LOVELY PROFESSIONAL UNIVERSITY 229