adding a dimension to an array

  • Thread starter Thread starter MattB
  • Start date Start date
M

MattB

I have an one dimensional array being created from a delimited list using
string.split. Now I'd like to take that array and add another dimension and
manually put a value in there based on the contents of the first element. I
can loop through my array no problem, but I don't see how (if?) I can add
another "column" to it. Seems like it should be simple.

Can I do this? How? TIA!

Matt
 
Matt,

I don't believe you can add a dimension to an array. I would declare a new
array and use array.copy to move the contents of the old 1-dim array into
the new multi-dim array.

HTH,

Raymond Lewallen
 
* "MattB said:
I have an one dimensional array being created from a delimited list using
string.split. Now I'd like to take that array and add another dimension and
manually put a value in there based on the contents of the first element. I
can loop through my array no problem, but I don't see how (if?) I can add
another "column" to it. Seems like it should be simple.

You cannot change the number of dimensions in an array, you will have to
create a new array with more dimensions and copy over data.
 
I was actually just trying that approach. I'm having trouble using
array.copy to go from a one-demensional array to a two-dimensional array.
Anyone got a sample? Thanks!

Matt
 
Mattb,
Array.Copy requires both arrays to have the same dimensions.

You will have to use a For loop to copy the elements.

Something like:

Dim x(9) As Integer
Dim y(9, 1) As Integer
For index As Integer = 0 To x.Length - 1
y(index, 0) = x(index)
Next

Hope this helps
Jay
 
Back
Top