有这样一个程序,是对Application集合中的元素进行活动的添加与删除,程序如下:
<%@ LANGUAGE=VBSCRIPT %>
<HTML>
<HEAD>
<TITLE>The Application Object</TITLE>
<STYLE TYPE="text/css">
BODY {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
INPUT {font-family:Tahoma,Arial,sans-serif; font-size:9pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold}
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-bottom:5px}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<SPAN CLASS="heading">The ASP Application Object</SPAN><HR>
<!--------------------------------------------------------------------------->
<% 'look for a command sent from the FORM section buttons
If Len(Request.Form("cmdAdd")) Then ' 利用是否长度为0来判断
strVarName = Request.Form("txtVarName")
strVarValue = Request.Form("txtVarValue")
Application.Lock
Application(strVarName) = strVarValue ' 此处报错
Application.Unlock
End If
If Len(Request.Form("cmdRemoveThis")) Then
strToRemove = Request.Form("lstRemove")
Application.Lock
Application.Contents.Remove(strToRemove)
Application.Unlock
End If
If Len(Request.Form("cmdRemoveAll")) Then
Application.Lock
Application.Contents.RemoveAll
Application.Unlock
End If
%>
<P><DIV CLASS="subhead">The Application.Contents Collection</DIV>
<%
For Each objItem in Application.Contents
If IsObject(Application.Contents(objItem)) Then
Response.Write "Object reference: '" & objItem & "'<BR>"
ElseIf IsArray(Application.Contents(objItem)) Then
Response.Write "Array: '" & objItem & "' contents are:<BR>"
varArray = Application.Contents(objItem)
'note: the following only works with a one-dimensional array
For intLoop = 0 To UBound(varArray)
Response.Write " Index(" & intLoop & ") = " & varArray(intLoop) & "<BR>"
Next
Else
Response.Write "Variable: '" & objItem & "' = " _
& Application.Contents(objItem) & "<BR>"
End If
Next
%>
<P><DIV CLASS="subhead">The Application.StaticObjects Collection</DIV>
<%
For Each objItem in Application.StaticObjects
If IsObject(Application.StaticObjects(objItem)) Then
Response.Write "<OBJECT> element: ID='" & objItem & "'<BR>"
End if
Next
%>
<!-- collect values to execute Application methods with -->
<FORM ACTION="<% = Request.ServerVariables("SCRIPT_NAME") %>" METHOD="POST"> ' 利用Request.ServerVariables("SCRIPT_NAME")将表单提交给自身
<P><DIV CLASS="subhead">Add a value to the Application Object</DIV>
<INPUT TYPE="SUBMIT" NAME="cmdAdd" VALUE=" ">
Application("
<INPUT TYPE="TEXT" NAME="txtVarName" SIZE="15" VALUE="My_New_Value">
") = "
<INPUT TYPE="TEXT" NAME="txtVarValue" SIZE="20" VALUE="Testing, testing ...">
"<P>
<P><DIV CLASS="subhead">Remove a value from the Application Object</DIV>
<INPUT TYPE="SUBMIT" NAME="cmdRemoveThis" VALUE=" ">
Application.Contents.Remove("
<SELECT NAME="lstRemove" SIZE="1">
<%
For Each objItem in Application.Contents
Response.Write "<OPTION>" & ob