asp 动态数组问题,急急

来源:百度知道 编辑:UC知道 时间:2024/04/30 04:20:07
下面程序执行时,可以从大到小显示
<%
aa=array(5,8,1,10)
for i=0 to ubound(aa)
for j=i+1 to 3
if aa(j)<aa(i) then
temp=aa(i)
aa(i)=aa(j)
aa(j)=temp
end if
next
response.Write cint(aa(i))&"<br/>"
next
%>

以上程序执行就没有问题

但为什么换成一下程序就不可以执行了呢
<%
a1="5,8,1,10"
a=split(a1,",")
b=ubound(a)
dim aa(a1)
redim aa(b)
aa=array(a1)
for i=0 to ubound(aa)
for j=i+1 to 3
if aa(j)<aa(i) then
temp=aa(i)
aa(i)=aa(j)
aa(j)=temp
end if
next
response.Write cint(aa(i))&"<br/>"
next
%>
刚才楼下的,程序还是不行啊
结果和我做的那个还是一样
没有什么变化

调试成功!
<%
a1="5,8,1,10"
a=split(a1,",")
b=ubound(a)
for i=0 to b
for j=i+1 to b '还有这里不用指明数字了吧.,直接用ubound循环出来的不是更好吗?
if cint(a(j))<cint(a(i)) then '这里将数据类型转换为整型
temp=a(i)
a(i)=a(j)
a(j)=temp
end if
next
response.Write cint(a(i))&"<br/>"
next
%>

楼上的兄弟,记得把数组里面的数据转换为整数,否则1会排在10的前面.呵呵.不知道你们有没有发现这个问题,

你改成下面这样一来就可以了
<%
a1="5,8,1,10"
a=split(a1,",")
b=ubound(a)
for i=0 to b
for j=i+1 to 3
if a(j)<a(i) then
temp=a(i)
a(i)=a(j)
a(j)=temp
end if
next
response.Write cint(a(i))&"<br/>"
next
%>
--------------------------
原因:

dim aa(a1) 是错误的数组定义,而且楼主的代码有部分显得多余
-----------------------------
修改案:
<%
a1="5,8,1,10"
a=split(a1,",")
b=ubound(