Forum Moderators: open

Message Too Old, No Replies

Add a column to an array

without losing any data

         

aspdaddy

9:48 am on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi

I have a 2D array full of data arrStuff

How do I add an extra column to the right hand side, initiliaed with all 0's

Thanks

TheNige

7:58 pm on Apr 27, 2007 (gmt 0)

10+ Year Member



You will need to use "Redim Preserve"

bmcgee

2:55 am on Apr 28, 2007 (gmt 0)

10+ Year Member



Note that redim only works on the last dimension of an array, which will work for what you need.

Also note that redim will not set the new buckets to 0, you will have to do that yourself.

aspdaddy

8:07 am on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anyone have example code? The problem is that the array is created using GetRows() so I dont know the dimensions in advance.

ksks

6:16 pm on Apr 28, 2007 (gmt 0)

10+ Year Member



Perhaps look into ArrayList()

TheNige

8:31 pm on Apr 30, 2007 (gmt 0)

10+ Year Member



I assume that you are using classic ASP right?

Get rows always produces a 2D array I believe, rows (dimension 1) and columns (dimension 2) representing your dataset.

You will need to find out the upper bounds of your 2nd dimension and then add one to it for the extra column.

'Get the column and row count
rowCount = UBound(myArray, 1)
columnCount = UBound(myArray, 2)

'Add the extra column
Redim Reserve myArray(rowCount, columnCount + 1)

'Then you will need to loop through the rows and update the new column to 0
For i=0 to rowCount
myArray(i, columnCount + 1) = 0
Next

I didn't test the above code but it should work in theory or get you close.

Also, couldn't you just add the 0 at the end of your select statement? "Select col1, col2, col3, 0 from mytable"

[edited by: TheNige at 8:32 pm (utc) on April 30, 2007]