Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Arrays: Basics
     [next Lesson]  Arrays: Best Way To Load

Arrays to store data Part #2 by Charles Carroll

Assigning an array size with a variable produces a variable unless the Redim command is used.

  • Method #1: You know the size
  • Method #2: the size is in a variable

   filename=/learn/test/arraysredim.asp

<Test Script Below>


<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.

   filename=/learn/test/arraysredimcorrect.asp

<Test Script Below>


<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 & "&nbsp;&nbsp;&nbsp;" 
        response.write my_array(counter) & "<br>"
    next

%>
</body></html>

Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site