vbs的数组问题!!!用redim总是报错800a0009 :'( 在线等~~~~急

musicfree_uibe 2003-07-09 10:18:48
一个二维数组
slot为数组实际大小
ReDim Preserve theFiles(slot,slot)时总是报下标越界。。。怎么回事?!
...全文
341 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
showerXP 2003-09-20
  • 打赏
  • 举报
回复
一开始定义就要reDim
像Dim theFiles()
再redim有问题
还有正如所说二维不能该第一维
超级大笨狼 2003-09-20
  • 打赏
  • 举报
回复
Microsoft® Visual Basic® Scripting Edition
ReDim 语句 语言参考
版本 3.0


请参阅


--------------------------------------------------------------------------------

描述
用于过程级声明动态数组变量并分配或重新分配存储空间。
语法
ReDim [Preserve] varname(subscripts) [, varname(subscripts)] . . .
ReDim 语句语法有以下部分:

部分 描述
Preserve 当更改现有数组最后一维的大小时保留数据。
varname 变量名,遵循标准变量命名约定。
subscripts 数组变量的维数,最多可以声明 60 维数组。subscripts 参数语法格式如下:
upper [,upper] . . .

数组的下界总是零。



说明
ReDim 语句通常用于指定或修改动态数组的大小,这些数组已用带有空括号的 Private、Public 或 Dim 语句(没有维数下标)正式声明过。可以重复使用 ReDim 语句更改数组维数和元素数目。
如果使用了 Preserve 关键字,就只能调整数组最后维的大小,并且不能改变数组的维数。例如,如果数组只有一维,就可以修改该数组的大小,因为该维是最后的也是仅有的一维。但是,如果数组有两个或更多维,就只能改变末维的大小并保留数组内容。下面的样例示范了如何不删除动态数组的原有内容而又增加末维的大小。


ReDim X(10, 10, 10)
. . .
ReDim Preserve X(10, 10, 15)


--------------------------------------------------------------------------------

小心 如果减小数组的大小,则将丢失被排除的元素中的数据。

--------------------------------------------------------------------------------

变量初始化时,数值变量初始化为 0,字符串变量初始化为零长度字符串 ("")。在使用引用对象的变量前,必须使用 Set 语句将某个现有对象赋予该变量。在进行对象赋值以前,已声明的对象变量有特定值 Nothing。

--------------------------------------------------------------------------------
© 1997 Microsoft Corporation 版权所有。
julyclyde 2003-07-09
  • 打赏
  • 举报
回复
那就是说不能变啦!
你改用数据结构存储算了
netexe 2003-07-09
  • 打赏
  • 举报
回复
提示:第一维大小是不能变的,
musicfree_uibe 2003-07-09
  • 打赏
  • 举报
回复
哦,看了看文档明白了。。。
if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array.

那么有什么办法解决我的问题?各位大侠帮帮忙!!!!
musicfree_uibe 2003-07-09
  • 打赏
  • 举报
回复
upup~~~~
musicfree_uibe 2003-07-09
  • 打赏
  • 举报
回复
不是啦。。。唉,我把源代码贴出来吧!
function bianli(path)

'initiate
path = server.mappath(path)
set fso=server.CreateObject("scripting.filesystemobject")
set objFolder=fso.GetFolder(path)
set objfiles = objfolder.files

'把文件名及文件路经存入theFiles数组
int slot = 0
Dim theFiles()
redim theFiles(50,50)
for each objFile in objFiles
filename = objFile.name
filePath = split(objFile.path,"docs\")
thepath1 = "。/docs/"
thepath = thepath1 & filepath(1)
theFiles(slot,0) = filename
theFiles(slot,1) = thepath
slot = slot + 1
if slot > UBound(theFiles) then
ReDim Preserve theFiles(Slot+20,slot+20)
end if
next
ReDim Preserve theFiles(slot,slot) '******就是这里出问题!!!!!!
'冒泡排序
for i = 0 to UBound(theFiles)-1
for j = i+1 to UBound(theFiles)
if strComp(theFiles(i,0),theFiles(j,0)) = 1 then
tmpFilename = theFiles(i,0)
tmpFilePath = theFiles(i,1)
theFiles(i,0) = theFiles(j,0)
theFiles(i,1) = theFiles(j,1)
theFiles(j,0) = tmpFilename
theFiles(j,1) = tmpFilePath
end if
next
next

'输出
for i = 0 to UBound(theFiles)
%>
<p align = "left">
---<img src='../../images/arrow_orange.gif' width='14' height='11'>
<a href='<%=theFiles(i,1)%>'><span class="activelink_yellow"><%=theFiles(i,0)%></span></a>
</p>
<%
next
end function
%>
julyclyde 2003-07-09
  • 打赏
  • 举报
回复
1 你是不是用ubound取的所谓“数组大小”?
如果是的话,你回去再看看文档。ubound取的是“最大可用下标”而不是数组大小
2 数组的下标是从0到最大可用下标,一共(最大可用下标+1)个元素
julyclyde 2003-07-09
  • 打赏
  • 举报
回复
你定义的大小和原大小一样,而且还preserve,那你重定义它干什么?

28,391

社区成员

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

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