取得application 对象变量的语法如下所示:
变数=application("变量名称")
接下来我们来实际操作application 变量。下列范例宣告了三个application 对象变量,利用循环显示后并清除:
<html>
<script language="vb" runat="server">
sub page_load(sender as object,e as eventargs)
dim shti as short
application.add("app1","value1")
application.add("app2","value2")
application.add("app3","value3")
for shti=0 to application.count-1
response.write("变量名:" & application.getkey(shti) )
response.write(" ,变数值:" & application.item(shti) & "<p>")
next
application.clear()
end sub
</script>
</html>
上述范例我们利用application 的add 方法产生application 变量并指定初始值,所有的application 变量都放在application 集合中由application 对象管理。所以我们要取出集合中的对象可以使用for...next 循环或是for each 循环,循环中分别使用getkey 方法传回变量名称,item属性传回变量内容,程序最后将全部在集合中的变量用clear 方法清除。