Home All Groups Group Topic Archive Search About
Author
4 Apr 2005 12:57 AM
Bill
In vbscript and vb6 when you created a array via a join that contained no
entries when you did a ubound against that array it returned -1, which of
course was very helpful for using it as the upper bound in a for loop. In
vb.net, in the same situation the ubound will return 0 and you get an array
with 1 null entry. I am missing something here or does this seem totally
incompatible?

Author
4 Apr 2005 1:45 AM
Stephany Young
The documentation for both the String.Split and the
Microsoft.VisualBasic.Split methods explicitly state:

<quote>
Return Value
    An array consisting of a single element containing this instance,
    if this instance contains none of the characters in separator.
</quote>

This IS different behaviour from VB6, and, in my opinion, finally corrected
a design fault. In VB6, take the string "x,y,z,". Apply the Split function
to it - Split("x,y,z,", ","), and the result is an array with 4 elements
(the empty string after the final comma is the 4th element). To be
consistent, I believe that Split("", ",") should have returned an array with
1 element. Because Split("", ",") actually returned an array with no
elements, then to be consistent I believe that Split(("x,y,z,", ",") should
have returned an array with 3 elements.

This inconsistent behaviour has been corrected in VB.NET.


Show quoteHide quote
"Bill" <B***@discussions.microsoft.com> wrote in message
news:2132CF55-E6CF-4459-AA22-439FC2754519@microsoft.com...
> In vbscript and vb6 when you created a array via a join that contained no
> entries when you did a ubound against that array it returned -1, which of
> course was very helpful for using it as the upper bound in a for loop. In
> vb.net, in the same situation the ubound will return 0 and you get an
> array
> with 1 null entry. I am missing something here or does this seem totally
> incompatible?
Author
4 Apr 2005 7:09 AM
Cor Ligthert
Bill,

I agree with you that the array in VBNet has a very inconistent behaviour.

Confirm every other program language I know are "MyArray(10)" ten strings,
while it is in VBNet eleven strings. In my opinion is this ver confusing.  I
therefore understand that when you say.

string() = string.split("")

Would expect at least 1 string because that would be than confusing because
string(0) = 1 string.

It would in my opinion be an improvement when this strange behaviour is once
banned from VBNet and that than 10 elements are really 10 elements and not
11.

Just my thought,

Cor
Author
4 Apr 2005 7:35 AM
Stephany Young
The original post had nothing to do with how a an array is declared. it was
about how the results of the Split function differed between VB6 and VB.NET.
That has been explained.

When arrays were introduced to BASIC, long before VB was a twinkle in Bill
Gate's eyes, the bounds were 1 based. This means that Dim x(10) As Integer
was the same as Dim x(1 To 10) As Integer. In those days, Dim x(10) As
Integer did, in fact, mean 'an array of 10 elements with subscripts 1 to 10
inclusive.

At some point in time, along came the Option Base statement where you could
declare that subscripts for your arrays were going to be 1 based or 0 based.
You could Use Option Base 0 or Option Base 1 as it took you fancy. If you
ommitted the Option base statement then it defaulted to Option Base 1.

If you used Option Base 0, Dim x(10) As Integer gave you an array of 11
elements subscripted by 0 to 10 inclusive and Dim x(0 to 9) As Integer gave
you an array of 10 elements subscripted by 0 to 9 inclusive.

The only, x(10), or last, x(0 to 10), part of the bounds clause has always,
in BASIC, determined the the upper bound of the array, NOT the number of
elements. It is coincidence that prior to Option Base the upper bound was
guaranteed to be the same as the number of elements.

As long as one 'thinks' BASIC when one is using BASIC then it is not
confusing at all. How one declares arrays in other languages is irrelevant.


Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message
news:%23jf69UOOFHA.904@tk2msftngp13.phx.gbl...
> Bill,
>
> I agree with you that the array in VBNet has a very inconistent behaviour.
>
> Confirm every other program language I know are "MyArray(10)" ten strings,
> while it is in VBNet eleven strings. In my opinion is this ver confusing.
> I therefore understand that when you say.
>
> string() = string.split("")
>
> Would expect at least 1 string because that would be than confusing
> because string(0) = 1 string.
>
> It would in my opinion be an improvement when this strange behaviour is
> once banned from VBNet and that than 10 elements are really 10 elements
> and not 11.
>
> Just my thought,
>
> Cor
>
Author
4 Apr 2005 8:03 AM
Cor Ligthert
Stephany,

Thanks, mostly I write this message in this newsgroup. This time I thought
that because of your previous message I don't do that. I always write that
the idea of using the first as starting indexer is more natural. As far as I
know has my language (and I assume a lot of others) not even a distinct
between "null" and "zero". For both "nul" is used. Although we have the
words "null" and "nothing", resp. "nul" and "niets".

And than I write that I consequently use the zero as starting indexer.

Cor