This assumes you know the basic characteristics of arrays, so let's consider how to deal with ASP in VBScript.
Arrays in VBScript are 0, which means that the index of array elements always starts from 0. Array represented by 0 index
The first position in the array, the 1 index represents the second position in the array, and so on.
There are two types of VBScript arrays - static and dynamic. Static arrays stay at a fixed size throughout their lifetime. want
To use static VBScript arrays you need to know the maximum number of early elements this array will contain. If you
Need the size of the index to be changed into a flexible VBScript array, then you can use a dynamic VBScript array
. The size of dynamic array indexes in VBScript can increase/decrease during its lifetime.
static array
Let's create an array called 'arrCars' that will hold the names of 5 cars
<%@ LANGUAGE=VBSCRIPT %>
<%
'Use the Dim statement along with the array name
'to create a static VBScript array
'The number in parentheses defines the array 's upper bound
Dim arrCars(4)
arrCars(0)=BMW
arrCars(1)=Mercedes
arrCars(2)=Audi
arrCars(3)=Bentley
arrCars(4)=Mini
'create a loop moving through the array
'and print out the values
For i=0 to 4
response.write arrCars(i) & <br>
Next 'move on to the next value of i
%>
Here's another way to define a VBScript array:
<%
'we use the VBScript Array function along with a Dim statement
'to create and populate our array
Dim arrCars
arrCars = Array(BMW,Mercedes,Audi,Bentley,Mini) 'each element
must be separated by a comma
'again we could loop through the array and print out the values
For i=0 to 4
response.write arrCars(i) & <br>
Next
%>
dynamic array
Dynamic arrays come in handy when you don't know how many items your array will hold. To create dynamic array you should
Use the Dim statement together with an array name without specifying an upper bound:
<%
Dim arrCars
arrCars = Array()
%>
In order to use this array, you need to use the ReDim statement to define the upper bound of the array:
<%
Dim arrCars
arrCars = Array()
Redim arrCars(27)
%>
If you need to resize this array in the future, you should use the ReDim statement. Be very careful with ReDim statements.
When you use the ReDim statement you lose all array elements. Keywords saved with a ReDim statement will
Keep the array we've increased in size:
<%
Dim arrCars
arrCars = Array()
Redim arrCars(27)
Redim PRESERVE arrCars(52)
%>