From: Dee Earley on
On 14/10/2009 22:37, Eduardo wrote:
> Jeff Johnson escribi�:
>> "Tom Shelton" <tom_shelton(a)comcastXXXXXXX.net> wrote in message
>> news:Oi$dt3oSKHA.4004(a)TK2MSFTNGP04.phx.gbl...
>>
>>>> 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 :)
>>
>> Me too. ALWAYS.
>
> What I usually do is to set just the upper bound and leave the lower
> bound in zero, but I use the array from 1 and ahead.
> I discard the first element.
>
> I always lose one element space, but I have other advantages:
> a) start counting with 1 (it's natural and easy)

I've got in the annoying habit of using 0, 1, 2 in real life.. :)

> b) an array with zero elements has different upper bound than an array
> with one element.

Yes, that's a given, regardless of your base value.
And yes, you can have a 0 element array (it's arkward to create though
depending on the data type)

> c) The array is always dimensioned.

Agreed
StringArray = Split("")
ByetArray = ""

Both these are dimensioned 0 based arrays with no elements.

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems
From: Karl E. Peterson on
Bill McCarthy wrote:
> "Jeff Johnson" <i.get(a)enough.spam> wrote ...
>> "Tom Shelton" <tom_shelton(a)comcastXXXXXXX.net> wrote ...
>>
>>> 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 :)
>>
>> Me too. ALWAYS.
>
> Ditto. I find it also helps people less familiar with VB, or those who swap
> back and forth between languages to remember the array is dimensioned by
> upper and lower bounds not count of elements.

Common ground! :-)

<AOL>
--
..NET: It's About Trust!
http://vfred.mvps.org


From: Scott M. on

"Eduardo" <mm(a)mm.com> wrote in message news:hb6e7s$9tq$1(a)aioe.org...
> Bill McCarthy escribi�:
>
>>> What I usually do is to set just the upper bound and leave the lower
>>> bound in zero, but I use the array from 1 and ahead.
>>> I discard the first element.
>>>
>>> I always lose one element space, but I have other advantages:
>>> a) start counting with 1 (it's natural and easy)
>>> b) an array with zero elements has different upper bound than an array
>>> with one element.
>>> c) The array is always dimensioned.
>>>
>>
>> The problem is for anyone else using your code, they are faced with
>> arrays with an unused element, yet they can't tell that if it is an
>> intrinsic type such as a numeric type, date or for that matter a string.
>> And if they do a For Each your habits stuff that up completely.
>
> I usually don't use variants. And I don't use For Each with arrays.
> But yes, I it could be a bit confusing to someone.

Not to mention the wasted space, not much, but some. In addition, even
though VB gives you the option to start counting wherever you like, there
are standards to consider. Most other environments and many other
programmers will start counting from zero, which could make your code be the
"odd man out".

-Scott


From: mayayana on
> What I usually do is to set just the upper bound and leave the lower
> bound in zero, but I use the array from 1 and ahead.
> I discard the first element.
>
I often do that too, especially in VBScript or
when passing the array around as a data
storage element. Sometimes that also provides
a way to store a number, so that A1(0) will return
the UBound.

(I figure that if anyone else is using my code,
as Bill M. complained about, then they'll just
have to make an efort to understand the code
they're using before they start pasting it into their
own project. :)


From: Eduardo on
Scott M. escribi�:

> Not to mention the wasted space, not much, but some. In addition, even
> though VB gives you the option to start counting wherever you like, there
> are standards to consider. Most other environments and many other
> programmers will start counting from zero, which could make your code be the
> "odd man out".

The advantages for me are far more than the drawbacks.
And I don't do this when the memory usage could be critical (a rare
situation, because generally they are small arrays of longs or string
that are quickly cleared after the operation).

I'm not programming low level routines for Windows's core, I want to do
it it clear (for me), fast, and easy.

I think that to deal with dimensioned/not dimensioned arrays is too much
complication that I easily avoid wasting the first element.

BTW, for the language designers I would suggest: I think that arrays
should start in 1 and not in 0 (I think I recall that McKinney wrote
that in his book, but I'm not sure), and that arrays declared

Dim mMyArray () as Whatever

I mean, not explicitely dimensioned, should be dimensioned automatically
when you try to write an element.

Dim mMyArray () as String

mMyArray(2) "B"
mMyArray(5) "E"

DebugPrint Ubound(mMyArray) ' Prints 5

And when it has no element Ubound should return 0.

The programming life would be simpler.
For the time being, I do what I said.
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?