PC Review


Reply
Thread Tools Rate Thread

Array Dimensioning

 
 
BillCPA
Guest
Posts: n/a
 
      1st Apr 2009
Is there a limit on how many dimensions an array can have? VB Help seems to
indicate it is only limited by memory (I have a 4GB machine), and even then
actually has no limit because data is written to and read from disc as needed.

I cannot get an array of larger than four dimensions to work (I want seven).
I have it defined as dynamic. The code will initially ReDim the array
without showing any error. It will allow me to assign values to it. But if
I am monitoring the code and look at the array after a value has been
assigned, it indicates 'subscript out of range', even though the index values
for each dimension are well within the values at the time of the ReDim.

I reduced the number of dimensions down by one from 7, and when I got to
four, it worked.

Any thoughts?

--
Bill @ UAMS
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      2nd Apr 2009
Dim arrBill() as Long
ReDim arrBill(1 to 100, 1 to 7)

The above is a two dimensional array.
What is the structure of your 7 dimensional array?
How are you accessing the elements?
--
Jim Cone
Portland, Oregon USA



"BillCPA" <Bill @ UAMS>
wrote in message
Is there a limit on how many dimensions an array can have? VB Help seems to
indicate it is only limited by memory (I have a 4GB machine), and even then
actually has no limit because data is written to and read from disc as needed.

I cannot get an array of larger than four dimensions to work (I want seven).
I have it defined as dynamic. The code will initially ReDim the array
without showing any error. It will allow me to assign values to it. But if
I am monitoring the code and look at the array after a value has been
assigned, it indicates 'subscript out of range', even though the index values
for each dimension are well within the values at the time of the ReDim.

I reduced the number of dimensions down by one from 7, and when I got to
four, it worked.

Any thoughts?

--
Bill @ UAMS
 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      2nd Apr 2009
The Subscript out of Range message refers to a file, worksheet or named
object that VBA cannot find to execute a command on. I am not sure it is
relevant to the size of the array.


"BillCPA" <Bill @ UAMS> wrote in message
news:320665CB-F7A6-4718-A6FD-(E-Mail Removed)...
> Is there a limit on how many dimensions an array can have? VB Help seems
> to
> indicate it is only limited by memory (I have a 4GB machine), and even
> then
> actually has no limit because data is written to and read from disc as
> needed.
>
> I cannot get an array of larger than four dimensions to work (I want
> seven).
> I have it defined as dynamic. The code will initially ReDim the array
> without showing any error. It will allow me to assign values to it. But
> if
> I am monitoring the code and look at the array after a value has been
> assigned, it indicates 'subscript out of range', even though the index
> values
> for each dimension are well within the values at the time of the ReDim.
>
> I reduced the number of dimensions down by one from 7, and when I got to
> four, it worked.
>
> Any thoughts?
>
> --
> Bill @ UAMS



 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      2nd Apr 2009
On Wed, 1 Apr 2009 15:30:01 -0700, BillCPA <Bill @ UAMS> wrote:

>Is there a limit on how many dimensions an array can have? VB Help seems to
>indicate it is only limited by memory (I have a 4GB machine), and even then
>actually has no limit because data is written to and read from disc as needed.
>
>I cannot get an array of larger than four dimensions to work (I want seven).
> I have it defined as dynamic. The code will initially ReDim the array
>without showing any error. It will allow me to assign values to it. But if
>I am monitoring the code and look at the array after a value has been
>assigned, it indicates 'subscript out of range', even though the index values
>for each dimension are well within the values at the time of the ReDim.
>
>I reduced the number of dimensions down by one from 7, and when I got to
>four, it worked.
>
>Any thoughts?


Not enough data.

For a simple array, I seem to have no problem setting up one with 10
dimensions:

