adding a dimension to an array

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
 
R

Raymond Lewallen

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
 
H

Herfried K. Wagner [MVP]

* "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.
 
M

MattB

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
 
J

Jay B. Harlow [MVP - Outlook]

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
 

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

Top