快速业务通道

ASP教程:ASP关于数组的应用技巧

作者 佚名技术 来源 ASP编程 浏览 发布时间 2012-03-12

WebjxCom提示:ASP教程:ASP关于数组的应用技巧.

数组的定义
Dim MyArray
MyArray = Array(1,5,123,12,98)

可扩展数组
Dim MyArray()
for i = 0 to 10
ReDim Preserve MyArray(i)
MyArray(i)=i
next

将一个字符串分割并返回分割结果的数组
Dim MyArray
MyArray = Split(tempcnt,chr(13)&chr(10))
For I = Lbound(MyArray) to Ubound(MyArray)
Response.Write MyArray(I) & "<br>"
Next

数组排序函数
function Sort(ary)
KeepChecking = TRUE
Do Until KeepChecking = FALSE
KeepChecking = FALSE
For I = 0 to UBound(ary)
If I = UBound(ary) Then Exit For
If ary(I) > ary(I+1) Then
FirstValue = ary(I)
SecondValue = ary(I+1)
ary(I) = SecondValue
ary(I+1) = FirstValue
KeepChecking = TRUE
End If
Next
Loop
Sort = ary
End function

数组排序函数应用例子
Dim MyArray
MyArray = Array(1,5,123,12,98)
MyArray = Sort(MyArray)
For I = Lbound(MyArray) to Ubound(MyArray)
Response.Write MyArray(I) & "<br>"
Next

在Application和Session中使用数组
Application.Lock
Application("StoredArray") = MyArray
Application.Unlock

LocalArray = Application("StoredArray")

覆盖Application中的数组
Application.Lock
Application("StoredArray") = LocalArray
Application.Unlock

Session使用方法与Application相同

从数据库中把数据导入数组中
Dim MyArray
取出全部记录
MyArray = RS.GetRows
取出前10项记录
MyArray = RS.GetRows(10)

For row = 0 To UBound(MyArray, 2)
For col = 0 To UBound(MyArray, 1)
Response.Write (col, row) & "<br>"
Next
Next

''*********************************
''针对asp冒泡算法
''*********************************
Function Sort(ary)
Dim KeepChecking,I,FirstValue,SecondValue
KeepChecking = TRUE
Do Until KeepChecking = FALSE
KeepChecking = FALSE
For I = 0 to UBound(ary)
If I = UBound(ary) Then Exit For
If ary(I) > ary(I+1) Then
FirstValue = ary(I)
SecondValue = ary(I+1)
ary(I) = SecondValue
ary(I+1) = FirstValue
KeepChecking = TRUE
End If
Next
Loop
Sort = ary
End Function

dim ID,ArrayID,Myarray,M
ID="55,48,78,10,90"
ArrayID=split(ID,",")
Myarray=Sort(ArrayID)
''排序测试
For M=0 To Ubound(Myarray)
Response.Write Myarray(M) & "<br>" & vbCRLF
Next

''当然也可以用下面的,
Dim Myarray
Myarray=Array(12,10,25,78,45)
Myarray=Sort(ArrayID)
''排序测试
For M=0 To Ubound(Myarray)
Response.Write Myarray(M) & "<br>" & vbCRLF
Next
''排序测试

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号