Generated Code
In the following section, will find the generated code (C# and VB.NET), important messages after upgrading your code (EWIs), and helpers information.
What does the VB6 AI Migrator generate? - C# and VB.NET Differences
There are some features that help to simulate VB6 behavior, making C# easier to use, but in some cases, VB.NET could be better. In this section, you will see a comparison of some features in C# and VB.NET.
Error Handling
It refers to the response and recovery procedures from error conditions present in a software application. The VB6 AI Migrator offers three options for error handling:
Leave On Error Statements (VB.NET Only)
"On Error GoTo" and "On Error Resume Next" statements will remain the same code in the VB.NET output code.
Most patterns will be upgraded to Try-Catch blocks. This option covers a huge amount of "On Error GoTo" patterns and very basic cases of "On Error Resume Next".
To Try-Catch With Lambdas (C# Only)
This feature covers the most common patterns of "On Error GoTo" and will generate special patterns to support most "On Error Resume Next" patterns.
Original VB6 Code:
Public Sub OnErrorGotoLabelMethod(arg As String)
On Error GoTo errHnd
Dim s As Integer
s = CInt(arg)
Foo s
Exit Sub
errHnd:
MsgBox "Invalid Argument"
End Sub
Public Sub OnErrorResumeNextMethod(arg As String)
On Error Resume Next
MsgBox arg
MsgBox CInt(arg)
MsgBox "This line will be executed allways"
If Err.Number <> 0 Then
'This code should be executed if there were any error(s)
MsgBox "OnErrorResumeNextMethod reached the last statement"
MsgBox "OnErrorResumeNextMethod reached the last statement"
MsgBox "OnErrorResumeNextMethod reached the last statement"
End If
End SubLeave On Error Statements (VB.NET Only)
Convert To Try-Catch
C# Code:
VB.NET Code:
To Try-Catch With Lambdas (C# Only)
Late Binding
This is a mechanism where the type is unknown until the variable is used during runtime; usually through the assignment. The VB6 AI Migrator offers three options for late binding:
Static code analysis + helper classes
This option will cause the late binding access cases that could not be resolved with a static code analysis to be managed at runtime by means of a helper class.
VB6 AI Migrator will use its static code analysis process to determine the correct type for each object and resolve the late binding access. Note: The VB6 AI Migrator solves most of these issues by using a static code analysis process to infer and determine the correct data type for each variable. However, there are some variables that take several values with inconsistent types and there is no way to infer a proper type. For these cases, manual changes are required to reach functional equivalence.
Static code analysis + dynamic variables
This option will cause the late binding access cases that could not be resolved with a static code analysis to be managed at runtime with dynamic variables.
Original VB6 Code:
Static code analysis + helper classes
C# Code:
VB.NET Code:
Static code analysis only
C# Code:
VB.NET Code:
Static code analysis + dynamic variables
C# Code:
VB.NET Code:
Go Sub
VB6 provides the ability to jump around in the code from one portion to another thru "labels" and create code that is not structured. By default Go Sub statements are not supported in .NET, but by turning on this option, the VB6 AI Migrator will apply the special pattern recognition mechanism to support the GoSub Statement.
This feature works only for C#. The user can enable or disable it.
Original VB6 Code:
C# Code:
VB.NET Code:
Getting information from the AssemblyInfo file
This feature refers to how the VB6 AI Migrator tool obtains the information contained in the AssemblyInfo file.
Original VB6 Code:
C# Code:
VB.NET Code:
Auto-Implemented Properties
They are used when no additional logic is required in the property accessors, making them more concise and readable.
This feature only works for C#. The user can enable or disable it.
Original VB6 Code:
C# Code:
VB.NET Code:
Case Sensitive
.NET Common Language Runtime is case-sensitive. VB.NET code relies on the runtime, which means it must be case-sensitive at runtime, like when it is looking up variables and methods. However, the VB.NET compiler and editor let you ignore that because they correct the case in your code, whereas C# does not, making VB.NET a case-insensitive language (there are exceptions, such as XML literals, and string comparisons).
EWIs
When upgrading a VB6 project to .NET, the VB6 AI Migrator upgrades most of the code and objects from VB6 to their equivalents in either C# or VB.NET. However, there might be some items that are not fully upgraded, requiring manual changes in order to compile, run and achieve functional equivalence. The VB6 AI Migrator helps with this process by inserting different Errors, Warnings, and Issues (EWI) information messages into the upgraded code as comments.
EWIs are a valuable part of VB6 to .NET upgrade efforts. They alert you to potential issues, and the upgraded code provides information about how to fix them. An EWI is placed on the line before the problem and it consists of three parts:
Example:
In the example above, an EWI is made up of:
Code Number.
A message describing the problem.
A link to the help topic.
Type
Description
Comment
Code that will cause a compilation error
Marks items that you need to fix before the upgraded code can run
Code partially upgraded, it requires some additional changes
Requires some manual intervention to avoid compilation and runtime errors
Behavior difference between VB6 and .NET. The code will compile and run, but it might have a difference at runtime
Most of the time code will work fine, but it should be reviewed as a precaution
Code was changed in a way that may confuse the developer
Normally will not require user intervention
Global Warning
EWI present on the Upgrade Report only, not to the source code
Upgrade Helpers
The VB6 AI Migrator is able to translate a large part of the VB6 code directly to simple C# statements, but some functionality is either too specific or too complex to allow a one-to-one conversion. In these cases, the VB6 AI Migrator uses helper classes that encapsulate complex commands into a single function call. These functions, if desired, are included in the generated code.
Upgrade Helper classes range from simple string manipulation functions to extensions of complex controls such as grids. The use of these classes allows the VB6 AI Migrator generated code to remain legible while maintaining functional equivalence with VB6.
Helpers integration
Helper Classes can be integrated into the migrated solution in three ways. This option can be selected in the Helpers Integration combo box in the Upgrade Options tab of the VB6 AI Migrator.

Option
Description
Source Code
The source code for the Helper Classes will be added directly to the solution in the UpgradeSupport folder.
Binary
Compiled .dll files for the Helper Classes will be referenced in the solution and will be placed in the UpgradeSupport folder.
NuGet
References to the Helper Classes will be made through NuGet. This option is available for certain .NET Platforms only:
.NET Framework 4.7.2
.NET Framework 4.8
.NET Core 3.1
.NET 5
.NET 6
Reflection Helper
The VB6 typing model allows late binding. This means variables may not have been declared with their actual type, but with a general type. E.g.: Control instead of Label, Form instead of Form1, or Variant instead of any other type.
Even when the variables are declared with a general type, the code can assume they contain an instance of a more specific type and access members from the latter. Neither the VB6 compiler nor the interpreter will raise an error if the actual type of the instance has the requested member.
On the other hand, .NET will give a compilation error whenever a member is not in the declared type of the variable.
VB6 AI Migrator solves most of these issues by using its typing mechanism. This module is able to identify and resolve most late binding cases and correct the declarations with their actual type before performing the conversion process. This mechanism allows solving the member access as well as many other typing-related upgrade issues.
However, some variables take several values with inconsistent types and there is no way to infer a proper type for them.
By selecting the Static code analysis + helper classes option in the Late Binding Resolution upgrade option, the VB6 AI Migrator generates ReflectionHelper calls for these last cases which were not solved by the typing mechanism.
The ReflectionHelper calls avoid .NET compilation errors and provide an equivalent behavior in many cases. However, it must be noted that not all the cases will behave in the same way since the upgrade process still lacks information about the actual type of the variable and its member during the application runtime. This is a simple example of the reflection helper usage:
Original VB6 Code:
Resulting C#.NET Code:
Printer Helper
The VB6 AI Migrator can handle the migration of the VB.Global.Printer class in two ways. The first is using Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.Printer class provided by Microsoft. This is handled inside a small helper class that manages the Printer object as a singleton and uses the methods provided within.
The second option is a helper class that handles printing using the .NET System.Drawing.Printing namespace. The code for this class is included when the Helpers Integration option is set to Source Code.
Original VB6 code:
C# code with PowerPacks:
C# code with native helper class:
Last updated
Was this helpful?