Issues

The following are some of the most common issues generated by the VB6 AI Migrator.

1002 - LSet cannot assign one type to another

Description

This occurs when a type is assigned to another, using the LSet Function, LSet Function copies all the source bytes from one type and then assigns then makes that the other type points to the copy. Currently, there is no way to determine the expected behavior for these cases.

Recommendations

  • You can manually assign all the values and pass them from a class to another. You could require byte functions, so please be sure of how the function passes the data from one type to another. For example, if you have a type that contains a string and the other has an array of strings of length 2, then you must make a function that splits and assigns the first array into two characters pieces, and then assign them to the second type array.

VB6 Original Code

Public Type TypeA
    x As Integer
End Type

Public Type TypeB
    x As Integer
End Type

Public Sub LSetTest()
    Dim aType As TypeA
    Dim bType As TypeB
    aType.x = 3
    LSet bType = aType
End Sub

C# Upgraded Code

VB.NET Upgraded Code

1010 - The preceding line couldn't be parsed

Description

Because of an unexpected error, VB6 AI Migrator could not parse a specific line, method, or code block.

Recommendations

  • This issue should be addressed manually by comparing the upgraded file with the original one and rewriting the missing code in the upgraded file.

1014 - 1% statement is not supported

Recommendations

  • We recommend using the Upgrade Option GoSub Conversion, this feature enables the support of GoSub statements by creating Local Functions (Only in C#). For more information check the latest MSDN documentation on Local functionsarrow-up-right.

  • Another way could be adding a method with the body of the label called by the GoSub manually. This will require passing all the necessary variables as byref parameters in the respective method.

VB6 Original Code

C# Upgraded Code

C# Expected Code

In this case, GoSub Conversion was selected, creating a local function.

VB.NET Upgraded Code

VB.NET Expected Code

As we mentioned before, the GoSub conversion is a feature available only in C#, which means we are not using this feature in this case.

1043 - Class instancing was changed to public

Description

In Visual Basic 6.0, instance creation was controlled by the instancing property of a class, which set both the access level (Public, Private, Friend) of a class and the way an object could be created. In Visual Basic .NET, the instancing property is no longer supported; you control how an object can be created by setting the access level of the constructor (Sub New):

Visual Basic 6.0 Instancing

Visual Basic .NET

Private

Class Access attribute: Private

PublicNotCreatable

Class Access attribute: Public. Declare the constructor Friend (Friend Sub New)

MultiUse

Class Access attribute: Public. Declare the constructor Public (Public Sub New)

There is no direct equivalent for SingleUse, GlobalSingleUse, or GlobalMultiUse instancing in Visual Basic .NET; when the instancing property is set to one of these values, the access level of both the class and the constructor is set to Public during the upgrade.

Recommendations

  • Check the code. The behavior may be slightly different than it was in Visual Basic 6.0, and you may need to change the access level of the class and/or the constructor.

1046 - %1 Parameter '%2' is not supported, and was removed

Description

The VB6 AI Migrator contains a set of methods and parameter mappings for VB6 and .NET. Included in this information are markers that indicate when parameters have been removed from their .NET counterparts. Whenever a parameter that has been removed is found in the original source code, this EWI is emitted by the VB6 AI Migrator. Currently, there is no way to determine expected behavior for these cases, the final solution will depend on the resolution approach.

Recommendations

  • There is no straightforward solution for this issue because some of the removed parameters may not have an equivalent in .NET at all. In some cases, the parameters change the behavior of the invoked method. The same effect might be possible by setting property values in the new .NET object. Likewise, an overload of the method might be available that provides this functionality. In other cases, there is no equivalent parameter to substitute, and it will be necessary to include code to replicate the desired functionality in .NET. Finally, in some cases, the omitted parameters cause no discernable difference. They can be safely omitted in most cases without affecting the functional equivalence. Common causes of this EWI involve the use of the Size, ColorDepth, X, and Y parameters of the LoadPicture function. It is also emitted in some uses of Interaction.AppActivate.

VB6 Original Code

C# Upgraded Code

VB.NET Upgraded Code

2038 - Form property 1%.ScaleMode is not supported

Description

In VB6, you could use a scale mode different from pixels to use as the unit for measures and locations in a form. This is not longer supported by .NET.

Recommendations

  • Use these functions to convert units to pixels, depending on the scale mode. The Unit can be centimeters, millimeters, inches, etc.

    • Microsoft.VisualBasic.Compatibility.VB6.Support.ToPixelsX(value, VB6.ScaleMode.Unit)

    • Microsoft.VisualBasic.Compatibility.VB6.Support.ToPixelsY(value, VB6.ScaleMode.Unit)

    • Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsToPixelsX(value)

    • Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsToPixelsY(value)

VB6 Original Code

C# Upgraded Code

VB.NET Upgraded Code

2064 - %1 %2 %3.%4 was not upgraded

Description

The VB6 AI Migrator converts members of a VB6 control library to their .NET equivalents whenever possible. The corresponding .NET elements are chosen to provide functional equivalence on the target platform.

In particular scenarios, some class properties may not have a direct equivalent in .NET or may have not be mapped in the current release of the VB6 AI Migrator. The VB6 AI Migrator generates this EWI to inform the user about these specific cases.

Also, some constants or static classes may not have a direct equivalent in the .NET core libraries or no mapping association exists in the specific version of the VB6 AI Migrator in use.

Since the Stub Generation upgrade option is normally enabled, the VB6 AI Migrator will create dummy declarations for these properties and reference them instead of the original reference to the not-supported property. This feature reduces the amount of compilation errors and provides the user with the possibility to manually implement the property's functionality in the stub declaration.

See also: Stubs Generation

Recommendations

  • The final solution will depend on the approach taken and the particulars of the application being migrated.

  • It will be necessary to implement the original property functionality through other means. This goal can be achieved through one of the following approaches:

    • Implement the functionality from scratch.

      • If the stub generation feature is enabled, it can be implemented in one place: the generated stub declaration.

      • If the stub generation feature is not used, it is necessary to change all references to the new .NET implementation.

    • Use an already existing method/property.

      • From .NET core libraries: Depending on what functionality is expected from a property, a particular VBUC user might be satisfied with a .NET equivalent, which, while not 100% equivalent, is sufficient for the specific case.

      • From third-party libraries: Some vendors might provide functionality previously available in VB6 and not in the .NET core libraries.

    • Refactor the code to use another method/property. This strategy makes sense when the underlying .NET object models are very different to the VB6 ones. In these cases, it is likely that a new approach will be the key.

VB6 Original Code

C# Upgraded Code

C# Expected Code

VB.NET Upgraded Code

VB.NET Expected Code

2068 - %1 %2 was not upgraded

Description

The VB6 AI Migrator is capable of mapping VB6 library members to .NET equivalents. These equivalents are chosen to provide maximum functional equivalence on the target platform.

Some class properties may not have a direct equivalent in specific scenarios because there is no equivalent in the .NET libraries or because no mapping association exists in VB6 AI Migrator.

Recommendations

  • There is no unique solution for this issue because some class properties may not have an equivalent in .NET at all.

  • The entire set of not-mapped elements requires the manual implementation of the missing member. The Stub Generation feature will assess the manual effort needed to reach functional equivalence by isolating all not-upgraded class properties in a single source file.

  • For more information please refer to Stub generation.

  • For these cases, we implement the PropertyBag and its methods in the VBRUN_PropertyBag class.

VB6 Original Code

C# Upgraded Code

C# Expected Code

VB.NET Upgraded Code

VB.NET Expected Code

2070 - Constant %1 was not upgraded

Description

Some constants may not have a direct equivalent in .NET or may not be mapped to a given equivalent in the current release of the VB6 AI Migrator.

Recommendations

  • There is no straightforward solution for this issue because some class properties may not have an equivalent in .NET at all.

  • The entire not-mapped set of elements requires the manual implementation of the missing member. The stub generation feature will assess the manual effort needed to reach functional equivalence by isolating all not-upgraded class properties in a single source file.

  • For more information, please refer to Stub generation.

  • Also, be sure to check the latest MSDN documentation on Windows Forms Controls for Visual Basic 6.0 Usersarrow-up-right.

VB6 Original Code

C# Upgraded Code

C# Expected Code

VB.NET Upgraded Code

VB.NET Expected Code

7003 - The Hdc should be released once it is used for safety

Description

This EWI is emitted when a handle to a device context is being used in Visual Basic 6.0 code. In the .Net environment, unmanaged handles like Hdc need to be released back to the GDI system. Failure to do so can result in general errors appearing in the application.

Recommendations

The first thing to consider is that .Net uses GDI+ instead of GDI for its graphics operations. GDI+ is generally easier to work with within the .Net framework and doesn't require calls to unmanaged code. However, GDI+ is a bit slower than regular GDI. So careful consideration must be paid to the performance of the application and the benefits of GDI+ vs GDI considered. In this case, two solutions will be given, one involving GDI and an alternative version using GDI+, and in the expected code it will be shown as follows:

  • Common code - Necessary changes to apply in both cases, we changed the signature of the DrawText method, so we'll have to update the call in the Paint event since we're now sending the Graphics object from PaintEventArgs as a parameter instead of the PictureBox.

  • GDI Solution - For this solution, we had to add a few more GDI methods, namely SetBkMode and SetTextColor. Additionally, CreateFontarrow-up-right and DeleteObject could also be added to the list if the font needs to be set. This is necessary because .NET handles drawing with GDI+, so if we want to change GDI's properties we'll have to do it through GDI calls. Also, the .Net PictureBox does not have Font properties we can set.

  • GDI+ Solution - In this case, we use the DrawString method of the System.Drawing.Graphics object.

Visual Basic 6.0 documentation

Additional information that might be helpful while handling this EWI.

VB6 Original Code

C# Upgraded Code

C# Expected Code

Common Code

GDI Solution

GDI+ Solution

VB.NET Upgraded Code

VB.NET Expected Code

Common Code

GDI Solution

GDI+ Solution

Last updated

Was this helpful?