In VB6, you could dimension an array with both a lower and upper bound. If
you used only an upper bound, then the lower bound was either 0 or 1
depending on the Option Base statement. In .Net, arrays always have a lower
bound of 0.
So a VB6 declaration of Dim strArray(100) could result in 100 or 101
elements depending on the option base setting.
In VB.Net, it was decided that instead of the dimension setting the number
of elements. it would be better for developers migrating from VB to keep the
dimension as the upper bound. So VB.Net would result in 101 elements.
The following is straight from the documentation:
Visual Basic .NET updates the declaration of array bounds to provide
interoperability with arrays in other programming languages.
Visual Basic 6.0
In Visual Basic 6.0, the default lower bound of every dimension of an array
is 0. You can change this to 1 with the Option Base statement. You can also
override the default lower bound in individual array declarations.
If you leave the default at 0, the number of elements in the array is equal
to the upper bound plus one. The following declaration reserves 21 elements
for the array Weight:
Dim Weight(20) As Single Visual Basic .NET
In Visual Basic .NET, the lower bound of every array dimension is 0, and you
cannot declare it to be otherwise. The Option Base statement is not
supported.
The number you specify for each dimension in the declaration is the upper
bound, and the initial element count is equal to the upper bound plus one.
The declaration in the preceding example reserves 21 elements for Weight,
with subscripts 0 through 20.
You can also specify a zero-length array, which does not contain any
elements, by declaring one of its upper bounds to be -1.
"User" <gu***@guest.com> wrote in message news:n9xOc.25$T_6.24@edtnps89...
Hi,
This is very basic, It may be a repost, if so I'm sorry.
The problem is that this declaration :
Private strMyArray(100) As String
will create an array of string with a length of 101, but the length
should be only of 100 (0 to 99).
Is there a setting in VB.NET to enable arrays to look like VB6's array ?
Thank you.