The function of ReDim in ASP is to define the array length dynamically
A statement inside a dynamic array can only appear in the process and may be used more than once. You can change the size of the array, and the number of dimensions.
Format:
REDIM [Preserve] Array name (subscript 1[subscript 2 ...] )
Preserve retains the contents of the dynamic array (if not, the currently stored statement is lost every time the ReDim statement is executed)
For example:
Copy Code code as follows:
Dim Dynarray () ' defines an array dynarray () as a dynamic array
REDIM Preserve Dynarray (20) ' assigns a number of tuples to the array
This is very important for some of the dynamic array changes in programming, and it is often used, processed, and ReDim to understand that the second computer is helpful in improving its programming.
Here are some examples of ASP arrays, of course not all dynamic arrays
To use arrays in ASP programming:
The definition of an array:
Copy Code code as follows:
Dim myarray
MyArray = Array (1 ' 5 ' 123 ' 12 ' 98)
Extensible array:
Copy Code code as follows:
Dim MyArray ()
For i = 0 to 10
ReDim Preserve myarray (i)
MyArray (i) =i
Next
Splits a string and returns an array of split results:
Copy Code code as follows:
Dim myarray
MyArray = Split (tempcnt ' Chr) &CHR (10))
For I = Lbound (myarray) to Ubound (myarray)
Response.Write MyArray (I) & "<br>"
Next
Array sort function:
Copy Code code as follows:
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
An example of an array sort function application:
Copy Code code as follows:
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
To use arrays in application and sessions:
Copy Code code as follows:
Application.Lock
Application ("StoredArray") = MyArray
Application.UnLock
LocalArray = Application ("StoredArray")
To overwrite an array in application:
Copy Code code as follows:
Application.Lock
Application ("StoredArray") = LocalArray
Application.UnLock
The session is used in the same way as application to import data from the database into an array:
Copy Code code as follows:
Dim myarray
' Take out all records
MyArray = RS. GetRows
' Take out the top 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
Through the above examples, we can deepen our understanding of the logarithmic group and use it flexibly in practical application.