Previous | Index | Next 

[PRB] VB.NET doesn’t support implicit conversions in Const statements

VB6 supports implicit conversions between numbers and string values inside Const statements, whereas VB.NET doesn’t. For example, this code is legal in VB6 but causes a compilation error in VB.NET:

        Const ONE As String = "1"
        Const TWO As Integer = ONE * 2

The current version of VB Migration Partner can’t solve this problem, even though a future version might generate code that works around this issue. In the meantime, the simpler solution to this (admittedly rare) problem is removing the offending statement, either by editing the original VB6 code or by adding a ParseReplace pragma:

        Const ONE As String = "1"
        '## ParseReplace Const TWO As Integer = 1 * 2
        Const TWO As Integer = ONE * 2

 

Previous | Index | Next