Changes to arrays between Visual Basic 6.0 and Visual Basic .NET

Array Bound Changes in Visual Basic
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.

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now