rss search

Dynamic Arrays

line

Dynamic arrays come in handy when you aren’t sure how many items your array will hold. To create a dynamic array you should use the Dim statement along with the array’s name, without specifying upper bound:

<%
Dim arrCars
arrCars = Array()
%>

In order to use this array you need to use the ReDim statement to define the array’s upper bound:

 

<%
Dim arrCars
arrCars = Array()
Redim arrCars(27)
%>

If in future you need to resize this array you should use the Redim statement again. Be very careful with the ReDim statement. When you use the ReDim statement you lose all elements of the array. Using the keyword PRESERVE in conjunction with the ReDim statement will keep the array we already have and increase the size:

<%
Dim arrCars
arrCars = Array()
Redim arrCars(27)
Redim PRESERVE arrCars(52)
%>
Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter


Leave a Reply

You must be logged in to post a comment.

Devguru.in is Stephen Fry proof thanks to caching by WP Super Cache