From: Tom Shelton on
On 2009-10-11, xytsrm <xytsrm(a)discussions.microsoft.com> wrote:
> dpb,
>
> Are you trying to say that ReDim A(10) is actually creating 11 elements 0-15?
>
> X.
>

I'm sureyou ment 0 - 10 :) But, yes that is exactly what it does when Option
Base is set to 0 (the default). If you change to Option Base 1 then it would
create 10 elements 1 - 10.

When you declare an array you are giving the last index - not the number of
elements.

--
Tom Shelton
From: Bob Butler on

"xytsrm" <xytsrm(a)discussions.microsoft.com> wrote in message
news:AFDCD26D-6561-4D81-94BE-0266DB1A679E(a)microsoft.com...
> dpb your right!
>
> I didn't read the discription of ReDim correctly. I thought ReDim() was
> dimensioning an absolute number of elements - its actually dimensioning
> the
> subscript, so the actual number of elements is one more then the ReDim().

If "Option Base 0" is in effect and the specified upper bound is greater
than 0 and you don't specify the lower bound then yes (except calling it the
"subscript" or the "index" is more confusing than calling it the "upper
bound").

In general I find that always specifying both the lower and upper bounds of
the array in both Dim and ReDim statements makes the code clearer by
eliminating any question of the intent.


From: xytsrm on
Yes, when I read the discription more carefully I noticed the reference to
"subscript".

Also you can selectively dimension by ReDim(1 to n) to start a given array
from 1 regardless of the Option Base statement.

X.

"Tom Shelton" wrote:

> On 2009-10-11, xytsrm <xytsrm(a)discussions.microsoft.com> wrote:
> > dpb,
> >
> > Are you trying to say that ReDim A(10) is actually creating 11 elements 0-15?
> >
> > X.
> >
>
> I'm sureyou ment 0 - 10 :) But, yes that is exactly what it does when Option
> Base is set to 0 (the default). If you change to Option Base 1 then it would
> create 10 elements 1 - 10.
>
> When you declare an array you are giving the last index - not the number of
> elements.
>
> --
> Tom Shelton
>
From: Tom Shelton on
On 2009-10-11, xytsrm <xytsrm(a)discussions.microsoft.com> wrote:
> Yes, when I read the discription more carefully I noticed the reference to
> "subscript".
>
> Also you can selectively dimension by ReDim(1 to n) to start a given array
> from 1 regardless of the Option Base statement.
>

Right... And, when I was a VB.CLASSIC guy I used to be in the habbit of doing
just that - explicitly declaring both bounds (even though I almost never used
anything but 0). It just made things a bit more clear to me :)

--
Tom Shelton
From: xytsrm on
I absolutely agree with that. When is comes to code I like to be as explicit
as possible right at the point of the each line of code, so that when you
need to modify it in six months, a year or more, it easier to remember what
you were doing and why you did it.

X.


"Tom Shelton" wrote:

> On 2009-10-11, xytsrm <xytsrm(a)discussions.microsoft.com> wrote:
> > Yes, when I read the discription more carefully I noticed the reference to
> > "subscript".
> >
> > Also you can selectively dimension by ReDim(1 to n) to start a given array
> > from 1 regardless of the Option Base statement.
> >
>
> Right... And, when I was a VB.CLASSIC guy I used to be in the habbit of doing
> just that - explicitly declaring both bounds (even though I almost never used
> anything but 0). It just made things a bit more clear to me :)
>
> --
> Tom Shelton
>
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Prev: Array of pointers
Next: Will this object get destroyed?