当前位置:中国星空学习网首页>网络编程>ASP>正文  
session 变量中的数组如何引用

  If you store an array in a Session object, you should not attempt to alter the elements of the stored array directly. For example, the following script will not work:

〈% Session(“StoredArray“)(3) = “new value“ %〉

This is because the Session object is implemented as a collection. The array element StoredArray(3) does not receive the new value. Instead, the value is indexed into the collection, overwriting any information stored at that location.

It is strongly recommended that if you store an array in the Session object, you retrieve a copy of the array before retrieving or changing any of the elements of the array. When you are done with the array, you should store the array in the Session object again so that any changes you made are saved. This is demonstrated in the following example:

---file1.asp---
〈%
’Creating and initializing the array
Dim MyArray()
Redim MyArray(5)
MyArray(0) = “hello“
MyArray(1) = “some other string“

’Storing the array in the Session object.
Session(“StoredArray“) = MyArray

Response.Redirect(“file2.asp“)
%〉

---file2.asp---
〈%
’Retrieving the array from the Session Object
’and modifying its second element.
LocalArray = Session(“StoredArray“)
LocalArray(1) = “ there“

’Printing out the string “hello there.“
Response.Write(LocalArray(0)&LocalArray(1))

’Re-storing the array in the Session object.
’This overwrites the values in StoredArray with the new values.
Session(“StoredArray“) = LocalArray
%〉

////////////////////////////////////////////////////////////////////////////////////
一个用application存数组的例子
2001-5-15  动网先锋  

If you store an array in an Application object, you should not attempt to alter the elements of the stored array directly. For example, the following script does not work:

〈% Application(“StoredArray“)(3) = “new value“ %〉

This is because the Application object is implemented as a collection. The array element StoredArray(3) does not receive the new value. Instead, the value would be included in the Application object collection, and would overwrite any information that had previously been stored at that location.

It is strongly recommended that if you store an array in the Application object, you retrieve a copy of the array before retrieving or changing any of the elements of the array. When you are done with the array, you should store the array in the Application object again, so that any changes you made are saved. This is demonstrated in the following scripts.

---file1.asp---
〈%
’Creating and initializing the array.
dim MyArray()
Redim MyArray(5)
MyArray(0) = “hello“
MyArray(1) = “some other string“

’Storing the array in the Application object.
Application.Lock
Application(“StoredArray“) = MyArray
Application.Unlock

Server.Transfer(“file2.asp“)
%〉

---file2.asp---
〈%
’Retrieving the array from the Application Object
’and modifying its second element.
LocalArray = Application(“StoredArray“)
LocalArray(1) = “ there“

’Printing out the string “hello there.“
Response.Write(LocalArray(0)&LocalArray(1))

’Re-storing the array in the Application object.
’This overwrites the values in StoredArray with the new values.
Application.Lock
Application(“StoredArray“) = LocalArray
Application.Unlock
%〉

 

上一篇: Asp 在 SQL Verver2000 中新建帐号和给帐号权限的实现
下一篇: 把文件存进 Access 数据库然后取出来提供下载的代码
站内公告
栏目导航
 Windows系统
 Linux/DOS
 办公应用
 工具软件
 图形图象
 网络应用
 安全防御
 网络编程
 软件教程
 实用技术
最新文章
中国星空图片网
·人体艺术
·性感美眉
·生活自拍
·幽默搞笑
·超级帅哥
·精彩万花筒
·梦幻景色
中国星空探索网
·神秘追踪 灵异接触
·鬼故事 灵异空间 图片
·未解之谜 探索宇宙
中国星空两性网
·两性图文 我的性事 情人 成人幽默
·性爱技巧 两性测试 性爱误区
·性事花边 生育避孕 性保健 性疾病
·两性生理 文化 讨论 心理 知识
·爱人同志 非常男女 一夜情
中国星空算网命
·手机吉凶 QQ号码吉凶 周公解梦
·塔罗牌测试 狗年运程
·关公灵签 紫薇斗数 八字排盘
·测试:你的成功指数有多少
·测验你的家庭是否美满?
·面相: 面型 眼睛 耳朵 口唇
·手相:拉你一把奶油桂花手
·测试:你能成为大富翁吗?
联系方式 设为首页
中国星空旗下---中国星空学习网    Copyright 2005-2050 Year   xx.happy369.com  Networks.All rights reserved
中国星空网所有内容均来源于网络,版权属于原作者,如侵犯到您的权益,请与我们联系,我们将尽快予以删除或处理。
中国星空不承担由于内容的合法性及健康性所引起的一切争议和法律责任。
陕ICP备05011765号 联系我们 
《女人如烟》--演唱:魏佳艺