Array definition
DimMyArray
MyArray = Array(1,5,123,12,98)
Expandable array
DimMyArray()
for i = 0 to 10
ReDim Preserve MyArray(i)
MyArray(i)=i
next
Splits a string and returns an array of split results
DimMyArray
MyArray = Split(tempcnt,chr(13)&chr(10))
For I = Lbound(MyArray) to Ubound(MyArray)
Response.Write MyArray(I) & <br>
Next
Array sort function
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
Array sorting function application example
DimMyArray
MyArray = Array(1,5,123,12,98)
MyArray = Sort(MyArray)
For I = Lbound(MyArray) to Ubound(MyArray)
Response.Write MyArray(I) & <br>
Next
Using arrays in Application and Session
Application.Lock
Application(StoredArray) = MyArray
Application.Unlock
LocalArray = Application(StoredArray)
Overwrite array in Application
Application.Lock
Application(StoredArray) = LocalArray
Application.Unlock
Session usage is the same as Application
Import data from database into array
DimMyArray
Get all records
MyArray = RS.GetRows
Get the first 10 records
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
'**********************************
'For asp bubbling algorithm
'**********************************
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)
'Sort test
For M=0 To Ubound(Myarray)
Response.Write Myarray(M) & <br> & vbCRLF
Next
'Of course you can also use the following,
Dim Myarray
Myarray=Array(12,10,25,78,45)
Myarray=Sort(ArrayID)
'Sort test
For M=0 To Ubound(Myarray)
Response.Write Myarray(M) & <br> & vbCRLF
Next
'Sort test