Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Redimming (preserve) a 3D array

This is a repost of an earlier question that didn't recieve responses (my
question may have been too obscure).

I have a 3D array which I'll call myarray(1 to 10, 1 to 100, 1 to 3)

I would like to reduce the number of parameters to turn it into a 2D array
which I'll call mynewarray(1 to 10, 1 to100) while keeping the data that is
already in the array.

Redim/preserve only allows you to mess with the last dimension (1 to 3),
which is fine- but from help:
"Similarly, when you use Preserve, you can change the size of the array only
by changing the upper bound; changing the lower bound causes an error"

The data I'd like to preserve is in the middle, e.g. mynewarray(x, y) =
myarray(x,y,2)

Is there a better method, or will I be forced to loop through and build
mynewarray one value at a time? The real problem is that in my larger loop
of code, myarray is dynamic and is updated frequently, and I'll have to pull
current copies of mynewarray fairly often, and that seems like a lot of
processing overhead. If there is a way to redim the array directly, that
would save me all kinds of time.

Thanks!

Keith


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Redimming (preserve) a 3D array

Since your data is already in the 3-D array, can't you just leave it there;
and when you need the data "in the middle", just fix the last index to 2,
and loop through the rest as you would if it were in the 2-D array? That
way, you won't have to move any data around and yet you can get to the
information you need.

Rick


"ker_01" wrote in message
...
This is a repost of an earlier question that didn't recieve responses (my
question may have been too obscure).

I have a 3D array which I'll call myarray(1 to 10, 1 to 100, 1 to 3)

I would like to reduce the number of parameters to turn it into a 2D array
which I'll call mynewarray(1 to 10, 1 to100) while keeping the data that
is already in the array.

Redim/preserve only allows you to mess with the last dimension (1 to 3),
which is fine- but from help:
"Similarly, when you use Preserve, you can change the size of the array
only by changing the upper bound; changing the lower bound causes an
error"

The data I'd like to preserve is in the middle, e.g. mynewarray(x, y) =
myarray(x,y,2)

Is there a better method, or will I be forced to loop through and build
mynewarray one value at a time? The real problem is that in my larger loop
of code, myarray is dynamic and is updated frequently, and I'll have to
pull current copies of mynewarray fairly often, and that seems like a lot
of processing overhead. If there is a way to redim the array directly,
that would save me all kinds of time.

Thanks!

Keith



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Redimming (preserve) a 3D array

Copying arrays element by element is pretty fast (Redim Preserve also uses
array copying under the covers, but possible more efficiently).
Depending on exactly what you want to do two alternative approaches might be
to

- change the sequence of the dimensions to (1 to 3, 1 to 10, 1 to 100) so
that the one you want to Redim Preserve is last
- use jagged arrays of variants
Jagged array method works something like this:

OPtion Base 1

Dim Var1 as variant
dim Var2 as variant
dim Var3 as variant

dim varJagged(3) as variant

Var1 = Range("A1:A10").Value
Var2 = Range("D10:D100").Value
Var3 = Range("F5:F250").Value

varJagged(1)=Var1
varJagged(2)=Var2
varJagged(3)=Var3

msgbox varJagged(2) (54,1)
Charles___________________________________________ _______The Excel
Calculation Sitehttp://www.decisionmodels.com"ker_01"
wrote in message
...
This is a repost of an earlier question that didn't recieve responses (my
question may have been too obscure).

I have a 3D array which I'll call myarray(1 to 10, 1 to 100, 1 to 3)

I would like to reduce the number of parameters to turn it into a 2D array
which I'll call mynewarray(1 to 10, 1 to100) while keeping the data that
is already in the array.

Redim/preserve only allows you to mess with the last dimension (1 to 3),
which is fine- but from help:
"Similarly, when you use Preserve, you can change the size of the array
only by changing the upper bound; changing the lower bound causes an
error"

The data I'd like to preserve is in the middle, e.g. mynewarray(x, y) =
myarray(x,y,2)

Is there a better method, or will I be forced to loop through and build
mynewarray one value at a time? The real problem is that in my larger loop
of code, myarray is dynamic and is updated frequently, and I'll have to
pull current copies of mynewarray fairly often, and that seems like a lot
of processing overhead. If there is a way to redim the array directly,
that would save me all kinds of time.

Thanks!

Keith




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Redimming (preserve) a 3D array

ker_01 wrote:
This is a repost of an earlier question that didn't recieve responses (my
question may have been too obscure).

I have a 3D array which I'll call myarray(1 to 10, 1 to 100, 1 to 3)

I would like to reduce the number of parameters to turn it into a 2D array
which I'll call mynewarray(1 to 10, 1 to100) while keeping the data that is
already in the array.

Redim/preserve only allows you to mess with the last dimension (1 to 3),
which is fine- but from help:
"Similarly, when you use Preserve, you can change the size of the array only
by changing the upper bound; changing the lower bound causes an error"

The data I'd like to preserve is in the middle, e.g. mynewarray(x, y) =
myarray(x,y,2)

Is there a better method, or will I be forced to loop through and build
mynewarray one value at a time? The real problem is that in my larger loop
of code, myarray is dynamic and is updated frequently, and I'll have to pull
current copies of mynewarray fairly often, and that seems like a lot of
processing overhead. If there is a way to redim the array directly, that
would save me all kinds of time.

Thanks!

Keith


I'm not sure I understand what you want to pare down to; nevertheless,
if the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook, you might
see whether the following gets you the

my2Darray=TwoD(my3Darray)

Alan Beban
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ReDim Preserve on 2D Array not working bony_tony Excel Programming 5 December 9th 07 03:21 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[_2_] Excel Programming 3 November 13th 07 04:08 PM
VBA syntax help: ReDim Preserve an array Dave Excel Discussion (Misc queries) 4 September 8th 07 07:37 PM
redim preserve the second dimension in a two-dim array Arnold Klapheck Excel Programming 4 September 19th 06 02:10 PM
Preserve settings Bampah Excel Discussion (Misc queries) 3 March 6th 06 04:58 PM


All times are GMT +1. The time now is 10:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"