STATEMENT: ReDim
ReDim
The ReDim statement allows you to formally declare, and to
later redeclare as many times as you need, the size (and hence the memory
space allocation) for a dynamic array that was originally declared using
either a Dim, Private or Public statement.
The first time you use ReDim to declare an array, you can create
either a single or a multiple dimension array. However, after you have
set the number of the dimensions, you cannot later go back and change
the number of the dimensions. Also, once you have created a multi-dimension
array, you can only redeclare the size of the last element.
If you make the array bigger, you can use the keyword Preserve
to protect all of the existing elements. If you make the array smaller,
you will lose part of the array elements even if you use Preserve.
Do not use Preserve the first time that you ReDim an array
since it will prohibit setting multiple dimensions.
In this example, we declare myarray() to have a single dimensions
and then resize the element. When we resize from 999 down to 9, we lose
the data in the other 990 elements.
Code:
<% Dim myarray() %>
<% ReDim myarray(5) %>
<% ReDim Preserve myarray(999) %>
<% ReDim Preserve myarray(9) %>
In this example, we declare myarray() to have three dimensions and
then resize the last element. When we resize the last element from 999
down to 9, we lose the data in the other 990 elements.
Code:
<% Dim myarray() %>
<% ReDim myarray(20, 10, 99) %>
<% ReDim Preserve myarray(20, 10, 999) %>
<% ReDim Preserve myarray(20, 10, 9) %>
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information
|