This documentation is archived and is not being maintained.

Declaration type not supported

Visual Studio .NET 2003

Some variable declarations that were allowed in Visual Basic 6.0 are no longer allowed in Visual Basic .NET.

Arrays of fixed-length strings

In Visual Basic 6.0, you could declare an array of fixed-length strings as follows:

Dim x(10) As String * 10

Arrays of fixed-length strings are not supported in Visual Basic .NET.

What to do next

  • Modify the declaration to use variable length strings:
    Dim x(10) As String
  • If fixed-length strings are necessary, you can manage the length of strings before assigning them to the array using the Len function, Left function and the PadRight method:
    Public Function FixedLength10(ByVal S As String) As String
       Dim l As Long
       L = Len(s)
       If l > 10 Then
          FixedLength10 = Microsoft.VisualBasic.Left(s, 10)
       ElseIf l < 10 Then
          FixedLength10 = s.PadRight(10)
       End If
    End Function

Arrays with more than 32 dimensions

In Visual Basic 6.0, the maximum number of dimensions for an array was 60. In Visual Basic .NET, the maximum number of dimensions is 32.

What to do next

  • Rethink the design of your application. Arrays with large number of dimensions are very memory-intensive and are likely to produce an out-of-memory error on most computers.

Arrays with a negative upper bounds

In Visual Basic 6.0, arrays could be declared with negative upper bounds. For example, the declaration Dim MyArray(-15 To –10) was valid.

What to do next

  • In Visual Basic 6.0, change the bounds of arrays so that upper bounds are not negative and modify any code that uses the arrays prior to upgrading.

References to a Private Enum

In Visual Basic 6.0, it was possible to reference a Private Enum from a Public Enum within the same module. In Visual Basic .NET, this is no longer allowed.

What to do next

  • Change the Enum to Public, or use the actual value of the Private Enum instead.

Color constants in an Enum

In Visual Basic 6.0, it was possible to define enumerations for colors using the VB Color constants:

' Visual Basic 6.0
Enum MyColors
   Red = vbRed
End Enum

In Visual Basic .NET, colors are reference types in the System.Drawing namespace; color constants are unnecessary.

What to do next

  • Find any code that uses the Enum and replace it with code that sets the color using System.Drawing.Color:
    ' After upgrade to Visual Basic .NET
    Me.BackColor = MyColors.Red
    ' Modified code
    Me.BackColor = System.Drawing.Color.Red

See Also

Left Function | Len Function | String.PadRight Method | System.Drawing Namespace | Declaration changed from Constant to Variable