请问怎么对数组赋值 asp

来源:百度知道 编辑:UC知道 时间:2024/06/09 04:43:29
用vbs的
我用
dim arr()
for i=0 to 3
arr(i)=i
next
response.write arr(2)
可是不行啊
各位大哥哥姐姐帮帮忙~!

asp对数组赋值分静态和动态数组;
参考方法分别如下:
1.静态数组
dim a(5)
a(0)="a"
a(1)="b"
....
a(4)="e"
2.动态数组
<%
on error resume next
dim a()
for i=0 to 200
redim Preserve a(i+1)
a(i) = 1
next
session("ff")=a
for j=0 to ubound(session("ff"))
Response.Write session("ff")(j)&"<br>"
next
if err then
Response.Write err.description
end if
%>
以上是把动态数组 赋值给session("ff")

退出循环
for...next 用exit for
do...loop 用exit do

数组必须提前定义大小

Dim arr(3)

或者是一开始不定义,而在随后的程序里计算出长度后,再动态定义

//一开始不知道具体的长度
Dim arr()

//经过一些运算后,产生了长度
myLength=xxxObj.length()

//然后再重新设定arr长度
Redim arr(myLength)

//然后开始赋值
for i=0 to myLength
arr(i)=i
next

在上面中你用了动态数组,动态数组在起初声明是可以不给出数组的维数.但在使用时,应该利用ReDim语句为其动态的分配内存空间.即:R