ASP Vbscript ReDim Array
ASP Vbscript Redim statement for arrays is used to redefine the array size. You can increase the size of the vbscript dynamic array in asp using redim statement. Vbscript redim statement works only with dynamic arrays declared with Dim statement with any array size defined. There is no limit for vbscript array to redefine their size. You can increase the size of the array using ReDim statement dynamically within the vbscript code and you can assign value at new memory locations created within the array index declared in the variable declaration statement.
Classic ASP VbScript Array Functions Examples:
You can see the live samples and examples of Classic ASP VbScript Array Functions from the following links:
Syntax for ASP Vbscript Redim Array
Dim myArray() ReDim myArray(10)
Redim statement will increase the size of the dynamic array to 10, having no size defined in the first statement. After redim declaration, myArray can store the 11 array items.
You can store the variant type data items in the Vbscript arrays. See the following example to learn the Redim statement for array and variant type values store in it.
Example of ASP Vbscript Redim Array
<% Dim myArray() Redim myArray(2) myArray(0) = "array item 1" myArray(1) = 1 myArray(2) = "array item 3" ReDim myArray(5) myArray(3) = 3 myArray(4) = "array item 5" myArray(5) = "array item 6" Response.Write "myArray(2): " & myArray(2) & "<br />" Response.Write "myArray(5): " & myArray(5) & "<br />" %>
In the above example myArray is declared as dynamic array in the vbscript code for asp web page. In the second statement Redim is used to set the array size =2 that can store 2 items. Then 3 values are assigned to 0, 1 and 2 index place of the myArray. Redim statement is used again to increase the size of myArray to 5 so that it could store 6 items. Then again 3 more values are assigned to the 3rd, 4th and 5th number index of myArray.
It will not display the value at array index 2 because when size of dynamic array is changed by used ReDim statement it looses the data stored in the array.
Continue to next tutorial: ASP Vbscript ReDim Preserve Array to learn how to increase the length of dynamic array without loosing old values.