PC Review


Reply
Thread Tools Rate Thread

adding a dimension to an array

 
 
MattB
Guest
Posts: n/a
 
      12th Apr 2004
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


 
Reply With Quote
 
 
 
 
Raymond Lewallen
Guest
Posts: n/a
 
      12th Apr 2004
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" <(E-Mail Removed)> wrote in message
news:c5ets3$uljh$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      12th Apr 2004
* "MattB" <(E-Mail Removed)> scripsit:
> 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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
MattB
Guest
Posts: n/a
 
      12th Apr 2004
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

Raymond Lewallen wrote:
> 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" <(E-Mail Removed)> wrote in message
> news:c5ets3$uljh$(E-Mail Removed)...
>> 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




 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      12th Apr 2004
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

"MattB" <(E-Mail Removed)> wrote in message
news:c5f1tm$uk8m$(E-Mail Removed)...
> 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
>
> Raymond Lewallen wrote:
> > 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" <(E-Mail Removed)> wrote in message
> > news:c5ets3$uljh$(E-Mail Removed)...
> >> 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

>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining Single Dimension to Multi Dimension Array Stathy K Microsoft Excel Programming 5 17th Feb 2009 06:18 PM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
Mutli-dimensional Array to Single-Dimension Array =?Utf-8?B?Qmx1ZSBBYXJkdmFyaw==?= Microsoft Excel Programming 3 15th Oct 2005 09:22 AM
Fastest way to copy from a one dimension byte array to two dimension int array johannblake@yahoo.com Microsoft C# .NET 5 14th Jun 2005 07:45 PM
Array transfer - 1 dimension v. 2 dimension JWolf Microsoft Excel Programming 2 29th Jun 2004 01:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:55 AM.