Can I add rows to an already dimensioned 2d array

C

Colin Steadman

Is the following assumption correct?

If I setup an array with 5 rows and 8 columns.

Private invoiceItemsArray
ReDim invoiceItemsArray(4,7)

Am I stuffed if I want to add a fifth row? From what I've
read I will only be able to add more columns in this
instance.

Is this correct? And if so is there a work-a-round.
Would I need to create a new array with one extra row, use
the old one to populate it and then add my new row data?

TIA,

Colin
 
B

Bob Barrows [MVP]

Colin said:
Is the following assumption correct?

If I setup an array with 5 rows and 8 columns.

Private invoiceItemsArray
ReDim invoiceItemsArray(4,7)

Am I stuffed if I want to add a fifth row? From what I've
read I will only be able to add more columns in this
instance.

Is this correct?

Yes, that is correct.
And if so is there a work-a-round.

Yes, reverse your definitions of "rows" and "columns"

Private invoiceItemsArray
ReDim invoiceItemsArray(7,4)
....
ReDim invoiceItemsArray(7,5)


HTH,
Bob Barrows
 
M

Mark Schupp

Will there always be 8 columns?

If so, either reverse the subscripts so that "column" is the first subscript
or use a one-dimensional array and compute the offsets as in:

col1val = invoiceItemsArray( nRow*8 )
col2val = invoiceItemsArray( nRow*8 + 1)
col3val = invoiceItemsArray( nRow*8 + 2)

etc.

If both subscript ranges are variable and you cannot put an upper bound on
one or the other then you will probably have to create a new array and copy
the existing data to increase the array size.
 
G

Guest

Yes, reverse your definitions of "rows" and "columns"

Private invoiceItemsArray
ReDim invoiceItemsArray(7,4)
....
ReDim invoiceItemsArray(7,5)


Damn, I knew something wasn't right. This is really
starting to get confusing. I'm going to drop this
completely for the moment, go home and work on it again
tomorrow morning when the mist has cleared.

Thank you.

Colin
 
D

dlbjr

'Use a Disconnected Recordset to manage the data
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.CursorType = adOpenStatic
rs.fields.append "TEXT1",200,15
rs.fields.append "NUM1",5

'APPEND AS MANY FIELDS AS NEEDED
rs.Open

'ADD RECORDS AS NEEDED
rs.AddNew

'DO WHAT EVER WITH THE DATA

'CLEAN UP
Set rs = Nothing


'dlbjr

'Discerning resolutions for the alms
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top