Help With Increasing Size Of Simple Multi Dimensional Array

Help With Increasing Size Of Simple Multi Dimensional Array

am 21.02.2005 18:24:30 von andy.mcvicker

Hi Gang

I want to create a simple array that could have up to 100 - 200 rows
and that always has 2 columns (and will have some number value in each
column). I can't seem to figure out how to create the array initially,
increase the row size 1 by 1 and populate the values of the array in a
loop.

Can you please help with the (I think) simple problem??

Thanks
Andy

Re: Help With Increasing Size Of Simple Multi Dimensional Array

am 21.02.2005 18:34:34 von gerard.leclercq

http://www.stylusinc.net/technology/microsoft/asp_arrays.sht ml

Re: Help With Increasing Size Of Simple Multi Dimensional Array

am 21.02.2005 18:44:41 von reb01501

Andy wrote:
> Hi Gang
>
> I want to create a simple array that could have up to 100 - 200 rows
> and that always has 2 columns (and will have some number value in each
> column). I can't seem to figure out how to create the array
> initially, increase the row size 1 by 1 and populate the values of
> the array in a loop.
>
> Can you please help with the (I think) simple problem??
>
> Thanks
> Andy

In a multidemensional array, only the last dimension can be resized. So you
need to use your first dimension to denote columns, and the second to denote
rows, allowing you to do this:

redim myarray(1, ubound(myarray,2) + 1)


Having said that, if it is at all possible to figure out before the loop how
many rows will be added, you will gain considerable performance benefits by
defining the proper number of rows before the loop:

dim myarray(), rows
rows=CalcNumberOfRows()
redim myarray(1,rows-1)
'run loop to fill array

If you can't determine the exact number of rows, your second best option is
to size your array to some number greater than you will ever need:

dim myarray(1,1000)
'run loop to fill array

Then simply ignore the empty rows in your later code.

Lastly, if you are filling the array from a recordset, you may be
overlooking the easiest solution of all: GetRows
(http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthget rows.asp).

Bob Barrows


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Re: Help With Increasing Size Of Simple Multi Dimensional Array

am 22.02.2005 01:34:33 von Roland Hall

"Bob Barrows [MVP]" wrote in message
news:uyxyB0DGFHA.3840@tk2msftngp13.phx.gbl...
: Andy wrote:
: > Hi Gang
: >
: > I want to create a simple array that could have up to 100 - 200 rows
: > and that always has 2 columns (and will have some number value in each
: > column). I can't seem to figure out how to create the array
: > initially, increase the row size 1 by 1 and populate the values of
: > the array in a loop.
: >
: > Can you please help with the (I think) simple problem??
: >
: > Thanks
: > Andy
:
: In a multidemensional array, only the last dimension can be resized. So
you
: need to use your first dimension to denote columns, and the second to
denote
: rows, allowing you to do this:
:
: redim myarray(1, ubound(myarray,2) + 1)
:
:
: Having said that, if it is at all possible to figure out before the loop
how
: many rows will be added, you will gain considerable performance benefits
by
: defining the proper number of rows before the loop:
:
: dim myarray(), rows
: rows=CalcNumberOfRows()
: redim myarray(1,rows-1)
: 'run loop to fill array
:
: If you can't determine the exact number of rows, your second best option
is
: to size your array to some number greater than you will ever need:
:
: dim myarray(1,1000)
: 'run loop to fill array
:
: Then simply ignore the empty rows in your later code.
:
: Lastly, if you are filling the array from a recordset, you may be
: overlooking the easiest solution of all: GetRows
: (http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthget rows.asp).

Or a dictionary object...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp