<!-- Declare instance of the ASPCounter component with application-level scope //--> <OBJECT ID=”ASPCounter” RUNAT=”Server” SCOPE=”Applicatoin” PROGID=”MSWC.Counters”> </OBJECT> ... ... <SCRIPT LANGUAGE=”VBScript” RUNAT=”Server”> Sub Application_onStart() ‘Create an instance of an ADO Connection with application-level scope Set Application(“ADOConnection”) = Server.CreateObject(“ADODB.Connection”) Dim varArray(3) ‘Create a Variant array and fill it varArray(0) = “This is a” varArray(1) = “Variant array” varArray(2) = “stored in the” varArray(3) = “Application object” Application(“Variant_Array”) = varArray ‘Store it in thd Application Application(“Start_Time”) = CStr(Now) ‘Store the date/time as a string Application(“Visit_Count”) = 0 ‘Set counter variable to zero End Sub ... ... </SCRIPT> |
For Each objItem in Application.Contents If IsObject(Application.Contents(objItem)) Then Response.Write “Object reference: ‘” & objItem & “’ ” ElseIf IsArray(Application.Contents(objItem)) Then Response.Write “Array: ‘” & objItem & “’ contents are: ” 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) & “ ” Next Else Response.Write “Variable: ‘” & objItem & “’ = “ _ & Application.Contents(objItem) & “ ” End If Next |
varArray = Application.Contents(objItem) |
For intLoop = 0 UBound(varArray) |
For intLoop = 0 To UBound(varArray) IntNumberOfDimensions = UBound(varArray, 1) For intDimension = 0 To intNumberOfDimensions Response.Write “ Index(“ & intLoop & “) = “ _ & varArray(intLoop, intDimension) Next Response.Write “” Next |
For Each objItem in Application.StaticObjects If IsObject(Application.StaticObjects(objItem)) Then Response.Write “<OBJECT> element: ID=’” & objItem & “’ ” End If Next |
2、对集合的操作
1) 增加值到Contents集合
增加值到Contents集合的方法,与在global.asa网页的脚本代码中使用过的方法相同。允许把一个新的Variant值增加到Application对象中,并已有建议的名字和值(可根据需要进行编辑),单击按钮,重新载入这个网页,把值增加到Application.Contents集合中,并且在列表中显示。
增加新的Contents条目的代码
所有的按钮和其他HTML控件放置在示例网页中的一个窗体上。ACTION设置了当前网页的路径,提交该窗体时,重新装入。METHOD属性为“POST”,所以控件中的值出现在Request.Form集合中。在以前的章节中采用过这两种技术:
<FORM ACTION=”<% = Request.ServerVariables(“SCRIPT_NAME”) %>” METHOD=”POST”> |
<INPUT TYPE=”SUBMIT” NAME=”cmdAdd” VALUE=” ”> |
If Len(Request.Form("cmdAdd")) Then strVarName = Request.Form("txtVarName") strVarValue = Request.Form("txtVarValue") Application.Lock Application("strVarName") = strVarValue Application.Unlock End If |
… <SELECT NAME=”lstRemove” SIZE=”1”> <% For Each objItem in Application.Contents Response.Write “<OPTION>” & objItem & “</OPTION>” Next &> </SELECT> … |
<SELECT NAME=”lstRemove” SIZE=”1”> <OPTION>ADOConnection</OPTION> <OPTION>Variant_Array</OPTION> <OPTION>Start_Time</OPTION> <OPTION>Visit_Count</OPTION> <OPTION>My_New_Value</OPTION> </SELECT> |
If Len(Request.Form("cmdRemoveThis")) Then strToRemove = Request.Form("lstRemove") Response.Write "strToRemove = " & strToRemove 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 |
新闻热点
疑难解答