===============
Sub foo()
Dim arr(2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
End Sub
===============
--ron
 
Reply With Quote
 
BillCPA
Guest
Posts: n/a
 
      2nd Apr 2009
Public arrFile() as String

ReDim arrFile(Var0, Var1, Var2, Var3, Var4, Var5, Var6) - variables may be
up to 500

arrFile(Var0, Var1, Var2, Var3, Var4, Var5, Var6) = datastring

--
Bill @ UAMS


"Jim Cone" wrote:

> Dim arrBill() as Long
> ReDim arrBill(1 to 100, 1 to 7)
>
> The above is a two dimensional array.
> What is the structure of your 7 dimensional array?
> How are you accessing the elements?
> --
> Jim Cone
> Portland, Oregon USA
>
>
>
> "BillCPA" <Bill @ UAMS>
> wrote in message
> Is there a limit on how many dimensions an array can have? VB Help seems to
> indicate it is only limited by memory (I have a 4GB machine), and even then
> actually has no limit because data is written to and read from disc as needed.
>
> I cannot get an array of larger than four dimensions to work (I want seven).
> I have it defined as dynamic. The code will initially ReDim the array
> without showing any error. It will allow me to assign values to it. But if
> I am monitoring the code and look at the array after a value has been
> assigned, it indicates 'subscript out of range', even though the index values
> for each dimension are well within the values at the time of the ReDim.
>
> I reduced the number of dimensions down by one from 7, and when I got to
> four, it worked.
>
> Any thoughts?
>
> --
> Bill @ UAMS
>

 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      2nd Apr 2009

Array element numbering starts at zero unless you specify otherwise.
So declaring arrFile(100) is the same as arrFile(0 to 99) and that means
there is no element 100.
Declare your array like this...
ReDim arrFile(1 to Var0, 1 to Var1, 1 to Var2...)
--
Jim Cone
Portland, Oregon USA




"BillCPA" <Bill @ UAMS>
wrote in message
Public arrFile() as String
ReDim arrFile(Var0, Var1, Var2, Var3, Var4, Var5, Var6) - variables may be
up to 500

arrFile(Var0, Var1, Var2, Var3, Var4, Var5, Var6) = datastring
--
Bill @ UAMS



"Jim Cone" wrote:
> Dim arrBill() as Long
> ReDim arrBill(1 to 100, 1 to 7)
>
> The above is a two dimensional array.
> What is the structure of your 7 dimensional array?
> How are you accessing the elements?
> --
> Jim Cone
> Portland, Oregon USA




> "BillCPA" <Bill @ UAMS>
> wrote in message
> Is there a limit on how many dimensions an array can have? VB Help seems to
> indicate it is only limited by memory (I have a 4GB machine), and even then
> actually has no limit because data is written to and read from disc as needed.
>
> I cannot get an array of larger than four dimensions to work (I want seven).
> I have it defined as dynamic. The code will initially ReDim the array
> without showing any error. It will allow me to assign values to it. But if
> I am monitoring the code and look at the array after a value has been
> assigned, it indicates 'subscript out of range', even though the index values
> for each dimension are well within the values at the time of the ReDim.
>
> I reduced the number of dimensions down by one from 7, and when I got to
> four, it worked.
>
> Any thoughts?
>
> --
> Bill @ UAMS
>

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      2nd Apr 2009
Bill

It seems you just need a single dimension array Dim arrTemp(500) OR if you
are not sure of the number of elements you need to store use the Preserve
statement while redimensioning. In the below code n can be any number

Dim arrTemp() as Variant
ReDim arrTemp(0)

'Try replacing n with 500 or 65000
For lngTemp = 1 to n
ReDim Preserve arrTemp(lngTemp)
arrTemp(lngTemp) = Range("A" & lngTemp)
Next lngTemp


If this post helps click Yes
---------------
Jacob Skaria


"BillCPA" wrote:

> Is there a limit on how many dimensions an array can have? VB Help seems to
> indicate it is only limited by memory (I have a 4GB machine), and even then
> actually has no limit because data is written to and read from disc as needed.
>
> I cannot get an array of larger than four dimensions to work (I want seven).
> I have it defined as dynamic. The code will initially ReDim the array
> without showing any error. It will allow me to assign values to it. But if
> I am monitoring the code and look at the array after a value has been
> assigned, it indicates 'subscript out of range', even though the index values
> for each dimension are well within the values at the time of the ReDim.
>
> I reduced the number of dimensions down by one from 7, and when I got to
> four, it worked.
>
> Any thoughts?
>
> --
> Bill @ UAMS

 
Reply With Quote
 
BillCPA
Guest
Posts: n/a
 
      2nd Apr 2009
Actually, I use the zero level of each element, so I want them to be 0 to nn.

Here is the pertinent code:

Public arrFile() As String - this is in Module 1
Public FldrNo0 As Integer - this is in Module 1; FldrNo1-6 are the same as 0

The following ReDim statement is in Module 3:
ReDim arrFile(FldrNo0, FldrNo1, FldrNo2, FldrNo3, FldrNo4, FldrNo5, (FldrNo6
+ 10))
(The array is not a passed parameter, and there is no other ReDim before
this.)

Currently, when the code gets to the ReDim, these are the values of FldrNon:
FldrNo0=30; FldrNo1=19; FldrNo2=51; FldrNo3=70;
FldrNo4=83; FldrNo5=168; FldrNo6=202

If I stop the run immediately after the ReDim statement, and check the
UBound of any of the elements, it shows 'Subscript out of Range'.

If I continue running until I populate the array, it executes the statement
(see below) that places a value into the array without giving any error, but
if I check the value in the array immediately after that statement, it shows
'Subscript out of Range'.

arrFile(FldrNo0, FldrNo1, FldrNo2, FldrNo3, FldrNo4, FldrNo5, FldrNo6) =
f0.Name

As I mentioned, it does exactly the same with 6 and 5 dimensions, but when I
get to 4 dimensions, it works fine.

Extremely frustrating.

--
Bill @ UAMS


"Jim Cone" wrote:

>
> Array element numbering starts at zero unless you specify otherwise.
> So declaring arrFile(100) is the same as arrFile(0 to 99) and that means
> there is no element 100.
> Declare your array like this...
> ReDim arrFile(1 to Var0, 1 to Var1, 1 to Var2...)
> --
> Jim Cone
> Portland, Oregon USA
>
>
>
>
> "BillCPA" <Bill @ UAMS>
> wrote in message
> Public arrFile() as String
> ReDim arrFile(Var0, Var1, Var2, Var3, Var4, Var5, Var6) - variables may be
> up to 500
>
> arrFile(Var0, Var1, Var2, Var3, Var4, Var5, Var6) = datastring
> --
> Bill @ UAMS
>
>
>
> "Jim Cone" wrote:
> > Dim arrBill() as Long
> > ReDim arrBill(1 to 100, 1 to 7)
> >
> > The above is a two dimensional array.
> > What is the structure of your 7 dimensional array?
> > How are you accessing the elements?
> > --
> > Jim Cone
> > Portland, Oregon USA

>
>
>
> > "BillCPA" <Bill @ UAMS>
> > wrote in message
> > Is there a limit on how many dimensions an array can have? VB Help seems to
> > indicate it is only limited by memory (I have a 4GB machine), and even then
> > actually has no limit because data is written to and read from disc as needed.
> >
> > I cannot get an array of larger than four dimensions to work (I want seven).
> > I have it defined as dynamic. The code will initially ReDim the array
> > without showing any error. It will allow me to assign values to it. But if
> > I am monitoring the code and look at the array after a value has been
> > assigned, it indicates 'subscript out of range', even though the index values
> > for each dimension are well within the values at the time of the ReDim.
> >
> > I reduced the number of dimensions down by one from 7, and when I got to
> > four, it worked.
> >
> > Any thoughts?
> >
> > --
> > Bill @ UAMS
> >

>

 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      2nd Apr 2009
Please excuse my previous response.
Maybe I should get enough sleep before responding to questions.
If no lower bound is declared in an array then the lower bound is zero...
ReDim MyArr(100) is the same as ReDim MyArr(0 to 100)

I believe with seven dimensions in the array that you are having memory
problems. Arrays eat memory and multi-dimensional arrays are hungry.
You need to rethink your approach. In almost all cases, a two-dimensional
array should suffice... ReDim (0 to 30, 0 to 202)
--
Jim Cone
Portland, Oregon USA



"BillCPA" <Bill @ UAMS>
wrote in message
Actually, I use the zero level of each element, so I want them to be 0 to nn.
Here is the pertinent code:

Public arrFile() As String - this is in Module 1
Public FldrNo0 As Integer - this is in Module 1; FldrNo1-6 are the same as 0

The following ReDim statement is in Module 3:
ReDim arrFile(FldrNo0, FldrNo1, FldrNo2, FldrNo3, FldrNo4, FldrNo5, (FldrNo6
+ 10))
(The array is not a passed parameter, and there is no other ReDim before
this.)

Currently, when the code gets to the ReDim, these are the values of FldrNon:
FldrNo0=30; FldrNo1=19; FldrNo2=51; FldrNo3=70;
FldrNo4=83; FldrNo5=168; FldrNo6=202

If I stop the run immediately after the ReDim statement, and check the
UBound of any of the elements, it shows 'Subscript out of Range'.
If I continue running until I populate the array, it executes the statement
(see below) that places a value into the array without giving any error, but
if I check the value in the array immediately after that statement, it shows
'Subscript out of Range'.

arrFile(FldrNo0, FldrNo1, FldrNo2, FldrNo3, FldrNo4, FldrNo5, FldrNo6) =
f0.Name

As I mentioned, it does exactly the same with 6 and 5 dimensions, but when I
get to 4 dimensions, it works fine.
Extremely frustrating.
--
Bill @ UAMS
 
Reply With Quote
 
BillCPA
Guest
Posts: n/a
 
      3rd Apr 2009
I think you are probably right - it must be the memory, altho the way I read
the Help info, memory shouldn't be a problem - if it writes and reads to disc
when memory gets full.

I have already gone to one dimensional - I will just write everything as one
big string and separate it later. I would have done that quicker, but wanted
to see if anyone had any ideas on the multi-dimensional arrays.

I appreciate the input - look forward to next time.

--
Bill @ UAMS


"Jim Cone" wrote:

> Please excuse my previous response.
> Maybe I should get enough sleep before responding to questions.
> If no lower bound is declared in an array then the lower bound is zero...
> ReDim MyArr(100) is the same as ReDim MyArr(0 to 100)
>
> I believe with seven dimensions in the array that you are having memory
> problems. Arrays eat memory and multi-dimensional arrays are hungry.
> You need to rethink your approach. In almost all cases, a two-dimensional
> array should suffice... ReDim (0 to 30, 0 to 202)
> --
> Jim Cone
> Portland, Oregon USA
>
>
>
> "BillCPA" <Bill @ UAMS>
> wrote in message
> Actually, I use the zero level of each element, so I want them to be 0 to nn.
> Here is the pertinent code:
>
> Public arrFile() As String - this is in Module 1
> Public FldrNo0 As Integer - this is in Module 1; FldrNo1-6 are the same as 0
>
> The following ReDim statement is in Module 3:
> ReDim arrFile(FldrNo0, FldrNo1, FldrNo2, FldrNo3, FldrNo4, FldrNo5, (FldrNo6
> + 10))
> (The array is not a passed parameter, and there is no other ReDim before
> this.)
>
> Currently, when the code gets to the ReDim, these are the values of FldrNon:
> FldrNo0=30; FldrNo1=19; FldrNo2=51; FldrNo3=70;
> FldrNo4=83; FldrNo5=168; FldrNo6=202
>
> If I stop the run immediately after the ReDim statement, and check the
> UBound of any of the elements, it shows 'Subscript out of Range'.
> If I continue running until I populate the array, it executes the statement
> (see below) that places a value into the array without giving any error, but
> if I check the value in the array immediately after that statement, it shows
> 'Subscript out of Range'.
>
> arrFile(FldrNo0, FldrNo1, FldrNo2, FldrNo3, FldrNo4, FldrNo5, FldrNo6) =
> f0.Name
>
> As I mentioned, it does exactly the same with 6 and 5 dimensions, but when I
> get to 4 dimensions, it works fine.
> Extremely frustrating.
> --
> Bill @ UAMS
>

 
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
array dimensioning LesHurley Microsoft Excel Programming 11 16th Apr 2009 03:56 PM
Excel VBA Compile Error when dimensioning jagged array EngPhys_Bate Microsoft Excel Programming 2 22nd Aug 2007 03:28 AM
dimensioning variables Carla101 Microsoft Excel Programming 8 11th Jan 2006 11:25 AM
dimensioning across modules =?Utf-8?B?UGFwYSBKb25haA==?= Microsoft Excel Programming 1 16th Feb 2005 09:40 PM
Dimensioning Arrays Peter M Microsoft Excel Programming 2 13th Dec 2003 06:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 PM.