ERR_RUNTIME #2081

    1% has a new behavior.

    Description

    The Visual Basic Upgrade Companion converts VB6 library items (types and members) to .NET equivalents whenever possible.  For some VB6 elements there are .NET constructs that work in a very similar way but may differ in their behavior depending on how they are used. The VBUC generates the EWI 2081 for these scenarios.

    During the upgrade process, some class members can be mapped to .NET structures with minor behavior differences. If this EWI is displayed in a given project, the selected target structure will keep the functional equivalence of the resulting code but may end up having small differences in some cases that may require some manual fine tuning, such as methods that are called in a different order or text that is displayed in a different font.

    Recommendations

    • Evaluate whether the specific differences might be present on the specific code being upgraded.  Sometimes these potential differences won't affect the application depending on how the original VB6 element was used.
    • Apply some modification to the upgraded source code which references the conflictive elements so that the differences are resolved.
    • Implement a new element in .NET that doesn’t show the conflictive behavior differences.  This might be done from scratch or by taking advantage of the existing .NET elements by using extension or wrapping approaches.
    • If a different element will be used instead of the one being generated by VBUC, the Custom Mappings Featurecould be used to override the preexisting conversion.

    Sample VB6

    Public Sub DifferentBehavior()
        Dim x As String
        x = "string data type"
        MsgBox LenB(x)
    End Sub

    Target VB.NET

    Public Sub DifferentBehavior()
        Dim x As String = "string data type"
        'UPGRADE_WARNING: (2081) LenB has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
        MessageBox.Show(CStr(Encoding.Unicode.GetByteCount(x)), Application.ProductName)
    End Sub

    Expected VB.NET

    In .NET the functions LenB, MidB, AscB, LeftB, RightB, InstrB have no direct equivalent, and their behavior would not remain consistent with VB6. The LenB function is meant to operate on binary data stored in a string and it returns its length in bytes, that is how many bytes are required for the particular string. In .NET String provides a Length property, this should not be confused with LenB. Each character can vary in size from 2-4 bytes according to the Unicode specification, so simplistic solutions like multiplying Length * 2 will only work for ASCII characters. In this case, the code generated by VBUC is appropriate, since all strings in .NET are encoded in Unicode. So the generated code will give us the expected result.

    PublicSub DifferentBehavior()

    Dim x AsString = "string data type"

    MessageBox.Show(CStr(Encoding.Unicode.GetByteCount(x)), Application.ProductName)

    EndSub

    Target C#

    public voidDifferentBehavior()
    {
        string x = "string data type";
        //UPGRADE_WARNING: (2081) LenB has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
        MessageBox.Show(Encoding.Unicode.GetByteCount(x).ToString(), ApplicationProductName);
    }

    Expected C#

    In .NET the functions LenB, MidB, AscB, LeftB, RightB, InstrB have no direct equivalent, and their behavior would not remain consistent with VB6. The LenB function is meant to operate on binary data stored in a string and it returns its length in bytes, that is how many bytes are required for the particular string. In .NET String provides a Length property, this should not be confused with LenB. Each character can vary in size from 2-4 bytes according to the Unicode specification, so simplistic solutions like multiplying Length * 2 will only work for ASCII characters. In this case, the code generated by VBUC is appropriate, since all strings in .NET are encoded in Unicode. So the generated code will give us the expected result.

    publicvoid  DifferentBehavior()

    {

      string x = "string data type";

      MessageBox.Show(Encoding.Unicode.GetByteCount(x).ToString(), Application.ProductName);

    }


    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration