Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default how to redim more than one dimension in a multidimensional dynamic array?

As I searched previous posts, I get the point that only the last
dimension can be redimed. I am wondering what if both dimensions are
need to be redimed? I have a 4 dimensional array, and each dimension
has a big upperbound. If I define all of them to be fixed expect for
the last dimension, it will result in many unnecessary loops. Any
suggestions?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to redim more than one dimension in a multidimensional dynamic array?

Only the last dimension can be redimensioned in a dynamic array if you want
to preserve

Redim preserve arr(1 to 20, 1 to 30)

the data.

--
Regards,
Tom Ogilvy

"lvcha.gouqizi" wrote in message
oups.com...
As I searched previous posts, I get the point that only the last
dimension can be redimed. I am wondering what if both dimensions are
need to be redimed? I have a 4 dimensional array, and each dimension
has a big upperbound. If I define all of them to be fixed expect for
the last dimension, it will result in many unnecessary loops. Any
suggestions?

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default how to redim more than one dimension in a multidimensional dynamic

Depending on what you are storing you might be able to replace the 4
dimensions with just one dimension and a user defined type. Then you can just
resize the one array and store 4 different variables for each item in the
array.

Type MyType
MyString as string
MyInteger as Integer
YourInteger as Integer
My Double as Double
end type

sub test()
dim MyStuff() as MyType

... 'redim preserve...
msgbox Mystuff(1).MyString

This might be a bit cryptic if you are not familiar with UDT's. If you need
more help just post back.
--
HTH...

Jim Thomlinson


"lvcha.gouqizi" wrote:

As I searched previous posts, I get the point that only the last
dimension can be redimed. I am wondering what if both dimensions are
need to be redimed? I have a 4 dimensional array, and each dimension
has a big upperbound. If I define all of them to be fixed expect for
the last dimension, it will result in many unnecessary loops. Any
suggestions?

Thanks.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default how to redim more than one dimension in a multidimensional dynamic array?

Only the last I am afraid. You need to start with the others as big as you
will ever need. Perhaps your loops could exit on an empty element, like this

For i = LBound(ary, 1) To UBound(ary, 1)
If IsEmpty(ary(i, 1)) Then
MsgBox i
Exit For
End If
Next i


--

HTH

RP
(remove nothere from the email address if mailing direct)


"lvcha.gouqizi" wrote in message
oups.com...
As I searched previous posts, I get the point that only the last
dimension can be redimed. I am wondering what if both dimensions are
need to be redimed? I have a 4 dimensional array, and each dimension
has a big upperbound. If I define all of them to be fixed expect for
the last dimension, it will result in many unnecessary loops. Any
suggestions?

Thanks.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default how to redim more than one dimension in a multidimensional dynamic array?

well, thanks. This is really a weak point of VB.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to redim more than one dimension in a multidimensional dynamic array?

Maybe you need to redefine you perspective.

Do your really need to redim both dimensions? If the real need is to add
rows, then reorient your array to

Arr(1 to num columns, 1 to numrows)

or
use an array of arrays.

--
Regards,
Tom Ogilvy


"lvcha.gouqizi" wrote in message
oups.com...
well, thanks. This is really a weak point of VB.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to redim more than one dimension in a multidimensional dynamic array?

You said you had a four dimensional array, but many people mistakenly call

arr(1 to 20,1 to 4)

as a four dimensional array. Also, it is hard to imagine any real use for a
4 dimensional array unless you are willing to do a lot of looping.

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
Maybe you need to redefine you perspective.

Do your really need to redim both dimensions? If the real need is to add
rows, then reorient your array to

Arr(1 to num columns, 1 to numrows)

or
use an array of arrays.

--
Regards,
Tom Ogilvy


"lvcha.gouqizi" wrote in message
oups.com...
well, thanks. This is really a weak point of VB.





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default how to redim more than one dimension in a multidimensional dynamic

thanks. Good idea!

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default how to redim more than one dimension in a multidimensional dyn

I have not done a multi-dimensional array in for ever. I can never keep my
looping straight enough to get back what I want. With UDT's it's easy...
Collections can also be very handy. They are more work to impliment but easy
to add and remove from.
--
HTH...

Jim Thomlinson


"lvcha.gouqizi" wrote:

thanks. Good idea!


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 Object array as parameter of Variant array Peter T Excel Programming 4 May 10th 05 02:11 PM
Using Application.match against one dimension of a multidimensional array? KR Excel Programming 1 January 24th 05 10:01 PM
ReDim, Preserve and Multidimensional arrays Andy Westlake[_2_] Excel Programming 3 October 19th 04 07:04 PM
Array transfer - 1 dimension v. 2 dimension JWolf[_2_] Excel Programming 2 June 29th 04 01:02 AM
size of multidimensional dynamic array ThatFella[_2_] Excel Programming 4 September 3rd 03 11:53 PM


All times are GMT +1. The time now is 10:26 AM.

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"