Code Conversion
This section provides some transformation that we apply so that some elements will be upgraded as you need it.
1. ActiveX
1.1. .NET Assemblies with COM Visible
This option will generate special attributes for the converted classes and their members in order to keep the resulting assemblies exposed through a COM interface.
General Description:
The VB6 AI Migrator converts Visual Basic 6 ActiveX binaries to .NET assemblies. By default, the resulting assemblies can be used only from managed code. This option should be selected to generate the .NET attributes required to expose these assemblies as COM Objects if it’s necessary to use them from non-managed code.
In addition to the “COMVisible” attribute on the class members, the resulting project is also marked as COM Visible.
Original VB6 code:
Code declared in an Activex EXE:
Code located in the main application that uses the Activex EXE:
C# code:
Code declared in an Activex EXE:
Code located in the main application that uses the Activex EXE:
VB.NET code:
Code declared in an Activex EXE:
Code located in the main application that uses the Activex EXE:
1.2. Out process and Application
This optional feature enables the conversion of ActiveX DLLs and EXEs (with global variables in a .bas module) via a helper class (ComponentClassHelper) that controls the instantiation of the generated classes.
General Description:
The VB6 AI Migrator converts Visual Basic 6 ActiveX EXEs to .NET EXE projects (out-of-process) and ActiveX DLLs to .NET assemblies (class library projects).
One of the main differences between Visual Basic 6 ActiveX binaries and .NET assemblies is how the components are instantiated and how their initialization determines its lifetime behavior.
When this feature is active, a helper class is used to replicate the following ActiveX instantiation types:
Private
PublicNotCreatable
SingleUse
GlobalSingleUse
MultiUse
GlobalMultiUse
Original VB6 code:
Code declared in an Activex EXE:
Code located in the main application that uses the Activex EXE:
C# code:
Code declared in an Activex EXE:
Code located in the main application that uses the Activex EXE:
VB.NET code:
Code declared in an Activex EXE:
Code located in the main application that uses the Activex EXE:
1.3. Standard .NET Assemblies
This optional feature converts the ActiveX DLLs and EXEs to .NET class libraries (DLLs).
General Description:
The VB6 AI Migrator converts Visual Basic 6 ActiveX EXEs and ActiveX DLLs to .NET class libraries (DLLs).
One of the main differences between Visual Basic 6 ActiveX binaries and .NET assemblies is how the components are instantiated and how their initialization determines its lifetime behavior.
With this option switched on, the code is converted to pure .NET code and the ActiveX instantiation models won’t be supported.
Original VB6 code:
Code declared in an Activex EXE:
Code located in the main application that uses the Activex EXE:
C# code:
Code declared in an Activex EXE:
Code located in the main application that uses the Activex EXE:
VB.NET code:
Code declared in an Activex EXE:
Code located in the main application that uses the Activex EXE:
2. Comment Out Dead Code
2.1. On
Private methods that are not referenced will be commented out.
Original VB6 code:
C# code:
VB.NET code:
2.1. Off
This feature will be turned off and no changes pertaining to this feature will be made.
Original VB6 code:
C# code:
VB.NET code:
3. Default Property Resolution
3.1. Static code analysis and helpers classes
By switching this feature on, the majority of default property cases that could not be resolved with a static code analysis are managed at runtime by the use of a helper class.
General Description:
The VB6 AI Migrator uses a powerful static code analyzer to determine the correct type for each object. By having the correct type for each object, the VB6 AI Migrator is able to determine its default property and expand this property in the converted code.
However, there are some cases where it’s not possible to determine the type of an object by using this technique. For these scenarios, the VB6 AI Migrator provides a helper class that is able to determine the type of these objects at runtime and get or set their default property.
In the following example, the variable ctl is used to iterate over a different type of controls. Each of these controls has different default properties, thus, during runtime, the default property of ctl will change. If this example is converted using this option, the helper class will determine the type of each use of the ctl variable at runtime and will get the appropriate default property for each instance.
Original VB6 code:
C# code:
VB.NET code:
3.2. Static code analysis only
By switching this feature on, the VB6 AI Migrator will use a powerful static code analysis process to determine the correct type for each object and expands its default property.
General Description:
The VB6 AI Migrator uses a static code analysis process to infer/determine the correct type for each object. By having the correct type of each object, the VB6 AI Migrator can determine the default property of the object and expand this property in the converted code.
However, there some cases where it is not possible to determine the type of an object by using a static code analysis. For these cases manual changes are required to achieve functional equivalence.
Original VB6 code:
C# code:
VB.NET code:
4. Error Handling
4.1. Leave on Error Statements (VB.NET Only)
By choosing this option the VB6 AI Migrator will generate .NET source code that employs the “On Error” statements just like the Visual Basic 6 code.
General Description:
The “On Error Go To” and “On Error Resume Next” error handling statements present in the Visual Basic 6 code will remain the same on the Visual Basic .NET output code. This feature removes the need for manual changes to bring the error handling statements to functional equivalence since it will be used the same in the upgraded code.
Original VB6 code:
VB.NET code:
4.2. Convert to Try-Catch
The most common occurrences of error handling patterns will be automatically upgraded to Try-Catch blocks using this feature. It covers a vast amount of On Error Goto patterns and very basic cases of On Error Resume Next.
General Description:
The VB6 AI Migrator analyzes the execution control of the Visual Basic 6 code detecting the “On Error GoTo” error handling patterns to generate .NET inherent Try-Catch blocks. When "On Error Resume Next" error handling patterns are found, they will be transformed to a basic Try-Catch block, which will have a different behavior. For the most common scenarios this transformation generates error-free pure .NET code out of the box. For more radical cases, the spaghetti-like error handling code found on Visual Basic 6 might require either some changes prior to the upgrade process or manual efforts once it is upgraded to .NET.
Original VB6 code:
C# code:
VB.NET code:
4.3. To Try-Catch with Lambdas (C# Only)
This feature covers the most common patterns of On Error Goto and, additionally, generates special patterns to support most On Error Resume Next patterns. These special patterns are based on the concept of lambda expressions.
General Description:
This option applies all the transformations present in the more basic “ErrorHandlingToTryCatch” feature and additionally supports most of the On Error Resume Next patterns by introducing a special pattern based on lambda expressions.
The “On Error Resume Next” functionality can be upgraded to .NET by using a combination of lambda expressions and Try catch blocks. This allows the resulting source code to behave like the legacy source code but on pure .NET technology. This feature can be used only for target Visual Studio solutions that support lambda expressions.
Original VB6 code:
C# code:
5. Form Load
5.1. FormLoad mechanism upgraded using a helper
These optional features apply special transformation rules to the form load and unload methods in order to provide different functionality over the .NET platform.
General Description:
Visual Basic 6 offered the “load” and “unload” methods to handle how the forms are loaded into memory and displayed. This functionality is not available by default in .NET and requires some extra considerations during the automated migration stage.
The VB6 AI Migrator is equipped with special transformation rules to port the Load and Unload methods and related functionality (show, hide and more) into .NET equivalent constructions by several means.
Original VB6 code:
C# code:
VB.NET code:
5.2. FormLoad event upgraded as a method invoked from form constructor
These optional features apply special transformation rules to the form load and unload methods in order to provide different functionality over the .NET platform.
General Description:
Visual Basic 6 offered the “load” and “unload” methods to handle how the forms are loaded into memory and displayed. This functionality is not available by default in .NET and requires some extra considerations during the automated migration stage.
The VB6 AI Migrator is equipped with special transformation rules to port the Load and Unload methods and related functionality (show, hide and more) into .NET equivalent constructions by several means.
Original VB6 code:
C# code:
VB.NET code:
5.3. FormLoad event upgraded to .NET native event
These optional features apply special transformation rules to the form load and unload methods in order to provide different functionality over the .NET platform.
General Description:
Visual Basic 6 offered the “load” and “unload” methods to handle how the forms are loaded into memory and displayed. This functionality is not available by default in .NET and requires some extra considerations during the automated migration stage.
The VB6 AI Migrator is equipped with special transformation rules to port the Load and Unload methods and related functionality (show, hide and more) into .NET equivalent constructions by several means.
Original VB6 code:
C# code:
VB.NET code:
6. Free COM Objects
6.1. Free COM Objects memory using helper
This option will cause the resulting code to use a helper class to free the COM objects' allocated memory in the same way as Visual Basic 6.0 does.
General Description:
Visual Basic 6.0 automatically releases the memory used by COM Objects. In .NET, there are some cases that require executing some functions in order to release the memory occupied by COM objects.
If this option is selected the VB6 AI Migrator will generate a call to a helper class in charge of releasing the memory used by COM Objects when a method is finished, a class is being destroyed or a COM reference is changing its value.
Original VB6 code:
C# code:
VB.NET code:
6.2. Free COM Objects memory manually
By using this option the VB6 AI Migrator will not generate special code to handle the COM Objects memory usage.
General Description:
Visual Basic 6.0 automatically releases the memory used by COM Objects. In .NET, there are some cases that require executing some functions in order to release the memory occupied by COM objects
If this option is selected, the VB6 AI Migrator will not generate any special code to release the memory used by COM Objects and manual changes might be required to make sure that all the references to the COM Objects are properly released.
Original VB6 code:
C# code:
VB.NET code:
7. Convert HelpFile and HelpContexID Feature
7.1 Do not Convert HelpFile and HelpContextID Feature
Choosing this option, the VB6 AI Migrator will not apply any special pattern or behavior. Help File and HelpContextID VB6 features statements are not supported by default in .NET structured code, so VB6 AI Migrator solve this feature with a stub.
Original VB6 code
C# code
VB.Net code
7.2 Convert HelpFile and HelpContextID Feature using Helper Class
Enable this feature provides a helper class to raise an information event for each control with HelpContextID property defined.
General Description
Visual Basic 6 has offered the possibility to use HelpContextID and a .chm file to display information about the current form and controls. That feature does not exist in .Net, so VB6 AI Migrator provides the opportunity to use a Helper class to have a relative behavior.
The Helper Class transforms the number of HelpContextID, assigning an event for each control with the property defined and checking if the .chm file exists.
Original VB6 Code
C# code:
VB.NET Code
8. Late Binding Resolution
8.1. 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.
General Description:
Visual Basic 6.0 provides the ability to use late-bound variable references. This means the variables may have not been declared with their actual type, but with a generic type. E.g. “control” instead of “label”, “form” instead of “form1” or “variant” instead of any other type. At runtime Visual Basic 6 determines the actual type of the variable and invokes the appropriate methods and/or members. On the other hand, .NET will throw a compilation error whenever a member is not in the declared type of the variable.
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 the VB6 AI Migrator provides a helper class that is able to determine the type of these objects at runtime and invoke or get the appropriate member.
This helper class reduces the amount of compilation errors in the resulting source code and provides an equivalent behavior in the most common scenarios. Nevertheless, not all the cases will achieve 100% functional equivalence since the upgrade process lacks information about object data type and its members during the application runtime.
Original VB6 code:
C# code:
VB.NET code:
8.2. Static code analysis only
By selecting this option, the VB6 AI Migrator will use its static code analysis process to determine the correct type for each object and resolve the late binding access.
General Description:
Visual Basic 6.0 provides the ability to use late-bound variable references. This means the variables may have not been declared with their actual type, but with a generic type. E.g. “control” instead of “label”, “form” instead of “form1” or “variant” instead of any other type. At runtime Visual Basic 6 determines the actual type of the variable and invokes the appropriate methods and/or members. On the other hand, .NET will throw a compilation error whenever a member is not in the declared type of the variable.
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.
Original VB6 code:
C# code:
VB.NET code:
8.3. 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.
General Description:
Visual Basic 6.0 provides the ability to use late-bound variable references. This means the variables may have not been declared with their actual type, but with a generic type. E.g. “control” instead of “label”, “form” instead of “form1” or “variant” instead of any other type. At runtime Visual Basic 6 determines the actual type of the variable and invokes the appropriate methods and/or members. On the other hand, .NET will throw a compilation error whenever a member is not in the declared type of the variable.
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 establish a proper non-generic type. For these cases the VB6 AI Migrator will add castings to dynamic to every member access that needs it, therefore allowing most of the cases to be resolved at runtime, as VB6 does.
With this feature, when C# is the target language, variables with generic types such as object, control, usercontrol will have their uses resolved at runtime; thus, providing more functional equivalence in the code. The dynamic type does not exist in VB.NET; however, we provide its counterpart, which is to have Option Strict Off and apply the function CType(myVar, object) to those member accesses, that allows late binding on object types.
This option is the alternative of resolving late-binding-access with Helper Classes (Reflection Helper). The use of the Reflection Helper adds a lot of verbosity to the migrated code and therefore we provide this option as well. However, there is functionality implemented in our helper class that cannot be accomplished with the use of dynamic variables. For example, we fix at runtime a lot of members of multiple common classes in VB6 to their equivalent in .NET. The VB6 AI Migrator user should be aware of such limitation when turning this feature on.
Original VB6 code:
C# code:
VB.NET code:
9. Line and Shape
9.1. Helper class
If this option is selected, the VB6 AI Migrator will upgrade all the “line” control references to the inherent .NET label control.
Class
Maps to
vb.line
System.Windows.Forms.Label
vb.shape
UpgradeHelpers.Gui.ShapeHelper
Original VB6 code:
C# code:
VB.NET code:
9.2. PowerPack and Helper class
By switching this optional feature on, the VB6 AI Migrator will convert the legacy “line” control to a .NET equivalent located under the Microsoft Visual Basic Power Packs library.
In order to use this functionality, the Visual Basic Power Packs must be installed on the machine. The latest Visual Basic Power Packs can be downloaded from here: http://msdn.microsoft.com/en-us/vbasic/bb735936
Class
Maps to
vb.line
Microsoft.VisualBasic.PowerPacks.LineShape
vb.shape
Microsoft.VisualBasic.PowerPacks.RectangleShape / Microsoft.VisualBasic.PowerPacks.OvalShape
Original VB6 code:
C# code:
VB.NET code:
10. String Functions
Conversion options for Strings Mid, left and right functions.
10.1. Helper class functions
This option enables the VB6 AI Migrator to convert the String related functions Mid, Left, and Right, located in the VBA.Strings library, to functions in a helper class.
Original VB6 code:
C# code:
VB.NET code:
10.2. Native .NET System.String class functions
This option enables the VB6 AI Migrator to convert the String related functions Mid, Left, and Right, located in the VBA.Strings library, to native .NET String class functions.
Original VB6 code:
C# code:
VB.NET code:
10.3. Support function in Microsoft.VisualBasic.Compatibility.VB6.Support namespace
Converts Mid, Left, and Right vba.Strings functions to support functions available in the Microsoft.VisualBasic.Compatibility.VB6.Support namespace.
Original VB6 code:
C# code:
VB.NET code:
11. Generate Skeletons
11.1. On
This feature will generate skeleton classes, which will contain empty methods. All code inside the methods will be removed.
Original VB6 code:
C# code:
VB.NET code:
11.2. Off
This feature will be turned off and no changes pertaining to this feature will be made.
Original VB6 code:
C# code:
VB.NET code:
12. Stubs Generation
12.1. Upgrade Stubs generation for non upgraded element
During the upgrade process, every non-updated element will include a comment in the resulting source code indicating that the expression/statement was not converted. The Upgrade Stubs Generation feature creates a dummy (stub) declaration for each kind of these elements.
The VB6 AI Migrator converts library elements to their equivalent when possible. When there is no equivalent, the default behavior was just to add a comment on the source code indicating the following expression/statement was not converted and requires manual correction. This might cause a number of compilation errors that might hide other issues that need to be resolved manually. The Stubs Generation feature creates dummy (stub) declarations for those elements that could not be mapped to .NET equivalents. It also changes all the references to the not-supported elements for references to the stub declarations. This technique does not resolve the whole issue since manual work will always be required to implement the functionality which is not present in .NET. However, it can save an important amount of time by achieving the following goals:
Making all the not supported elements to allow the project to compile, avoiding an important amount of compilation errors and helping to understand the required manual effort.
Encapsulate all the not-upgraded elements in a single location so a solution can be implemented for each not-supported element, instead of requiring changes for all its references throughout the code.
Original VB6 code:
C# code:
VB.NET code:
12.2. Upgrade Note indicating not updated element during upgrade process
During the upgrade process, every non-updated element will include a comment on the resulting source code indicating that the expression/statement was not converted.
Original VB6 code:
C# code:
VB.NET code:
13. Remove Unused Local Variables
13.1. On
Local variables that are not used inside of the method will be automatically removed.
Original VB6 code:
C# code:
VB.NET code:
13.2. Off
Local variables will not be removed, even if they are not used.
Original VB6 code:
C# code:
VB.NET code:
14. VBA Collection Conversion
14.1. To System.Collections native .NET classes
Converts the Collection type to general System.Collections classes such as Hashtable, ArrayList, StringCollection, and StringDictionary. The generated type depends on the way the collection is used and what is stored in it.
Class
Maps to
vba.Collection
System.Collections.Hashtable | System.Collections.ArrayList | System.Collections.Specialized.StringCollection | System.Collection.Specialized.StringDictionary
Original VB6 code:
C# code:
VB.NET code:
14.2. To System.Collections.Specialized.OrderedDictionary native .NET class
Converts the Collection type to System.Collections.Specialized.OrderedDictionary.
Class
Maps to
vba.Collection
System.Collections.Specialized.OrderedDictionary
Original VB6 code:
C# code:
VB.NET code:
15. Use TabControl Extension Class
Depending on other upgrade options such as MsComCtl mappings, the VB6 AI Migrator can generate code that uses the System.Windows.Forms.TabControl class to represent tab pages and their owner control.
The System.Windows.Forms.TabControl class provided by the .Net Framework does not provide support for HotKeys, like the MsComCtl.TabStrip or the TabDlg.SSTab. The VBUC provides a helper class called TabControlExtension that has this functionality, which inherits the TabControl class.
15.1 On
This is the default setting, and will replace uses of the TabControl class with the TabControlExtension class. The TabControlExtension works exactly like the TabControl, except that it has support for HotKeys. If the migration is set to use Helpers as code instead of Dlls, the code for this class will be available to view and modify if desired.

15.2 Off
By selecting this setting, the native TabControl class will be used. This option is best selected when the code needs to use as many native controls as possible.

16. Typer Conflict Resolution
The VB6 AI Migrator's Typer feature attempts to determine a primitive type for a Variant depending on how it is used in the code. For example, in the following code, the first Variant is used mostly as in integer, and in the second case, it's used as a string most of the time.
Original VB6 Code
16.1 On
This is the default setting. By turning this feature on, the VB6 AI Migrator's Typer will determine that the type of the first variable should be an integer, and the second should be a string.
C# Code
VB.NET Code
16.2 Off
By turning this feature off, these type conflicts will not be resolved by the typer, and the variables will be left as System.Object.
C# Code
VB.NET Code
Last updated
Was this helpful?