Article ID: 165293
Article Last Modified on 5/2/2006
<SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER>
SUB Application_OnStart
' This script executes when the first user comes to the site
' or the global.asa is modified.
' A simple fixed size array
Dim aFixed(3)
aFixed(1) = "Fixed"
aFixed(2) = "Size"
aFixed(3) = "Array"
' Cache the array as a member of the Application variables collection.
Application("aFixed") = aFixed
' Declare a dynamic (resizable) array.
Dim aColors()
' Allocate storage for the array.
Redim aColors(16)
' Store values representing a simple color table
' to each of the elements.
aColors(1) = "RED" ' [#FF0000]
aColors(2) = "GREEN" ' [#008000]
aColors(3) = "BLUE" ' [#0000FF]
aColors(4) = "AQUA" ' [#00FFFF]
aColors(5) = "BLACK" ' [#000000]
aColors(6) = "FUCHSIA" ' [#FF00FF]
aColors(7) = "GRAY" ' [#808080]
aColors(8) = "LIME" ' [#00FF00]
aColors(9) = "MAROON" ' [#800000]
aColors(10) = "NAVY" ' [#000080]
aColors(11) = "OLIVE" ' [#808000]
aColors(12) = "PURPLE" ' [#800080]
aColors(13) = "SILVER" ' [#C0C0C0]
aColors(14) = "TEAL" ' [#008080]
aColors(15) = "YELLOW" ' [#FFFF00]
aColors(16) = "WHITE" ' [#FFFFFF]
' Cache the array as a member of the Application variables collection.
Application("aColors") = aColors
END SUB
</SCRIPT>
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<BODY>
<H3>Arrays as Members of the Application variables collection.</H3>
<%
if IsArray(Application("aColors")) then
%>
<H3>A Resizable Array</H3>
<%
' Put a reference to the array in a temporary variable
' for easy access.
aColors = Application("aColors")
nColors = UBound(aColors)
%>
<TABLE BGCOLOR=BLACK>
<%
for i = 1 to nColors
cColor = aColors(i)
if cColor = "BLACK" then
cBGColor = "WHITE"
else
cBGColor = "BLACK"
end if
%>
<TR>
<TD BGCOLOR=<% =cBGColor %>>
<FONT COLOR=<% =cColor %>><% =cColor %></FONT>
</TR>
<% next %>
</TABLE>
<%
else
Response.Write("Application('aColors') is not an array! <BR>")
end if
if IsArray(Application("aFixed")) then
%>
<H3>A Fixed Size Array</H3>
<%
aFixed = Application("aFixed")
for i = 1 to UBound(aFixed)
Response.Write(aFixed(i) & "<BR>")
next
else
Response.Write("Application('aFixed') is not an array! <BR>")
end if
%>
</BODY>
</HTML>
http://<server>/Atest/Color.asp
Keywords: kbaspobj kbcodesnippet kbhowto kbhowtomaster kbscript KB165293