Page 205 - DCAP408_WEB_PROGRAMMING
P. 205
Unit 7: Introduction to ASP (Active Server Pages)
myFixedArray(1) = “Mother Teresa” Notes
myFixedArray(2) = “Bill Gates”
myFixedArray(3) = “Martin Luther King Jr.”
For Each item In myFixedArray
Response.Write(item & “<br />”)
Next
%>
Display:
Albert Einstein Mother Teresa Bill Gates Martin Luther King Jr.
ASP Dynamic Sized Arrays
To create an array whose size can be changed at any time simply do not put a number within the
parenthesis when you declare the array. When you know what size you want the array to be use
the ReDim keyword. You may ReDim as many times as you wish.
If you want to keep your data that already exists in the array then use thePreserve keyword.
Below is an example of all these things we have just talked about.
Example:
ASP Code:
<%
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
%>
Self Assessment
Fill in the blanks:
14. To create an array whose size can be changed at any time simply do not put a number
within the ............................. when you declare the array.
15. An array is a group of variables that you can access by specifying the .............................
inside the array.
LOVELY PROFESSIONAL UNIVERSITY 199