Arrays to store data

Posted on Aug 20, 2011 in ASP
Arrays to store data

<html><head>
<title>arraysredim.asp</title>
</head><body bgcolor="#FFFFFF">
<%
' this code 
Dim a_array(100)

' this code will fail
x=100
Dim my_array(x)

%>
</body></html>


Assigning an Array size With a variable produces an Error unless the ReDim command Is used. 

<html><head>
<title>arraysredimcorrect.asp</title>
</head><body bgcolor="#FFFFFF">
<%
Dim my_array()
x=100
ReDim preserve my_array(x)
my_array(20)="Hi!"
my_array(40)="How are You"

lowcount=LBound(my_array)
highcount=UBound(my_array)
Response.Write "lowcount=" & lowcount & ";highcount=" & highcount & "<p>"
For counter=lowcount To highcount
Response.Write counter & "   " 
Response.Write my_array(counter) & "<br>"
Next

%>
</body></html>