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.
This feature enables the resulting .NET components to be called from other non-managed components or applications via COM.
General Description:
The VBUC 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.
Code located in the main application that uses the Activex EXE:
Private m_Customer1 As ExeBillingObjects.CustomerPrivate m_Customer2 As ExeBillingObjects.CustomerPrivate Sub Form_Load() Set m_Customer1 =NewExeBillingObjects.Customer Set m_Customer2 =NewExeBillingObjects.CustomerEnd SubPrivate Sub cmdGet_Click() txtTheNumber.Text = m_Customer1.TheNumberEnd Sub
<ComVisible(True)> _<ProgId("ExeBillingObjects.Customer")> _<ClassInterface(ClassInterfaceType.AutoDual)> _PublicClassCustomer Public Property TheNumber() As Integer Get Return g_TheNumber End Get Set(ByVal Value As Integer) g_TheNumber = Value End Set End PropertyEnd Class
Code located in the main application that uses the Activex EXE:
Private m_Customer1 As ExeBillingObjects.CustomerPrivate m_Customer2 As ExeBillingObjects.CustomerPrivate Sub cmdGet_Click(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles cmdGet.Click txtTheNumber.Text =CStr(m_Customer1.TheNumber)End SubPrivate Sub Form1_Load(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles MyBase.Load m_Customer1 =NewExeBillingObjects.Customer() m_Customer2 =NewExeBillingObjects.Customer()End Sub
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.
ActiveX EXEs are converted to out-of-process .NET EXEs.
ActiveX DLLs are converted to .NET class libraries using application domains.
Component instantiation is performed using helper classes. With this approach most of the ActiveX functionality is replicated in the converted code.
General Description:
The VBUC 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:
Code located in the main application that uses the Activex EXE:
Private m_Customer1 As ExeBillingObjects.CustomerPrivate m_Customer2 As ExeBillingObjects.CustomerPrivate Sub Form_Load() Set m_Customer1 =NewExeBillingObjects.Customer Set m_Customer2 =NewExeBillingObjects.CustomerEnd SubPrivate Sub cmdGet_Click() txtTheNumber.Text = m_Customer1.TheNumberEnd Sub
Module Module1Public myVar AsString=""Public Sub InitGlobalVars() myVar ="" End SubEnd Module
Customer.vb
PublicClassCustomer Inherits UpgradeHelpers.Activex.ComponentClassHelper Public Property TheNumber() As Integer Get Return g_TheNumber End Get Set(ByVal Value As Integer) g_TheNumber = Value End Set End PropertyEnd Class
Code located in the main application that uses the Activex EXE:
Private m_Customer1 As ExeBillingObjects.CustomerPrivate m_Customer2 As ExeBillingObjects.CustomerPrivate Sub cmdGet_Click(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles cmdGet.Click txtTheNumber.Text =CStr(m_Customer1.TheNumber)End SubPrivate Sub Form1_Load(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles MyBase.Load m_Customer1 = ExeBillingObjects.ExeBillingObjectsFactory.Create(Of ExeBillingObjects.Customer)(m_Customer1) m_Customer2 = ExeBillingObjects.ExeBillingObjectsFactory.Create(Of ExeBillingObjects.Customer)(m_Customer2)End Sub
1.3. Standard .NET Assemblies
This optional feature converts the ActiveX DLLs and EXEs to .NET class libraries (DLLs).
All ActiveX binaries are converted to native .NET assemblies (class libraries).
With this approach, the converted code can be used only from managed code and the different ActiveX instantiation models (e.g MultiUse, GlobalMultiuse, etc) won’t be supported.
General Description:
The VBUC 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.
Code located in the main application that uses the Activex EXE:
Private m_Customer1 As ExeBillingObjects.CustomerPrivate m_Customer2 As ExeBillingObjects.CustomerPrivate Sub Form_Load() Set m_Customer1 =NewExeBillingObjects.Customer Set m_Customer2 =NewExeBillingObjects.CustomerEnd SubPrivate Sub cmdGet_Click() txtTheNumber.Text = m_Customer1.TheNumberEnd Sub
PublicClassCustomer Public Property TheNumber() As Integer Get Return g_TheNumber End Get Set(ByVal Value As Integer) g_TheNumber = Value End Set End PropertyEnd Class
Code located in the main application that uses the Activex EXE:
Private m_Customer1 As ExeBillingObjects.CustomerPrivate m_Customer2 As ExeBillingObjects.CustomerPrivate Sub cmdGet_Click(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles cmdGet.Click txtTheNumber.Text =CStr(m_Customer1.TheNumber)End SubPrivate Sub Form1_Load(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles MyBase.Load m_Customer1 =NewExeBillingObjects.Customer() m_Customer2 =NewExeBillingObjects.Customer()End Sub
2. Comment Out Dead Code
2.1. On
Private methods that are not referenced will be commented out.
Original VB6 code:
Public Sub PublicMethod() Call CalledPrivateMethodEnd SubPrivate Sub CalledPrivateMethod() MsgBox "This method is called."End SubPrivate Sub UncalledPrivateMethod() MsgBox "This method is not called."End Sub
C# code:
publicvoidPublicMethod(){CalledPrivateMethod();}privatevoidCalledPrivateMethod(){MessageBox.Show("This method is called.",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}//UPGRADE_NOTE: (7001) The following declaration (UncalledPrivateMethod) seems to be dead code//private void UncalledPrivateMethod()//{ //MessageBox.Show("This method is not called.", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));//}
VB.NET code:
Public Sub PublicMethod()CalledPrivateMethod()End SubPrivate Sub CalledPrivateMethod() MessageBox.Show("This method is called.", My.Application.Info.Title)End Sub'UPGRADE_NOTE: (7001) The following declaration (UncalledPrivateMethod) seems to be dead code''Private Sub UncalledPrivateMethod()''MessageBox.Show("This method is not called.", My.Application.Info.Title)''End Sub'
2.1. Off
This feature will be turned off and no changes pertaining to this feature will be made.
Original VB6 code:
Public Sub PublicMethod() Call CalledPrivateMethodEnd SubPrivate Sub CalledPrivateMethod() MsgBox "This method is called."End SubPrivate Sub UncalledPrivateMethod() MsgBox "This method is not called."End Sub
C# code:
publicvoidPublicMethod(){CalledPrivateMethod();}privatevoidCalledPrivateMethod(){MessageBox.Show("This method is called.",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}privatevoidUncalledPrivateMethod(){MessageBox.Show("This method is not called.",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}
VB.NET code:
Public Sub PublicMethod()CalledPrivateMethod()End SubPrivate Sub CalledPrivateMethod() MessageBox.Show("This method is called.", My.Application.Info.Title)End SubPrivate Sub UncalledPrivateMethod() MessageBox.Show("This method is not called.", My.Application.Info.Title)End Sub
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.
Manages special cases of default properties at runtime by using a helper class.
Increases the automation ratio and reduces the manual effort required to achieve functional equivalence.
General Description:
The Visual Basic Upgrade Companion uses a powerful static code analyzer to determine the correct type for each object. By having the correct type for each object, the VBUC 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 VBUC 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:
Dim s AsString'Display the default property of controls of a Form'For Each ctl In Me.Controls s = ctl MsgBox sNext ctl'Display the default property of TextBox'MsgBox Me.TextBox1
C# code:
string s =String.Empty;//Display the default property of controls of a Formforeach (Control ctl inContainerHelper.Controls(this)){ s =ReflectionHelper.GetPrimitiveValue(ctl).ToString(); MessageBox.Show(s,Application.ProductName);}//Display the default property of TextBoxMessageBox.Show(this.TextBox1.Text,Application.ProductName);
VB.NET code:
Dim s AsString=""'Display the default property of controls of a Form'For Each ctl As Control In ContainerHelper.Controls(Me) s = ReflectionHelper.GetPrimitiveValue(ctl).ToString() MessageBox.Show(s, Application.ProductName)Next ctl'Display the default property of TextBox'MessageBox.Show(Me.TextBox1.Text, Application.ProductName)
3.2. Static code analysis only
By switching this feature on, the VBUC will use a powerful static code analysis process to determine the correct type for each object and expands its default property.
Expands the default properties by using only static code analysis.
There are some cases where it’s not possible to determine the type of an object by using static code analysis and it may require manual intervention to achieve functional equivalence.
General Description:
The Visual Basic Upgrade Companion (VBUC) uses a static code analysis process to infer/determine the correct type for each object. By having the correct type of each object, the VBUC 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:
Dim s AsString'Display the default property of controls of a Form'For Each ctl In Me.Controls s = ctl MsgBox sNext ctl'Display the default property of TextBox'MsgBox Me.TextBox1
C# code:
string s =String.Empty;//Display the default property of controls of a Formforeach (Control ctl inContainerHelper.Controls(this)){ //UPGRADE_WARNING: (1068) ctl of type VB.Control is being forced to string s =ctl.ToString();MessageBox.Show(s,Application.ProductName);}//Display the default property of TextBoxMessageBox.Show(this.TextBox1.Text,Application.ProductName);
VB.NET code:
Dim s AsString=""'Display the default property of controls of a Form'For Each ctl As Control In ContainerHelper.Controls(Me)'UPGRADE_WARNING: (1068) ctl of type VB.Control is being forced to String.' s = ctl.ToString() MessageBox.Show(s, Application.ProductName)Next ctl'Display the default property of TextBox'MessageBox.Show(Me.TextBox1.Text, Application.ProductName)
4. Error Handling
4.1. Leave on Error Statements (VB.NET Only)
By choosing this option the VBUC will generate .NET source code that employs the “On Error” statements just like the Visual Basic 6 code.
This option increases the automation and reduces the manual effort required to get functional equivalence.
This feature is optional while upgrading to Visual Basic .NET but is not available for C#.
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:
Public Sub OnErrorGotoLabelMethod(arg AsString)On Error GoToerrHnd Dim s AsInteger s =CInt(arg) Foo s Exit SuberrHnd: MsgBox "Invalid Argument"End SubPublic Sub OnErrorResumeNextMethod(arg AsString)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 IfEnd Sub
VB.NET code:
Public Sub OnErrorGotoLabelMethod(ByVal arg AsString)On Error GoToerrHnd Dim s AsInteger s =CInt(arg)Foo(s) Exit SuberrHnd: MessageBox.Show("Invalid Argument", My.Application.Info.Title)End SubPublic Sub OnErrorResumeNextMethod(ByVal arg AsString)On Error Resume Next MessageBox.Show(arg, My.Application.Info.Title) MessageBox.Show(CStr(CInt(arg)), My.Application.Info.Title) MessageBox.Show("This line will be executed allways", My.Application.Info.Title) If Information.Err().Number <>0 Then'This code should be executed if there were any error(s)' MessageBox.Show("OnErrorResumeNextMethod reached the last statement", My.Application.Info.Title) MessageBox.Show("OnErrorResumeNextMethod reached the last statement", My.Application.Info.Title) MessageBox.Show("OnErrorResumeNextMethod reached the last statement", My.Application.Info.Title) End IfEnd Sub
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.
This option generates more .NET-like code.
This feature is optional while upgrading to Visual Basic .NET but is compulsory for C# code generation.
General Description:
The Visual Basic Upgrade Companion 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:
Public Sub OnErrorGotoLabelMethod(arg AsString)On Error GoToerrHnd Dim s AsInteger s =CInt(arg) Foo s Exit SuberrHnd: MsgBox "Invalid Argument"End SubPublic Sub OnErrorResumeNextMethod(arg AsString)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 IfEnd Sub
C# code:
publicvoidOnErrorGotoLabelMethod(string arg){try {int s =0; s =Convert.ToInt32(Double.Parse(arg));Foo(s); }catch {MessageBox.Show("Invalid Argument",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly())); }}publicvoidOnErrorResumeNextMethod(string arg){ //UPGRADE_TODO: (1069) Error handling statement (On Error Resume Next) was converted to a pattern that might have a different behavior.try {MessageBox.Show(arg,AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));MessageBox.Show(Convert.ToInt32(Double.Parse(arg)).ToString(),AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));MessageBox.Show("This line will be executed allways",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly())); //UPGRADE_WARNING: (2081) Err.Number has a new behavior.if (Information.Err().Number!=0) { //This code should be executed if there were any error(s)MessageBox.Show("OnErrorResumeNextMethod reached the last statement",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));MessageBox.Show("OnErrorResumeNextMethod reached the last statement",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));MessageBox.Show("OnErrorResumeNextMethod reached the last statement",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly())); } }catch (Exception exc) {NotUpgradedHelper.NotifyNotUpgradedElement("Resume in On-Error-Resume-Next Block"); }}
VB.NET code:
Public Sub OnErrorGotoLabelMethod(ByVal arg AsString) Try Dim s AsInteger s =CInt(arg)Foo(s) Catch MessageBox.Show("Invalid Argument", My.Application.Info.Title) End TryEnd SubPublic Sub OnErrorResumeNextMethod(ByVal arg AsString)'UPGRADE_TODO: (1069) Error handling statement (On Error Resume Next) was converted to a pattern that might have a different behavior.' Try MessageBox.Show(arg, My.Application.Info.Title) MessageBox.Show(CStr(CInt(arg)), My.Application.Info.Title) MessageBox.Show("This line will be executed allways", My.Application.Info.Title) If Information.Err().Number <>0 Then'This code should be executed if there were any error(s)' MessageBox.Show("OnErrorResumeNextMethod reached the last statement", My.Application.Info.Title) MessageBox.Show("OnErrorResumeNextMethod reached the last statement", My.Application.Info.Title) MessageBox.Show("OnErrorResumeNextMethod reached the last statement", My.Application.Info.Title) End If Catch exc As Exception NotUpgradedHelper.NotifyNotUpgradedElement("Resume in On-Error-Resume-Next Block") End TryEnd Sub
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.
This option provides a higher automation ratio, reducing the subsequent required manual work.
This feature is available for C# code generation only.
The feature will only work for the .NET framework 4.0 or higher / VS2010 or higher.
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:
Public Sub OnErrorGotoLabelMethod(arg AsString)On Error GoToerrHnd Dim s AsInteger s =CInt(arg) Foo s Exit SuberrHnd: MsgBox "Invalid Argument"End SubPublic Sub OnErrorResumeNextMethod(arg AsString)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 IfEnd Sub
C# code:
publicvoidOnErrorGotoLabelMethod(string arg){try {int s =0; s =Convert.ToInt32(Double.Parse(arg));Foo(s); }catch {MessageBox.Show("Invalid Argument",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly())); }}publicvoidOnErrorResumeNextMethod(string arg){Exception ex =null;ErrorHandlingHelper.ResumeNext(out ex, () => {MessageBox.Show(arg,AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}, () => {MessageBox.Show(Convert.ToInt32(Double.Parse(arg)).ToString(),AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}, () => {MessageBox.Show("This line will be executed allways",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));});if (ex !=null) {ErrorHandlingHelper.ResumeNext( //This code should be executed if there were any error(s) () => {MessageBox.Show("OnErrorResumeNextMethod reached the last statement",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}, () => {MessageBox.Show("OnErrorResumeNextMethod reached the last statement",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}, () => {MessageBox.Show("OnErrorResumeNextMethod reached the last statement",AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}); }}
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.
This approach will use a helper class to expose the load and unload functionality.
This approach offers a higher automatic conversion ratio.
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 VBUC 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:
Public RedColor AsBooleanPrivate Sub Form_Load()If RedColor Then Text1 ="The selected color is red"Else Text1 ="The selected color is blue"End IfEnd Sub
C# code:
//UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load event and has a new behavior.[FormsHelper.LoadAttribute]privatevoidForm2_Load(Object eventSender,EventArgs eventArgs){if (!this.IsFormLoaded()) {this.SetFormLoaded(true, visualControls);if (RedColor) {Text1.Text="The selected color is red"; }else {Text1.Text="The selected color is blue"; } }}
VB.NET code:
'UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load event and has a new behavior.'<FormsHelper.LoadAttribute> _Private Sub Form2_Load(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles MyBase.Load If Not Me.IsFormLoaded() Then Me.SetFormLoaded(True, visualControls) If RedColor Then Text1.Text ="The selected color is red" Else Text1.Text ="The selected color is blue" End If End IfEnd Sub
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.
Upgrade the Load event to a method invoked from the InitializeComponents method.
This approach might require manual adjustments to achieve functional equivalence.
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 VBUC 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:
Public RedColor AsBooleanPrivate Sub Form_Load()If RedColor Then Text1 ="The selected color is red"Else Text1 ="The selected color is blue"End IfEnd Sub
C# code:
//UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load method and has a new behavior.privatevoidForm_Load(){if (RedColor) {Text1.Text="The selected color is red"; }else {Text1.Text="The selected color is blue"; }}
VB.NET code:
'UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load method and has a new behavior.'Private Sub Form_Load() If RedColor Then Text1.Text ="The selected color is red" Else Text1.Text ="The selected color is blue" End IfEnd Sub
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.
Upgrade the Form load event to .NET inherent load event
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 VBUC 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:
Public RedColor AsBooleanPrivate Sub Form_Load()If RedColor Then Text1 ="The selected color is red"Else Text1 ="The selected color is blue"End IfEnd Sub
C# code:
//UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load event and has a new behavior.privatevoidForm2_Load(Object eventSender,EventArgs eventArgs){if (RedColor) {Text1.Text="The selected color is red"; }else {Text1.Text="The selected color is blue"; }}
VB.NET code:
'UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load event and has a new behavior.'Private Sub Form2_Load(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles MyBase.Load If RedColor Then Text1.Text ="The selected color is red" Else Text1.Text ="The selected color is blue" End IfEnd Sub
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.
Generates a call to a helper class in order to release the memory used by COM Objects.
This option is not required if all the COM objects are converted to .NET.
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 VBUC 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:
Private Sub Command1_Click() Dim conConnection AsNewADODB.Connection Dim cmdCommand AsNewADODB.Command Dim rstRecordSet AsNewADODB.Recordset conConnection.Open cmdCommand.CommandText ="SELECT*FROM TestTable;" rstRecordSet.OpenEnd Sub
Private Sub Command1_Click(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Dim conConnection AsNewADODB.Connection Dim cmdCommand AsNewADODB.Command Dim rstRecordSet AsNewADODB.Recordset Try conConnection.Open() cmdCommand.CommandText ="SELECT*FROM TestTable;" rstRecordSet.Open() Finally MemoryHelper.ReleaseAndCleanObject(rstRecordSet) rstRecordSet = Nothing MemoryHelper.ReleaseAndCleanObject(cmdCommand) cmdCommand = Nothing MemoryHelper.ReleaseAndCleanObject(conConnection) conConnection = Nothing End TryEnd Sub
6.2. Free COM Objects memory manually
By using this option the VBUC will not generate special code to handle the COM Objects memory usage.
The VBUC will not generate any special code to release memory used by COM Objects.
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 VBUC 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:
Private Sub Command1_Click()Dim conConnection AsNewADODB.ConnectionDim cmdCommand AsNewADODB.CommandDim rstRecordSet AsNewADODB.RecordsetconConnection.OpencmdCommand.CommandText ="SELECT*FROM TestTable;"rstRecordSet.OpenEnd Sub
Private Sub Command1_Click(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles Command1.Click Dim conConnection AsNewADODB.Connection Dim cmdCommand AsNewADODB.Command Dim rstRecordSet AsNewADODB.Recordset conConnection.Open() cmdCommand.CommandText ="SELECT*FROM TestTable;" rstRecordSet.Open()End Sub
7. Convert HelpFile and HelpContexID Feature
7.1 Do not Convert HelpFile and HelpContextID Feature
Choosing this option, the VBUC 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 VBUC solve this feature with a stub.
Original VB6 code
Private Sub Form_Load()
App.HelpFile = "clcshelp.chm"
End Sub
C# code
privatevoidForm_Load(){ //UPGRADE_ISSUE: (2064) VB method VB.Global was not upgraded. More Information: https://docs.mobilize.net/vbuc/ewis#2064 //UPGRADE_ISSUE: (2070) Constant App was not upgraded. More Information: https://docs.mobilize.net/vbuc/ewis#2070 //UPGRADE_ISSUE: (2064) App property App.HelpFile was not upgraded. More Information: https://docs.mobilize.net/vbuc/ewis#2064UpgradeStubs.VB.getGlobal().getApp().setHelpFile("clcshelp.chm");}
VB.Net code
Private Sub Form_Load()
'UPGRADE_ISSUE: (2064) VB method VB.Global was not upgraded. More Information: https://docs.mobilize.net/vbuc/ewis#2064
'UPGRADE_ISSUE: (2070) Constant App was not upgraded. More Information: https://docs.mobilize.net/vbuc/ewis#2070
'UPGRADE_ISSUE: (2064) App property App.HelpFile was not upgraded. More Information: https://docs.mobilize.net/vbuc/ewis#2064
UpgradeSolution1Support.UpgradeStubs.VB.getGlobal().getApp().setHelpFile("clcshelp.chm")
End Sub
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.
Generates an event for each control with HelpContextID
Verifies if .chm help file exists
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 Visual Basic Upgrade Companion 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
Private Sub Form_Load()
App.HelpFile = "clcshelp.chm"
End Subvb
C# code:
//UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load method and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080privatevoidForm_Load(){UpgradeSupport.helpSupport.HelpFile="clcshelp.chm";}//In Designer FileprotectedvoidInitializeHelp(){UpgradeSupport.helpSupport.SetHelpContextId(this,523);UpgradeSupport.helpSupport.SetHelpContextId(Slider1,509);}
VB.NET Code
'UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load method and has a new behavior. More Information: https://docs.mobilize.net/vbuc/ewis#2080
Private Sub Form_Load()
UpgradeSupport.helpSupport.HelpFile = "clcshelp.chm"
End Sub
'In Designer File
Protected Sub InitializeHelp()
UpgradeSupport.helpSupport.SetHelpContextId(Me, 523)
UpgradeSupport.helpSupport.SetHelpContextId(Slider1, 509)
End Sub
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.
Manage late-bound reference scenarios by using a helper class.
This option increases the automation ratio and reduces the manual effort required to get functional equivalence.
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 Visual Basic Upgrade Companion 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 VBUC 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:
Public Sub Func(myControl As Control, myForm As Form, myVar As Variant) myControl.controlProp1 = myVar.varProp1 myForm.formProp1 = myControl.controlProp1 myVar.varProp1 = myForm.formProp1 myControl.Func 1 myForm.Func 1 myVar.Func 1End Sub
Public Sub Func(ByVal myControl As Control, ByVal myForm As Form, ByVal myVar AsObject) ReflectionHelper.LetMember(myControl,"controlProp1", ReflectionHelper.GetMember(myVar,"varProp1")) ReflectionHelper.LetMember(myForm,"formProp1", ReflectionHelper.GetMember(myControl,"controlProp1")) ReflectionHelper.LetMember(myVar,"varProp1", ReflectionHelper.GetMember(myForm,"formProp1")) ReflectionHelper.Invoke(myControl,"Func",NewObject() {1}) ReflectionHelper.Invoke(myForm,"Func",NewObject() {1}) ReflectionHelper.Invoke(myVar,"Func",NewObject() {1})End Sub
8.2. Static code analysis only
By selecting this option, the VBUC will use its static code analysis process to determine the correct type for each object and resolve the late binding access.
Resolve Late Binding Access by using only static code analysis.
There are some cases where it is not possible to determine the type of an object by using a static code analysis and it may require manual intervention.
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 Visual Basic Upgrade Companion 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:
Public Sub Func(myControl As Control, myForm As Form, myVar As Variant) myControl.controlProp1 = myVar.varProp1 myForm.formProp1 = myControl.controlProp1 myVar.varProp1 = myForm.formProp1 myControl.Func 1 myForm.Func 1 myVar.Func 1End Sub
C# code:
publicvoidFunc(Control myControl,Form myForm,object myVar){ //UPGRADE_TODO: (1067) Member controlProp1 is not defined in type VB.Control. //UPGRADE_TODO: (1067) Member varProp1 is not defined in type Variant.myControl.controlProp1=myVar.varProp1; //UPGRADE_TODO: (1067) Member formProp1 is not defined in type VB.Form. //UPGRADE_TODO: (1067) Member controlProp1 is not defined in type VB.Control.myForm.formProp1=myControl.controlProp1; //UPGRADE_TODO: (1067) Member varProp1 is not defined in type Variant. //UPGRADE_TODO: (1067) Member formProp1 is not defined in type VB.Form.myVar.varProp1=myForm.formProp1; //UPGRADE_TODO: (1067) Member Func is not defined in type VB.Control.myControl.Func(1); //UPGRADE_TODO: (1067) Member Func is not defined in type VB.Form.myForm.Func(1); //UPGRADE_TODO: (1067) Member Func is not defined in type Variant.myVar.Func(1);}
VB.NET code:
Public Sub Func(ByVal myControl As Control, ByVal myForm As Form, ByVal myVar AsObject)'UPGRADE_TODO: (1067) Member controlProp1 is not defined in type VB.Control.''UPGRADE_TODO: (1067) Member varProp1 is not defined in type Variant.' myControl.controlProp1 = myVar.varProp1'UPGRADE_TODO: (1067) Member formProp1 is not defined in type VB.Form.''UPGRADE_TODO: (1067) Member controlProp1 is not defined in type VB.Control.' myForm.formProp1 = myControl.controlProp1'UPGRADE_TODO: (1067) Member varProp1 is not defined in type Variant.''UPGRADE_TODO: (1067) Member formProp1 is not defined in type VB.Form.' myVar.varProp1 = myForm.formProp1'UPGRADE_TODO: (1067) Member Func is not defined in type VB.Control.' myControl.Func(1)'UPGRADE_TODO: (1067) Member Func is not defined in type VB.Form.' myForm.Func(1)'UPGRADE_TODO: (1067) Member Func is not defined in type Variant.' myVar.Func(1)End Sub
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.
Manage late-bound reference scenarios by using dynamic variables.
This option increases the automation ratio and reduces the manual effort required to get functional equivalence.
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 Visual Basic Upgrade Companion 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 VBUC 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 VBUC user should be aware of such limitation when turning this feature on.
Original VB6 code:
Public Sub Func(myControl As Control, myForm As Form, myVar As Variant) myControl.controlProp1 = myVar.varProp1 myForm.formProp1 = myControl.controlProp1 myVar.varProp1 = myForm.formProp1 myControl.Func 1 myForm.Func 1 myVar.Func 1End Sub
Partial ClassForm1 ... Public WithEvents Shape2 As UpgradeHelpers.Gui.ShapeHelper Public WithEvents Shape1 As UpgradeHelpers.Gui.ShapeHelper Public WithEvents Line4 As System.Windows.Forms.Label Public WithEvents Line3 As System.Windows.Forms.Label Public WithEvents Line2 As System.Windows.Forms.Label Public WithEvents Line1 As System.Windows.Forms.Label ... Me.Shape2 = New UpgradeHelpers.Gui.ShapeHelper() Me.Shape1 = New UpgradeHelpers.Gui.ShapeHelper() Me.Line4 = New System.Windows.Forms.Label() Me.Line3 = New System.Windows.Forms.Label() Me.Line2 = New System.Windows.Forms.Label() Me.Line1 = New System.Windows.Forms.Label() ... '' 'Shape2 ' Me.Shape2.AllowDrop = True Me.Shape2.BackColor = System.Drawing.SystemColors.Window Me.Shape2.BackStyle = 0 Me.Shape2.BorderStyle = 1 Me.Shape2.Enabled = False Me.Shape2.FillColor = System.Drawing.Color.Black Me.Shape2.FillStyle = 1 Me.Shape2.Location = New System.Drawing.Point(288, 88) Me.Shape2.Name = "Shape2" Me.Shape2.Shape = 2 Me.Shape2.Size = New System.Drawing.Size(129, 57) Me.Shape2.Visible = True ... '' 'Line4 ' Me.Line4.AllowDrop = True Me.Line4.BackColor = System.Drawing.SystemColors.WindowText Me.Line4.Enabled = False Me.Line4.Location = New System.Drawing.Point(32, 216) Me.Line4.Name = "Line4" Me.Line4.Size = New System.Drawing.Size(240, 1) Me.Line4.Visible = True '' 'Line3 ' Me.Line3.AllowDrop = True Me.Line3.BackColor = System.Drawing.SystemColors.WindowText Me.Line3.Enabled = False Me.Line3.Location = New System.Drawing.Point(272, 16) Me.Line3.Name = "Line3" Me.Line3.Size = New System.Drawing.Size(1, 200) Me.Line3.Visible = True ...End Class
9.2. PowerPack and Helper class
By switching this optional feature on, the VBUC will convert the legacy “line” control to a .NET equivalent located under the Microsoft Visual Basic Power Packs library.
This feature requires the installation of the Visual Basic Power Packs libraries.
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
Partial ClassForm1 Public WithEvents Shape2 As Microsoft.VisualBasic.PowerPacks.OvalShape Public WithEvents Shape1 As Microsoft.VisualBasic.PowerPacks.RectangleShape Public WithEvents Line4 As Microsoft.VisualBasic.PowerPacks.LineShape Public WithEvents Line3 As Microsoft.VisualBasic.PowerPacks.LineShape Public WithEvents Line2 As Microsoft.VisualBasic.PowerPacks.LineShape Public WithEvents Line1 As Microsoft.VisualBasic.PowerPacks.LineShape Public WithEvents ShapeContainer1 As Microsoft.VisualBasic.PowerPacks.ShapeContainer ... Me.ShapeContainer1 = New Microsoft.VisualBasic.PowerPacks.ShapeContainer() Me.Shape2 = New Microsoft.VisualBasic.PowerPacks.OvalShape() Me.Shape1 = New Microsoft.VisualBasic.PowerPacks.RectangleShape() Me.Line4 = New Microsoft.VisualBasic.PowerPacks.LineShape() Me.Line3 = New Microsoft.VisualBasic.PowerPacks.LineShape() Me.Line2 = New Microsoft.VisualBasic.PowerPacks.LineShape() Me.Line1 = New Microsoft.VisualBasic.PowerPacks.LineShape() ... '' 'ShapeContainer1 ' Me.ShapeContainer1.Location = New System.Drawing.Point(0, 0) Me.ShapeContainer1.Size = New System.Drawing.Size(434, 239) Me.ShapeContainer1.Shapes.Add(Shape2) Me.ShapeContainer1.Shapes.Add(Shape1) Me.ShapeContainer1.Shapes.Add(Line4) Me.ShapeContainer1.Shapes.Add(Line3) Me.ShapeContainer1.Shapes.Add(Line2) Me.ShapeContainer1.Shapes.Add(Line1) '' 'Shape2 ' Me.Shape2.BackColor = System.Drawing.SystemColors.Window Me.Shape2.BackStyle = Microsoft.VisualBasic.PowerPacks.BackStyle.Transparent Me.Shape2.BorderColor = System.Drawing.SystemColors.WindowText Me.Shape2.BorderStyle = System.Drawing.Drawing2D.DashStyle.Solid Me.Shape2.BorderWidth = 1 Me.Shape2.Enabled = False Me.Shape2.FillColor = System.Drawing.Color.Black Me.Shape2.FillStyle = Microsoft.VisualBasic.PowerPacks.FillStyle.Transparent Me.Shape2.Location = New System.Drawing.Point(288, 88) Me.Shape2.Name = "Shape2" Me.Shape2.Size = New System.Drawing.Size(129, 57) Me.Shape2.Visible = True ... '' 'Line4 ' Me.Line4.BorderColor = System.Drawing.SystemColors.WindowText Me.Line4.BorderStyle = System.Drawing.Drawing2D.DashStyle.Solid Me.Line4.BorderWidth = 1 Me.Line4.Enabled = False Me.Line4.Name = "Line4" Me.Line4.Visible = True Me.Line4.X1 = 32 Me.Line4.X2 = 272 Me.Line4.Y1 = 216 Me.Line4.Y2 = 216 '' 'Line3 ' Me.Line3.BorderColor = System.Drawing.SystemColors.WindowText Me.Line3.BorderStyle = System.Drawing.Drawing2D.DashStyle.Solid Me.Line3.BorderWidth = 1 Me.Line3.Enabled = False Me.Line3.Name = "Line3" Me.Line3.Visible = True Me.Line3.X1 = 272 Me.Line3.X2 = 272 Me.Line3.Y1 = 16 Me.Line3.Y2 = 216 ...End Class
10. String Functions
Conversion options for Strings Mid, left and right functions.
10.1. Helper class functions
This option enables the VBUC 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:
Private Sub foo() Dim s AsString Dim theLength AsInteger s ="select Employee_Id, Fist_Name, Middle_Name, Last_Name, Birthday, Salary from Employee order by Last_Name, First_Name, Middle_Name" Dim select_index AsInteger s =Trim(s) selectString = VBA.Strings.Left(s,6) selectString =LCase(selectString) If selectString ="select" Then Else'error' End If Dim selectIndex AsInteger selectIndex = VBA.Strings.InStr(1, s,"select ") selectIndex = selectIndex +Len("select") s = VBA.Strings.Mid(s, selectIndex, Len(s)) Dim fromIndex AsInteger fromIndex = VBA.Strings.InStr(1, s,"from ") Dim fromString AsString fromString = VBA.Strings.Right(s, Len(s)- (fromIndex -1)) s = VBA.Strings.Replace(s, fromString,"") Dim theMembersArray()AsString s =Trim(s) theMembersArray = VBA.Strings.Split(s,",") Dim index AsInteger Dim arrayLength AsInteger theLBound =LBound(theMembersArray) theUBound =UBound(theMembersArray) For index = theLBound To theUBoundtheMembersArray(index)=Trim(theMembersArray(index)) Next indexEnd Sub
C# code:
privatevoidfoo(){object theUBound =null;object theLBound =null;object selectString =null;string s ="select Employee_Id, Fist_Name, Middle_Name, Last_Name, Birthday, Salary from Employee order by Last_Name, First_Name, Middle_Name"; s =s.Trim(); selectString =StringsHelper.Left(s,6); selectString =ReflectionHelper.GetPrimitiveValue<string>(selectString).ToLower();if (ReflectionHelper.GetPrimitiveValue<string>(selectString) =="select") { }else { //error }int selectIndex = (s.IndexOf("select ") +1); selectIndex +=Strings.Len("select"); s =StringsHelper.Mid(s, selectIndex,Strings.Len(s));int fromIndex = (s.IndexOf("from ") +1);string fromString =StringsHelper.Right(s,Strings.Len(s) - (fromIndex -1)); s =Strings.Replace(s, fromString,"",1,-1,CompareMethod.Binary); s =s.Trim();string[] theMembersArray = (string[]) s.Split(','); theLBound =theMembersArray.GetLowerBound(0); theUBound =theMembersArray.GetUpperBound(0); //UPGRADE_WARNING: (1068) theUBound of type Variant is being forced to Scalar.object tempForEndVar =ReflectionHelper.GetPrimitiveValue(theUBound);for (int index =ReflectionHelper.GetPrimitiveValue<int>(theLBound); index <=ReflectionHelper.GetPrimitiveValue<double>(tempForEndVar); index++) {theMembersArray[index] =theMembersArray[index].Trim(); }}
VB.NET code:
Private Sub foo() Dim theUBound, theLBound, selectString AsObject Dim s AsString="select Employee_Id, Fist_Name, Middle_Name, Last_Name, Birthday, Salary from Employee order by Last_Name, First_Name, Middle_Name" s = s.Trim() selectString = StringsHelper.Left(s,6) selectString = ReflectionHelper.GetPrimitiveValue(Of String)(selectString).ToLower() If ReflectionHelper.GetPrimitiveValue(Of String)(selectString) ="select" Then Else'error' End If Dim selectIndex AsInteger= (s.IndexOf("select ")+1) selectIndex += Strings.Len("select") s = StringsHelper.Mid(s, selectIndex, Strings.Len(s)) Dim fromIndex AsInteger= (s.IndexOf("from ")+1) Dim fromString AsString= StringsHelper.Right(s, Strings.Len(s)- (fromIndex -1)) s = s.Replace(fromString,"") s = s.Trim() Dim theMembersArray()AsString= s.Split(","c) theLBound = theMembersArray.GetLowerBound(0) theUBound = theMembersArray.GetUpperBound(0)'UPGRADE_WARNING: (1068) theUBound of type Variant is being forced to Scalar.' Dim tempForEndVar AsObject= ReflectionHelper.GetPrimitiveValue(theUBound) For index AsInteger= ReflectionHelper.GetPrimitiveValue(Of Integer)(theLBound) To ReflectionHelper.GetPrimitiveValue(Of Integer)(tempForEndVar)theMembersArray(index)=theMembersArray(index).Trim() Next indexEnd Sub
10.2. Native .NET System.String class functions
This option enables the VBUC to convert the String related functions Mid, Left, and Right, located in the VBA.Strings library, to native .NET String class functions.
This feature generates more .NET-like code.
Original VB6 code:
Private Sub foo() Dim s AsString Dim theLength AsInteger s ="select Employee_Id, Fist_Name, Middle_Name, Last_Name, Birthday, Salary from Employee order by Last_Name, First_Name, Middle_Name" Dim select_index AsInteger s =Trim(s) selectString = VBA.Strings.Left(s,6) selectString =LCase(selectString) If selectString ="select" Then Else'error' End If Dim selectIndex AsInteger selectIndex = VBA.Strings.InStr(1, s,"select ") selectIndex = selectIndex +Len("select") s = VBA.Strings.Mid(s, selectIndex, Len(s)) Dim fromIndex AsInteger fromIndex = VBA.Strings.InStr(1, s,"from ") Dim fromString AsString fromString = VBA.Strings.Right(s, Len(s)- (fromIndex -1)) s = VBA.Strings.Replace(s, fromString,"") Dim theMembersArray()AsString s =Trim(s) theMembersArray = VBA.Strings.Split(s,",") Dim index AsInteger Dim arrayLength AsInteger theLBound =LBound(theMembersArray) theUBound =UBound(theMembersArray) For index = theLBound To theUBoundtheMembersArray(index)=Trim(theMembersArray(index)) Next indexEnd Sub
C# code:
privatevoidfoo(){string s ="select Employee_Id, Fist_Name, Middle_Name, Last_Name, Birthday, Salary from Employee order by Last_Name, First_Name, Middle_Name"; s =s.Trim();string selectString =s.Substring(0,Math.Min(6,s.Length)); selectString =selectString.ToLower();if (selectString =="select") { }else { //error }int selectIndex = (s.IndexOf("select ") +1); selectIndex +=Strings.Len("select"); s =s.Substring(selectIndex -1,Math.Min(Strings.Len(s),s.Length- (selectIndex -1)));int fromIndex = (s.IndexOf("from ") +1);string fromString =s.Substring(Math.Max(s.Length- (Strings.Len(s) - (fromIndex -1)),0)); s =StringsHelper.Replace(s, fromString,"",1,-1,CompareMethod.Binary); s =s.Trim();string[] theMembersArray = (string[]) s.Split(',');int theLBound =theMembersArray.GetLowerBound(0);int theUBound =theMembersArray.GetUpperBound(0);int tempForEndVar = theUBound;for (int index = theLBound; index <= tempForEndVar; index++) {theMembersArray[index] =theMembersArray[index].Trim(); }}
VB.NET code:
Private Sub foo() Dim s AsString="select Employee_Id, Fist_Name, Middle_Name, Last_Name, Birthday, Salary from Employee order by Last_Name, First_Name, Middle_Name" s = s.Trim() Dim selectString AsString= s.Substring(0, Math.Min(6, s.Length)) selectString = selectString.ToLower() If selectString ="select" Then Else'error' End If Dim selectIndex AsInteger= (s.IndexOf("select ")+1) selectIndex += Strings.Len("select") s = s.Substring(selectIndex -1, Math.Min(Strings.Len(s), s.Length - (selectIndex -1))) Dim fromIndex AsInteger= (s.IndexOf("from ")+1) Dim fromString AsString= s.Substring(Math.Max(s.Length - (Strings.Len(s)- (fromIndex -1)),0)) s = s.Replace(fromString,"") s = s.Trim() Dim theMembersArray()AsString= s.Split(","c) Dim theLBound AsInteger= theMembersArray.GetLowerBound(0) Dim theUBound AsInteger= theMembersArray.GetUpperBound(0) For index AsInteger= theLBound To theUBoundtheMembersArray(index)=theMembersArray(index).Trim() Next indexEnd Sub
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.
By using this option the converted application will not have any reference to the COM Component.
Original VB6 code:
Private Sub foo() Dim s AsString Dim theLength AsInteger s ="select Employee_Id, Fist_Name, Middle_Name, Last_Name, Birthday, Salary from Employee order by Last_Name, First_Name, Middle_Name" Dim select_index AsInteger s =Trim(s) selectString = VBA.Strings.Left(s,6) selectString =LCase(selectString) If selectString ="select" Then Else'error' End If Dim selectIndex AsInteger selectIndex = VBA.Strings.InStr(1, s,"select ") selectIndex = selectIndex +Len("select") s = VBA.Strings.Mid(s, selectIndex, Len(s)) Dim fromIndex AsInteger fromIndex = VBA.Strings.InStr(1, s,"from ") Dim fromString AsString fromString = VBA.Strings.Right(s, Len(s)- (fromIndex -1)) s = VBA.Strings.Replace(s, fromString,"") Dim theMembersArray()AsString s =Trim(s) theMembersArray = VBA.Strings.Split(s,",") Dim index AsInteger Dim arrayLength AsInteger theLBound =LBound(theMembersArray) theUBound =UBound(theMembersArray) For index = theLBound To theUBoundtheMembersArray(index)=Trim(theMembersArray(index)) Next indexEnd Sub
C# code:
privatevoidfoo(){string s ="select Employee_Id, Fist_Name, Middle_Name, Last_Name, Birthday, Salary from Employee order by Last_Name, First_Name, Middle_Name"; s =s.Trim();string selectString =Strings.Left(s,6); selectString =selectString.ToLower();if (selectString =="select") { }else { //error }int selectIndex = (s.IndexOf("select ") +1); selectIndex +=Strings.Len("select"); s =Strings.Mid(s, selectIndex,Strings.Len(s));int fromIndex = (s.IndexOf("from ") +1);string fromString =Strings.Right(s,Strings.Len(s) - (fromIndex -1)); s =StringsHelper.Replace(s, fromString,"",1,-1,CompareMethod.Binary); s =s.Trim();string[] theMembersArray = (string[]) s.Split(',');int theLBound =theMembersArray.GetLowerBound(0);int theUBound =theMembersArray.GetUpperBound(0);int tempForEndVar = theUBound;for (int index = theLBound; index <= tempForEndVar; index++) {theMembersArray[index] =theMembersArray[index].Trim(); }}
VB.NET code:
Private Sub foo() Dim s AsString="select Employee_Id, Fist_Name, Middle_Name, Last_Name, Birthday, Salary from Employee order by Last_Name, First_Name, Middle_Name" s = s.Trim() Dim selectString AsString= Strings.Left(s,6) selectString = selectString.ToLower() If selectString ="select" Then Else'error' End If Dim selectIndex AsInteger= (s.IndexOf("select ")+1) selectIndex += Strings.Len("select") s = Strings.Mid(s, selectIndex, Strings.Len(s)) Dim fromIndex AsInteger= (s.IndexOf("from ")+1) Dim fromString AsString= Strings.Right(s, Strings.Len(s)- (fromIndex -1)) s = s.Replace(fromString,"") s = s.Trim() Dim theMembersArray()AsString= s.Split(","c) Dim theLBound AsInteger= theMembersArray.GetLowerBound(0) Dim theUBound AsInteger= theMembersArray.GetUpperBound(0) For index AsInteger= theLBound To theUBoundtheMembersArray(index)=theMembersArray(index).Trim() Next indexEnd Sub
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:
Private Sub Form_Load() Dim x AsInteger x =1End SubPublic Sub PublicMethod() Dim y AsInteger y =1End SubPrivate Sub PrivateMethod() Dim z AsInteger z =1End Sub
Private Sub Form_Load(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles MyBase.Load'Skeletons Generation'End SubPublic Sub PublicMethod()'Skeletons Generation'End SubPrivate Sub PrivateMethod()'Skeletons Generation'End Sub
11.2. Off
This feature will be turned off and no changes pertaining to this feature will be made.
Original VB6 code:
Private Sub Form_Load() Dim x AsInteger x =1End SubPublic Sub PublicMethod() Dim y AsInteger y =1End SubPrivate Sub PrivateMethod() Dim z AsInteger z =1End Sub
C# code:
privatevoidForm_Load(Object eventSender,EventArgs eventArgs){int x =1;}publicvoidPublicMethod(){int y =1;}privatevoidPrivateMethod(){int z =1;}
VB.NET code:
Private Sub Form_Load(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles MyBase.Load Dim x AsInteger=1End SubPublic Sub PublicMethod() Dim y AsInteger=1End SubPrivate Sub PrivateMethod() Dim z AsInteger=1End Sub
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.
It makes all the not supported elements compile, avoiding an important amount of compilation errors and makes easier to understand the required manual effort.
A solution can be implemented for each not-supported element in a unique location in the target source code, instead of changing all the not-upgraded member references.
The VBUC 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:
Public Sub main() Dim s1 AsString Dim s2 AsString Dim theLen AsInteger theLen =8 s1 =Chr(65) s2 =ChrB(65) MsgBox s1 MsgBox s2 Dim f As Form Dim fs As FillStyleConstants fs = f.FillStyle f.FillStyle = fsEnd Sub
C# code:
internalstaticclassModule1{publicstaticvoidMain() {int theLen =8;string s1 =Strings.Chr(65).ToString(); //UPGRADE_ISSUE: (1040) ChrB function is not supported.string s2 =UpgradeStubs.VBA_Strings.ChrB(65);MessageBox.Show(s1,AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));MessageBox.Show(s2,AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));Form f =null; //UPGRADE_ISSUE: (2064) Form property f.FillStyle was not upgraded. //UPGRADE_ISSUE: (2068) VBRUN.FillStyleConstants object was not upgraded.UpgradeStubs.VBRUN_FillStyleConstantsEnum fs =f.getFillStyle(); //UPGRADE_ISSUE: (2064) Form property f.FillStyle was not upgraded.f.setFillStyle(fs); }}//File UpgradeStubs.csnamespaceUpgradeStubs{publicstaticclassSystem_Windows_Forms_Control {publicstaticUpgradeStubs.VBRUN_FillStyleConstantsEnumgetFillStyle(thisControl instance) {UpgradeHelpers.Helpers.NotUpgradedHelper.NotifyNotUpgradedElement("VB.Control.FillStyle");returndefault(UpgradeStubs.VBRUN_FillStyleConstantsEnum); }publicstaticvoidsetFillStyle(thisControl instance,UpgradeStubs.VBRUN_FillStyleConstantsEnum FillStyle) {UpgradeHelpers.Helpers.NotUpgradedHelper.NotifyNotUpgradedElement("VB.Control.FillStyle"); } } publicclassVBA_Strings {publicstaticstringChrB(byte CharCode) {UpgradeHelpers.Helpers.NotUpgradedHelper.NotifyNotUpgradedElement("VBA.Strings.ChrB");returndefault(string); } } publicenumVBRUN_FillStyleConstantsEnum { None =-1 }}
VB.NET code:
Module Module1Public Sub main() Dim theLen AsInteger=8 Dim s1 AsString= Strings.Chr(65).ToString()'UPGRADE_ISSUE: (1040) ChrB function is not supported.' Dim s2 AsString= UpgradeSolution1Support.UpgradeStubs.VBA_Strings.ChrB(65) MessageBox.Show(s1, My.Application.Info.Title) MessageBox.Show(s2, My.Application.Info.Title) Dim f As Form'UPGRADE_ISSUE: (2064) Form property f.FillStyle was not upgraded.''UPGRADE_ISSUE: (2068) VBRUN.FillStyleConstants object was not upgraded.' Dim fs As UpgradeSolution1Support.UpgradeStubs.VBRUN_FillStyleConstantsEnum = f.getFillStyle()'UPGRADE_ISSUE: (2064) Form property f.FillStyle was not upgraded.' f.setFillStyle(fs) End Sub'File UpgradeStubs.cs'NamespaceUpgradeStubsPublicModuleSystem_Windows_Forms_Control <System.Runtime.CompilerServices.Extension()> _PublicFunctiongetFillStyle(ByVal instanceAsControl) AsUpgradeSolution1Support.UpgradeStubs.VBRUN_FillStyleConstantsEnumUpgradeHelpers.Helpers.NotUpgradedHelper.NotifyNotUpgradedElement("VB.Control.FillStyle")Return0EndFunction <System.Runtime.CompilerServices.Extension()> _PublicSubsetFillStyle(ByVal instanceAsControl, ByValFillStyleAsUpgradeSolution1Support.UpgradeStubs.VBRUN_FillStyleConstantsEnum)UpgradeHelpers.Helpers.NotUpgradedHelper.NotifyNotUpgradedElement("VB.Control.FillStyle")EndSubEndModulePublicClassVBA_StringsPublicSharedFunctionChrB(ByVal CharCodeAsByte) AsStringUpgradeHelpers.Helpers.NotUpgradedHelper.NotifyNotUpgradedElement("VBA.Strings.ChrB")Return ""EndFunctionEndClassPublicEnumVBRUN_FillStyleConstantsEnumNone = -1EndEnumEndNameSpace
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.
This option includes a warning comment on the output source code for each not supported element.
Original VB6 code:
Public Sub main() Dim s1 AsString Dim s2 AsString Dim theLen AsInteger theLen =8 s1 =Chr(65) s2 =ChrB(65) MsgBox s1 MsgBox s2 Dim f As Form Dim fs As FillStyleConstants fs = f.FillStyle f.FillStyle = fsEnd Sub
C# code:
internalstaticclassModule1{publicstaticvoidMain() {int theLen =8;string s1 =Strings.Chr(65).ToString(); //UPGRADE_ISSUE: (1040) ChrB function is not supported.string s2 =ChrB(65);MessageBox.Show(s1,AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));MessageBox.Show(s2,AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));Form f =null; //UPGRADE_ISSUE: (2064) Form property f.FillStyle was not upgraded. //UPGRADE_ISSUE: (2068) VBRUN.FillStyleConstants object was not upgraded.VBRUN.FillStyleConstants fs =f.FillStyle; //UPGRADE_ISSUE: (2064) Form property f.FillStyle was not upgraded.f.FillStyle= fs; }}
VB.NET code:
Public Sub main() Dim theLen AsInteger=8 Dim s1 AsString= Strings.Chr(65).ToString()'UPGRADE_ISSUE: (1040) ChrB function is not supported.' Dim s2 AsString=ChrB(65) MessageBox.Show(s1, My.Application.Info.Title) MessageBox.Show(s2, My.Application.Info.Title) Dim f As Form'UPGRADE_ISSUE: (2064) Form property f.FillStyle was not upgraded.''UPGRADE_ISSUE: (2068) VBRUN.FillStyleConstants object was not upgraded.' Dim fs As VBRUN.FillStyleConstants = f.FillStyle'UPGRADE_ISSUE: (2064) Form property f.FillStyle was not upgraded.' f.FillStyle = fsEnd Sub
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:
PrivateFunctionfoo()AsString'var2 is an unused variable' Dim var2 AsString Dim var1 AsString var1 ="Function example" foo = var1 End FunctionPrivate Sub goo()'var1 is an unused variable' Dim var1 AsString Dim var2 AsString var2 ="Subroutine example" MsgBox var2End Sub
C# code:
privatestringfoo(){ //var2 is an unused variablestring var1 ="Function example";return var1;}privatevoidgoo(){ //var1 is an unused variablestring var2 ="Subroutine example";MessageBox.Show(var2,AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}
VB.NET code:
PrivateFunctionfoo()AsString'var2 is an unused variable' Dim var1 AsString="Function example" Return var1End FunctionPrivate Sub goo()'var1 is an unused variable' Dim var2 AsString="Subroutine example" MessageBox.Show(var2, My.Application.Info.Title)End Sub
13.2. Off
Local variables will not be removed, even if they are not used.
Original VB6 code:
PrivateFunctionfoo()AsString'var2 is an unused variable' Dim var2 AsString Dim var1 AsString var1 ="Function example" foo = var1 End FunctionPrivate Sub goo()'var1 is an unused variable' Dim var1 AsString Dim var2 AsString var2 ="Subroutine example" MsgBox var2End Sub
C# code:
privatestringfoo(){ //var2 is an unused variablestring var2 ="";string var1 ="Function example";return var1;}privatevoidgoo(){ //var1 is an unused variablestring var1 ="";string var2 ="Subroutine example";MessageBox.Show(var2,AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));}
VB.NET code:
PrivateFunctionfoo()AsString'var2 is an unused variable' Dim var2 AsString="" Dim var1 AsString="Function example" Return var1End FunctionPrivate Sub goo()'var1 is an unused variable' Dim var1 AsString="" Dim var2 AsString="Subroutine example" MessageBox.Show(var2, My.Application.Info.Title)End Sub
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.
By using this option the converted application will not have any reference to the COM Component.
Public Sub main() Dim c1 AsNewCollection Dim c2 AsNewCollection Dim c3 AsNewCollection Dim i AsInteger c1.Add "a" c1.Add "b" c1.Add "c" i = c1.Count c2.Add 0 c2.Add 1 c2.Add 2 c2.Add 3 i = c2.Count c3.Add 0 c3.Add "a" c3.Add 1 c3.Add "b" c3.Add 2 c3.Add "c" c3.Add 3 c3.Add "d" c3.Add 4 i = c3.Count Dim c AsNewCollection c.Add "Element1",1 MsgBox c(1) c.Remove (1)End Sub
C# code:
internalstaticclassModule1{publicvoidmain() {StringDictionary c1 =newStringDictionary();Hashtable c2 =newHashtable();Hashtable c3 =newHashtable();c1.Add("a","a");c1.Add("b","b");c1.Add("c","c");int i =c1.Count;c2.Add(0,0);c2.Add(1,1);c2.Add(2,2);c2.Add(3,3); i =c2.Count;c3.Add(0,0);c3.Add("a","a");c3.Add(1,1);c3.Add("b","b");c3.Add(2,2);c3.Add("c","c");c3.Add(3,3);c3.Add("d","d");c3.Add(4,4); i =c3.Count;StringDictionary c =newStringDictionary();c.Add("1","Element1");MessageBox.Show((string) c[1],AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));c.Remove("1"); }}
VB.NET code:
Module Module1Public Sub main() Dim c1 AsNewStringDictionary() Dim c2 AsNewHashtable() Dim c3 AsNewHashtable() c1.Add("a","a") c1.Add("b","b") c1.Add("c","c") Dim i AsInteger= c1.Count c2.Add(0,0) c2.Add(1,1) c2.Add(2,2) c2.Add(3,3) i = c2.Count c3.Add(0,0) c3.Add("a","a") c3.Add(1,1) c3.Add("b","b") c3.Add(2,2) c3.Add("c","c") c3.Add(3,3) c3.Add("d","d") c3.Add(4,4) i = c3.Count Dim c AsNewStringDictionary() c.Add(CStr(1),"Element1") MessageBox.Show(CStr(c(1)), My.Application.Info.Title) c.Remove(CStr(1)) End Sub
14.2. To System.Collections.Specialized.OrderedDictionary native .NET class
Converts the Collection type to System.Collections.Specialized.OrderedDictionary.
By using this option the converted application will not have any reference to the COM Component.
Class
Maps to
vba.Collection
System.Collections.Specialized.OrderedDictionary
Original VB6 code:
Public Sub main() Dim c1 AsNewCollection Dim c2 AsNewCollection Dim c3 AsNewCollection Dim i AsInteger c1.Add "a" c1.Add "b" c1.Add "c" i = c1.Count c2.Add 0 c2.Add 1 c2.Add 2 c2.Add 3 i = c2.Count c3.Add 0 c3.Add "a" c3.Add 1 c3.Add "b" c3.Add 2 c3.Add "c" c3.Add 3 c3.Add "d" c3.Add 4 i = c3.Count Dim c AsNewCollection c.Add "Element1",1 MsgBox c(1) c.Remove (1)End Sub
C# code:
internalstaticclassModule1{publicstaticvoidMain() {OrderedDictionary c1 =newOrderedDictionary();OrderedDictionary c2 =newOrderedDictionary();OrderedDictionary c3 =newOrderedDictionary();c1.Add("a","a");c1.Add("b","b");c1.Add("c","c");int i =c1.Count;c2.Add(0,0);c2.Add(1,1);c2.Add(2,2);c2.Add(3,3); i =c2.Count;c3.Add(0,0);c3.Add("a","a");c3.Add(1,1);c3.Add("b","b");c3.Add(2,2);c3.Add("c","c");c3.Add(3,3);c3.Add("d","d");c3.Add(4,4); i =c3.Count;OrderedDictionary c =newOrderedDictionary();c.Add(1,"Element1"); //UPGRADE_WARNING: (1068) c(1) of type Variant is being forced to string.MessageBox.Show(Convert.ToString(c[0]),Application.ProductName);c.RemoveAt(0); }}
VB.NET code:
Module Module1Public Sub main() Dim c1 AsNewOrderedDictionary Dim c2 AsNewOrderedDictionary Dim c3 AsNewOrderedDictionary c1.Add("a","a") c1.Add("b","b") c1.Add("c","c") Dim i AsInteger= c1.Count c2.Add(0,0) c2.Add(1,1) c2.Add(2,2) c2.Add(3,3) i = c2.Count c3.Add(0,0) c3.Add("a","a") c3.Add(1,1) c3.Add("b","b") c3.Add(2,2) c3.Add("c","c") c3.Add(3,3) c3.Add("d","d") c3.Add(4,4) i = c3.Count Dim c AsNewOrderedDictionary c.Add(1,"Element1")'UPGRADE_WARNING: (1068) c(1) of type Variant is being forced to String.' MessageBox.Show(CStr(c(0)), Application.ProductName) c.RemoveAt(0) End Sub
15. Use TabControl Extension Class
Depending on other upgrade options such as MsComCtl mappings, the VBUC 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 VBUC'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
Public Sub TyperConflictTest()
Dim objVar1 As Variant
Dim objVar2 As Variant
objVar1 = 5
objVar1 = 10
objVar1 = 20
objVar1 = "100"
objVar2 = 5
objVar2 = "Test 1"
objVar2 = "Test 2"
End Sub
16.1 On
This is the default setting. By turning this feature on, the VBUC's Typer will determine that the type of the first variable should be an integer, and the second should be a string.
Public Sub TyperConflictTest()
Dim objVar1 As Integer = 5
objVar1 = 10
objVar1 = 20
objVar1 = 100
Dim objVar2 As String = CStr(5)
objVar2 = "Test 1"
objVar2 = "Test 2"
End Sub
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.
Public Sub TyperConflictTest()
Dim objVar1 As Object = 5
objVar1 = 10
objVar1 = 20
objVar1 = "100"
Dim objVar2 As Object = 5
objVar2 = "Test 1"
objVar2 = "Test 2"
End Sub