提示下标越界

wvtjplh 2009-01-17 01:21:35
Dim   myarray() 
Redim myarray(1,2)
j=1
do while not rs.eof
myarray(j,0)=Csng(rs("total"))
myarray(j,1)=rs("tt")
j=j+1
ReDim Preserve myarray(j,2)
rs.movenext
loop
rs.close
set rs=nothing
call CloseConn()
end if


该如何处理?
谢谢!
...全文
106 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
sy_binbin 2009-01-17
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 luxu001207 的回复:]
引用 3 楼 sy_binbin 的回复:
引用 1 楼 luxu001207 的回复:
...
myarray(1,2)
好像只有
myarray(0,0)
myarray(0,1)





1楼的换头像了啊!差点没认出来

这个头像好啊
[/Quote]

为什么好啊??你老婆吗??
smartcatiboy 2009-01-17
  • 打赏
  • 举报
回复
想楼主这种情况,使用recordset.getRows更方便些


strSql="SELECT total,tt FROM tblTable"
set objRst=objCon.execute(strSql)
myarray=objRst.getRows
objCon.close
smartcatiboy 2009-01-17
  • 打赏
  • 举报
回复
多维数组使用preserve时,只能作用于最后一个维度



'错误的:
redim aTest(A,B)
redim preserve aTest(A+1,B)


'正确的:
redim aTest(A,B)
redim preserve aTest(A,B+1)
zeroonewfy 2009-01-17
  • 打赏
  • 举报
回复
不应该存在下标越界呀.每次都是重新定义过

asp里数组是0开始的

你dim myarray(1,2) 就有
myarray(0,0) myarray(0,1) myarray(0,2)
myarray(1,0) myarray(1,1) myarray(1,2)


6个元素
你没有下标越界呀

你看好错误提示没有.提示的是哪一行.你这里循环没有下标越界问题.你不要看错地方了

Atai-Lu 2009-01-17
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sy_binbin 的回复:]
引用 1 楼 luxu001207 的回复:
...
myarray(1,2)
好像只有
myarray(0,0)
myarray(0,1)





1楼的换头像了啊!差点没认出来
[/Quote]
这个头像好啊
toury 2009-01-17
  • 打赏
  • 举报
回复
搞错了,看这个:

<%
rs.open sql,conn,1,1
if not rs.eof then
Dim myarray()
Redim myarray(rs.recordcount-1,1)

for i=0 to rs.recordcount-1
total=rs("total")&""
if len(total)=0 then total=0
myarray(i,0)=total
myarray(i,1)=rs("tt")&""
rs.movenext
next
rs.close: set rs=nothing
call CloseConn()
else
'...............................
response.end
end if
%>
toury 2009-01-17
  • 打赏
  • 举报
回复
rs.open sql,conn,1,1
if not rs.eof then
Dim myarray()
Redim myarray(rs.recordcount-1,1)

for i=0 to rs.recordcount-1
total=rs("total")&""
if len(total)=0 then total=0
myarray(i,0)=Csng(rs("total"))
myarray(i,1)=rs("tt")&""
rs.movenext
next
rs.close: set rs=nothing
call CloseConn()
else
'...............................
response.end
end if
tank_pp 2009-01-17
  • 打赏
  • 举报
回复
使用 Preserve,只能调整数组最后一维的大小。
可以利用临时数组存储数据,然后再把临时数组数据转回P数组:
Dim myarray()
dim newarray()
Redim myarray(1,2)
j=1
do while not rs.eof
myarray(j,0)=Csng(rs("total"))
myarray(j,1)=rs("tt")
Redim newarray(j,2)
for i=1 to j...'myarray数组数据转至newarray数组中
newarray(i,0)=myarray(i,0)
newarray(i,1)=myarray(i,1)
next
j=j+1
ReDim myarray(j,2)
for i=1 to j-1...'newarray数组数据转至myarray数组中
myarray(i,0)=newarray(i,0)
myarray(i,1)=newarray(i,1)
next
rs.movenext
loop
rs.close
set rs=nothing
call CloseConn()
end if
layers2323 2009-01-17
  • 打赏
  • 举报
回复
不要搞错了,vb和其他语言的数组不同。
a(1)是个包含2个元素的数组。
a(1,2)是包含2*3 个元素。

你应该是rs的长度超过了。
dgdyq 2009-01-17
  • 打赏
  • 举报
回复
把J=1改成J=0试试
sy_binbin 2009-01-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 luxu001207 的回复:]
...
myarray(1,2)
好像只有
myarray(0,0)
myarray(0,1)
[/Quote]




1楼的换头像了啊!差点没认出来
wvtjplh 2009-01-17
  • 打赏
  • 举报
回复
ReDim Preserve myarray(j,2)
不可以吗?
Atai-Lu 2009-01-17
  • 打赏
  • 举报
回复
...
myarray(1,2)
好像只有
myarray(0,0)
myarray(0,1)

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