在ASP编程中使用数组

2018-09-06 10:58

阅读:541

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

可扩展数组
DimMyArray()
fori=0to10
ReDimPreserveMyArray(i)
MyArray(i)=i
next

将一个字符串分割并返回分割结果的数组
DimMyArray
MyArray=Split(tempcnt,chr(13)&chr(10))
ForI=Lbound(MyArray)toUbound(MyArray)
Response.WriteMyArray(I)&<br>
Next

数组排序函数
function..Sort(ary)
KeepChecking=TRUE
DoUntilKeepChecking=FALSE
KeepChecking=FALSE
ForI=0toUBound(ary)
IfI=UBound(ary)ThenExitFor
Ifary(I)>ary(I+1)Then
FirstValue=ary(I)
SecondValue=ary(I+1)
ary(I)=SecondValue
ary(I+1)=FirstValue
KeepChecking=TRUE
EndIf
Next
Loop
Sort=ary
Endfunction..

数组排序函数应用例子
DimMyArray
MyArray=Array(1,5,123,12,98)
MyArray=Sort(MyArray)
ForI=Lbound(MyArray)toUbound(MyArray)
Response.WriteMyArray(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相同

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

Forrow=0ToUBound(MyArray,2)
Forcol=0ToUBound(MyArray,1)
Response.Write(col,row)&<br>
Next
Next


评论


亲,登录后才可以留言!