Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default size of multidimensional dynamic array

Having created a dynamic, multidimensional array like so:

Dim gInfo() As String
ReDim gInfo(0 To 1, 0 To 1)

I understand that you can only change the size of the last dimension.
Once having created an array, though, how do you find the size of this
second dimension?

The following line would not compile ("expected Array"):

iSize = UBound(gInfo(1))

I expected gInfo(x) to return the xth array in this "array of arrays".
Is this not so in VBA? How then do you get the size of the second
dimension? Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default size of multidimensional dynamic array

Where is the code that made gInfo(1) an array? It isn't in your post,
and VBA also seems to think that gInfo is not an array. And in any
event, gInfo is declared as a 2-D array, so gInfo(1) doesn't refer to
anything, unlike gInfo(0,1) or gInfo(1,0) or gInfo(1,1).

If all the code being executed is
Dim gInfo() As String
ReDim gInfo(0 To 1, 0 To 1)
iSize = UBound(gInfo(1))

then gInfo is not an array of arrays, and you should change gInfo(1) to
gInfo,2.

Alan Beban

ThatFella wrote:
Having created a dynamic, multidimensional array like so:

Dim gInfo() As String
ReDim gInfo(0 To 1, 0 To 1)

I understand that you can only change the size of the last dimension.
Once having created an array, though, how do you find the size of this
second dimension?

The following line would not compile ("expected Array"):

iSize = UBound(gInfo(1))

I expected gInfo(x) to return the xth array in this "array of arrays".
Is this not so in VBA? How then do you get the size of the second
dimension? Thanks in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default size of multidimensional dynamic array

By the way, you should be more precise in your use of "size"; do you
mean the upper bound? Or the number of elements accommodated in that
"direction"? In your case, if gInfo has not been changed from its
original declaration, the upper bound of the "column" dimension is 1,
but the number of "columns" is 2.

Alan Beban

ThatFella wrote:
Having created a dynamic, multidimensional array like so:

Dim gInfo() As String
ReDim gInfo(0 To 1, 0 To 1)

I understand that you can only change the size of the last dimension.
Once having created an array, though, how do you find the size of this
second dimension?

The following line would not compile ("expected Array"):

iSize = UBound(gInfo(1))

I expected gInfo(x) to return the xth array in this "array of arrays".
Is this not so in VBA? How then do you get the size of the second
dimension? Thanks in advance.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default size of multidimensional dynamic array

-Originally posted by Alan Beban -

<snip

then gInfo is not an array of arrays, and you should change gInfo(1)
to
gInfo,2.

Alan Beban



Guess I haven't read the documentation of UBound recently.
UBound(gInfo, 2) is what I was looking for. Thanks!

In response to your comment about size, I didn't really care which way
it was taken; either answer would have sufficed, but I'll be more
precise next time. But since you bring it up, how DO you get actual
length of the array (not UBound)? Thanks.

--
ThatFella
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default size of multidimensional dynamic array

Typically,

for 1-dimensional arrays:
iSize=UBound(arr) - LBound(arr) + 1

for 2-dimensional arrays:
iSize = (UBound(arr, 1) - LBound(arr, 1) + 1) * _
(UBound(arr, 2) - LBound(arr, 2) + 1)

Alan Beban

ThatFella wrote:
-Originally posted by Alan Beban -

<snip

then gInfo is not an array of arrays, and you should change gInfo(1)
to
gInfo,2.

Alan Beban



Guess I haven't read the documentation of UBound recently.
UBound(gInfo, 2) is what I was looking for. Thanks!

In response to your comment about size, I didn't really care which way
it was taken; either answer would have sufficed, but I'll be more
precise next time. But since you bring it up, how DO you get actual
length of the array (not UBound)? Thanks.




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
copying dynamic size to ms powerpoint confused Excel Worksheet Functions 1 October 17th 05 11:48 AM
How to declare a dynamic array Peter Rooney Excel Discussion (Misc queries) 4 April 13th 05 01:25 PM
Declare Multidimensional Arrays Alan Beban[_3_] Excel Programming 3 August 21st 03 02:40 AM
Multidimensional Arrays - VBA Brent McIntyre Excel Programming 3 August 11th 03 09:01 AM
Multidimensional Arrays - VBA Brent McIntyre Excel Programming 14 August 8th 03 10:49 PM


All times are GMT +1. The time now is 02:18 PM.

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

About Us

"It's about Microsoft Excel"