Codefixer - ASP tutorials, resources and software
ASP.NET 3.5/2.0 Hosting – Click Here
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Wednesday 23 July
MembersPro PayPal - ASP Membership software

asp.netPRO “Best ASP.NET Host” – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Dynamic Arrays

In our 'Arrays' tutorial we showed you how to create a fixed size array. The code below declares the array using the Dim statement and passes in a parameter which specifies the maximum number of items that the array can contain. In this case it's 7 as the array has a zero based starting index.

<%
Dim myArray(6)
%>

Dynamic arrays come in handy when you aren't sure how many items your array will hold. To declare a dynamic array simply leave out the parameter.

<%
Dim myArray()
%>

Suppose you wished to create an array to hold all the item ID's in your visitors shopping cart. As you aren't sure how many items they'll purchase you could first of all create a dynamic array.

<%
Dim myShopCartArray()
%>

If your visitor then puts 3 items in their cart you could resize the array using the REDIM function (redimension).

<%
Dim myShopCartArray()

Redim myShopCartArray(2) 'remember zero based index
%>

If the visitor puts another item in their shopping cart you'll need to resize the array again. However you'd lose all the information in the existing array if you just used the Redim function. Using the keyword PRESERVE will keep the array we already have and increase the size.

<%
Dim myShopCartArray()

Redim myShopCartArray(2) 'remember zero based index
Redim PRESERVE myShopCartArray(3)
%>


In part 1 read about 'Arrays'
In part 2 read about 'Array Functions'
In part 3 read about 'Multidimensional Arrays'

LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software