Type Inference
In Visual Basic 6.0 it is very common to use variables without an explicit declaration. The Visual Basic Upgrade Companion generates all the explicit, full-typed declarations for these variables avoiding the usage of generic data types (i.e. Object). The Artificial Intelligence-based type inference engine concludes the most appropriate data types for variables, parameters, fields and return values. The type inference is available for both VB.NET and C#.NET.
The Visual Basic Upgrade Companion is able to solve variable, method and inter-project scope typing issues. The resulting source code boasts full typed variable declarations and explicit castings (if necessary) for all the variables, based on their usage and programmatic behavior.
The typing issues are simple to fix in small scales, but its complexity raises when combined with late binding and unusual programming practices. The manual changes required to obtain functionally equivalent code will proportionally grow with the migration project size.
The Visual Basic Upgrade Companion will shorten the manual changes stage by providing pure, high quality and fully typed .NET source code; allowing the entire migration project to be executed in less time than expected, reducing the overall costs and assuring the highest ROI.
The following VB6 source code sample contains three non-typed and one fixed-length string variables being used and assigned in a particular way.
Original VB6 Source Code:
Private Sub typeInference()
Dim var1
Dim var2
Dim var3
Dim var4 As String * 50
var4 = App.Path & "\createDsn.ini" 'Declare your ini file !
var1 = ArgTypeInference(var2, var3, var4, Len(var4))
End Sub
Public Function ArgTypeInference(ByVal arg1 As Integer, ByVal arg2 As String, ByVal arg3 As String, ByVal arg4 As Integer)
MsgBox arg1
MsgBox arg2
MsgBox arg3
MsgBox arg4
ArgTypeInference = 1
End Function
Due to its advanced type inference mechanism, the Visual Basic Upgrade Companion’s resulting source code contains clearly defined data types. For this example, var1, var2 and var3 were typed based on their usage (Byte, Integer and String respectively). Also the “ArgTypeInference” function return value was upgraded to an explicit call of the “return” keyword.
VB.NET Code Generated by the Visual Basic Upgrade Companion
Private Sub typeInference()
Dim var2 As Integer
Dim var3 As String = ""
Dim var4 As New FixedLengthString(50)
var4.Value = My.Application.Info.DirectoryPath & "\createDsn.ini" 'Declare your ini file !
Dim var1 As Byte = ArgTypeInference(var2, var3, var4.Value, var4.Value.Length)
End Sub
Public Function ArgTypeInference(ByVal arg1 As Integer, ByVal arg2 As String, ByVal arg3 As String, ByVal arg4 As Integer) As Byte
MessageBox.Show(CStr(arg1), Application.ProductName)
MessageBox.Show(arg2, Application.ProductName)
MessageBox.Show(arg3, Application.ProductName)
MessageBox.Show(CStr(arg4), Application.ProductName)
Return 1
End Function
All the transformations applied in the previous example are available for C# source code generation as well.
C# Code Generated by the Visual Basic Upgrade Companion
private void typeInference()
{
int var2 = 0;
string var3 = String.Empty;
FixedLengthString var4 = new FixedLengthString(50);
var4.Value = Path.GetDirectoryName(Application.ExecutablePath) + "\\createDsn.ini"; //Declare your ini file !
int var1 = ArgTypeInference(var2, var3, var4.Value, var4.Value.Length);
}
public byte ArgTypeInference( int arg1, string arg2, string arg3, int arg4)
{
MessageBox.Show(arg1.ToString(), Application.ProductName);
MessageBox.Show(arg2, Application.ProductName);
MessageBox.Show(arg3, Application.ProductName);
MessageBox.Show(arg4.ToString(), Application.ProductName);
return 1;
}