In Asparray follow the same form and rules as these in Vbscriptarray. You can create an array of specific sizes or you can create a vibrant size array. Here we illustrate the two types of array.
<%
Dim Myfixedarray (3) ' Fixed size array
Dim Mydynarray () ' Dynamic size array
%>
We will focus on the fixed size array in the first and overlay dynamic array later in this lesson.
assigning values to arrays
Let's make up for the value of our fixed size array. Our fixed array will store the name of a famous person. To specify an array of values you need to know three things:
The name array
The value to store
Value to store in the location array.
An array is a set of variables that you can specify by the array within the location. Our Arraymyfixedarray has 4 positions: 0, 1, 2 and 3. Let's specify some values for our array.
<%
Dim Myfixedarray (3) ' Fixed size array
Myfixedarray (0) = "Albert Einstein"
Myfixedarray (1) = "Mother Teresa"
Myfixedarray (2) = "Bill Gates"
Myfixedarray (3) = "Martin Luther King Jr."
%>
<%
Dim Myfixedarray (3) ' Fixed size array
Myfixedarray (0) = "Albert Einstein"
Myfixedarray (1) = "Mother Teresa"
Myfixedarray (2) = "Bill Gates"
Myfixedarray (3) = "Martin Luther King Jr."
For each item in Myfixedarray
Response.Write (Item & "<br/>")
Next
%>
ASP array Definition
To create an array, its size can be changed at all times without putting some parentheses inside when you declare the array. When you know you want the size of the array will use the ReDim keyword. You may ReDim many times of your wishes.
If you want your data to already exist in the array and then use the reserved keyword. Here is an example of all these things that we have just talked about.
<%
Dim Mydynarray () ' Dynamic size array
ReDim Mydynarray (1)
Mydynarray (0) = "Albert Einstein"
Mydynarray (1) = "Mother Teresa"
ReDim Preserve Mydynarray (3)
Mydynarray (2) = "Bill Gates"
Mydynarray (3) = "Martin Luther King Jr."
For each item in Mydynarray
Response.Write (Item & "<br/>")
Next
%>