In an ASP program, you need to define a dynamic array, but the size of the array can not be ReDim in place once, depending on the actual need to increase, and then have the following code:
| The code is as follows |
Copy Code |
|
<%
Dim arr ()
' Assign value
For i = 1 to 10
Redim Preserve arr (UBound (arr) + 1)
Arr (UBound (arr)) = I
Next
' Traversal
For i=0 to UBound (arr)
Response.Write (Arr (i) & "<br/>")
Next
%> |
Run Error:
The reason is not to call the ReDim definition array before the subscript, using UBound to obtain an array of RCAs error, prompted the subscript out of bounds, the code can be slightly modified to resolve:
| The code is as follows |
Copy Code |
|
<%
Dim arr ()
ReDim arr (0)
' Assign value
For i = 1 to 10
If arr (UBound (arr)) <> "" Then
Redim Preserve arr (UBound (arr) + 1)
End If
Arr (UBound (arr)) = I
Next
' Traversal
For i=0 to UBound (arr)
Response.Write (Arr (i) & "<br/>")
Next
%> |