Export (0) Print
Expand All
Expand Minimize

Lower bound of array was changed to 0

Visual Studio .NET 2003

Previous versions of Visual Basic allowed you to set the lower bounds of an array to 1 using the Option Base statement, or to any valid number using the syntax MyArray(lowerbounds to upperbounds) where upperbounds and lowerbounds are numbers. Arrays in Visual Basic .NET are required to have lower bounds of 0.

During upgrade, the lower bounds of all arrays are changed to 0, as in the following example:

' Visual Basic 6.0
Dim x(1 To 10) As Integer
Dim z() As Integer
ReDim z(5 To 15) As Integer

' After upgrade to Visual Basic .NET
' UPGRADE_WARNING: Lower bound of array x was changed from 1 to 0.
Dim x(10) As Short
Dim z() As Short
' UPGRADE_WARNING: Lower bound of array z was changed from 5 to 0.
ReDim z(15)

What to do next

Review your code to see where and how the array is being used.

  • If the original array had a lower bound greater than 0, the elements of the array remain the same:
    ' Visual Basic 6.0
    Dim x(1 To 10) As Integer
    ' Assign a value to the first element.
    x(1) = 100
    
    ' After upgrade to Visual Basic .NET
    ' UPGRADE_WARNING: Lower bound of array x was changed from 1 to 0.
    Dim x(10) As Integer
    ' Assign a value to the first element (now the second element).
    x(1) = 100
    
  • If any code relies on the size of the array (for example, passing the array to an API function, writing to a file, or assigning to another array), it will be incorrect since the size of the array has changed:
    ' Visual Basic 6.0
    Dim x(10 To 15) As Integer
    Dim y As Integer
    y = UBound(x) - LBound(x)
    ' Returns 4.
    Debug.Print y
    
    ' After upgrade to Visual Basic .NET
    ' UPGRADE_WARNING: Lower bound of array x was changed from 10 to 0.
    Dim x(15) As Short
    Dim y As Short
    y = UBound(x) - LBound(x)
    ' Returns 15.
    System.Diagnostics.Debug.WriteLine(y)
    

See Also

Array Bound Changes in Visual Basic | Array Size Declaration Changes in Visual Basic

Show:
© 2014 Microsoft