all groups > inetserver asp db > february 2005 >
You're in the

inetserver asp db

group:

Help With Increasing Size Of Simple Multi Dimensional Array



Help With Increasing Size Of Simple Multi Dimensional Array Andy
2/21/2005 9:24:30 AM
inetserver asp db: 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 Bob Barrows [MVP]
2/21/2005 12:44:41 PM
[quoted text, click to view]

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/mdmthgetrows.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 Gérard Leclercq
2/21/2005 5:34:34 PM
Re: Help With Increasing Size Of Simple Multi Dimensional Array Roland Hall
2/21/2005 6:34:33 PM
[quoted text, click to view]
: > 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/mdmthgetrows.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

AddThis Social Bookmark Button