欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp中使用redim、preserve創(chuàng)建動(dòng)態(tài)數(shù)組實(shí)例

 更新時(shí)間:2014年08月15日 09:32:03   投稿:junjie  
這篇文章主要介紹了asp中使用redim、preserve創(chuàng)建動(dòng)態(tài)數(shù)組實(shí)例,本文還給出了ASP中其它的數(shù)組操作例子,需要的朋友可以參考下

asp中REDIM的功能是動(dòng)態(tài)定義數(shù)組長(zhǎng)度
  
動(dòng)態(tài)數(shù)組里面的一個(gè)語(yǔ)句,只能出現(xiàn)在過(guò)程里面,可以多次使用??梢愿淖償?shù)組大小,和維數(shù)。

格式:

REDIM [Preserve] 數(shù)組名(下標(biāo)1[下標(biāo)2....])
Preserve 保留動(dòng)態(tài)數(shù)組的內(nèi)容(不用的話,每次執(zhí)行REDIM語(yǔ)句,當(dāng)前存儲(chǔ)的語(yǔ)句會(huì)全部丟失)

例如:

復(fù)制代碼 代碼如下:

Dim DynArray() '定義數(shù)組DynArray()為動(dòng)態(tài)數(shù)組
REDIM Preserve DynArray(20)'為該數(shù)組分配元數(shù)個(gè)數(shù)

  這樣對(duì)編程中一些動(dòng)態(tài)的改變數(shù)組是非常重要的,而且經(jīng)常能用到,處理到,這REDIM深入了解第二電腦認(rèn)為對(duì)自己的編程的提高很有幫助。

下面舉一些ASP數(shù)組的例子,當(dāng)然不全是動(dòng)態(tài)數(shù)組

在ASP編程中使用數(shù)組:

數(shù)組的定義:

復(fù)制代碼 代碼如下:

Dim MyArray
MyArray = Array(1‚5‚123‚12‚98)

可擴(kuò)展數(shù)組:

復(fù)制代碼 代碼如下:

Dim MyArray()
for i = 0 to 10
ReDim Preserve MyArray(i)
MyArray(i)=i
next

將一個(gè)字符串分割并返回分割結(jié)果的數(shù)組:

復(fù)制代碼 代碼如下:

Dim MyArray
MyArray = Split(tempcnt‚chr(13)&chr(10))
For I = Lbound(MyArray) to Ubound(MyArray)
Response.Write MyArray(I) & "<br>"
Next

數(shù)組排序函數(shù):

復(fù)制代碼 代碼如下:

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

數(shù)組排序函數(shù)應(yīng)用例子:

復(fù)制代碼 代碼如下:

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中使用數(shù)組:

復(fù)制代碼 代碼如下:

Application.Lock
Application("StoredArray") = MyArray
Application.Unlock
LocalArray = Application("StoredArray")

覆蓋Application中的數(shù)組:

復(fù)制代碼 代碼如下:

Application.Lock
Application("StoredArray") = LocalArray
Application.Unlock

Session使用方法與Application相同,從數(shù)據(jù)庫(kù)中把數(shù)據(jù)導(dǎo)入數(shù)組中:

復(fù)制代碼 代碼如下:

Dim MyArray
'取出全部記錄
MyArray = RS.GetRows
'取出前10項(xiàng)記錄
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

通過(guò)以上的例子可以加深我們對(duì)數(shù)組的理解,在實(shí)際運(yùn)用中加以靈活運(yùn)用。

相關(guān)文章

最新評(píng)論