ASP中数组的使用

1.数组的定义
Dim intArray
intArray= Array(1,2,3,4,5,6,7,8,9,10,11,12)
Dim strArray
strArray = Array("a","b","c","d","e","f","g")
Dim arr(20)
注意了这里的20是定义了从0到20的21格数组元素

2.可扩展数组
Dim MyArray()
For i = 0 to 5
   ReDim Preserve MyArray(i)
   MyArray(i)=i
Next

3.将字符串分割为数组
Dim strArray
strArray= Split("This is Array!"," ")

For i = LBound(strArray) to UBound(strArray) 
   Response.Write strArray(i)
Next

4.数组排序函数
Function ArraySort(ary) 
        flag= TRUE 

        Do Until flag = FALSE 
               flag = 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 
                             flag = TRUE 
                      End If 
               Next
        Loop 
        ArraySort = ary
End Function

数组排序函数应用例子
Dim intArray
intArray = Array(1,5,123,12,98)
intArray = Sort(intArray )
For i = Lbound(intArray ) to Ubound(intArray )
     Response.Write intArray (i)
Next

5.在Application和Session中使用数组
Application.Lock
ApplicationStoredArray) = MyArray
Application.Unlock

LocalArray = Application(StoredArray)

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

Session使用方法与Application相同

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

For row = 0 To UBound(RsArray, 2)
    For col = 0 To UBound(RsArray, 1)
        Response.Write RsArray(col, row) 
    Next
Next

7.二维数组
Dim arr(10,10)

arr(0,0)="frist"
posted @ 2007-03-12 11:08  meil  阅读(1879)  评论(2编辑  收藏  举报