Type inference
In Visual Basic 6.0 it is very common to use variables without declaring them. When the Upgrade Wizard finds variables without a declaration, it writes Error Warning and Issue (EWI) 1037 (UPGRADE_WARNING: Couldn't resolve default property of object ‘x’) for every use of the variable as shown in the example below. The variable declaration upgrade warning can occur frequently in some VB projects. It typically represents 30% to 40% of total EWIs. The Visual Basic Upgrade Companion can eliminate most of the occurrences of this upgrade warning. This reduction represents about 10% to 20% of the total EWIS, depending on the design of the project.
Example: Variable Declaration
In this example the Upgrade Wizard declares all variables as Object while the Visual Basic Upgrade Companion declares them as Byte.
Visual Basic 6.0 code
PrivateSub Command1_Click()
a=5
b = 10
c = 5 + 10
EndSub
VB.NET: Upgrade Wizard generated code (with variable declaration upgrade warning)
Private Sub Command1_Click(ByVal eventSender As System.Object, …
Dim c As Object
Dim b As Object
Dim a As Object
'UPGRADE_WARNING: Couldn't resolve default property of object a.
a=5
'UPGRADE_WARNING: Couldn't resolve default property of object b.
b = 10
'UPGRADE_WARNING: Couldn't resolve default property of object c.
c = 5 + 10
End Sub
VB.NET: Visual Basic Upgrade Companion generated code (no upgrade warning!)
Private Sub Command1_Click(...) Handles Command1.Click
Dim a As Byte =5
Dim b As Byte = 10
Dim c As Byte = 5 + 10
End Sub
C#: Visual Basic Upgrade Companion generated code (no upgrade warning!)
private void Command1_Click(…)
byte a = 5;
byte b = 10;
byte c = 5 + 10;
Example: Function parameters
The function "fibonnacci" in VB6 is declared without return type. Also variable "j" does not have a specific type. Since both the function and the parameter don’t have a type, the Upgrade Wizard declares them as an Object.
The Visual Basic Upgrade Companion analyzes the function and determines that the return type is Integer and the type of parameter "j" is Byte.
Visual Basic 6.0 code
Public Function fibonnacci(j)
If j = 0 Or j = 1 Then
fibonnacci = 1
Else
fibonnacci = fibonnacci(j -1) + fibonnacci(j -2)
End If
End Function
VB.NET: Upgrade Wizard generated code (with variable declaration upgrade warning)
Public Function fibonnacci(ByRef j As Object) As Object
'UPGRADE_WARNING: Couldn't resolve default property of object j.
If j = 0 Or j = 1 Then
'UPGRADE_WARNING: 'Couldn't resolve default property of object fibonnacci.'
fibonnacci = 1
Else
'UPGRADE_WARNING: 'Couldn't resolve default property of property of object j.
'UPGRADE_WARNING: 'Couldn't resolve default property of object fibonnacci(j -2).
'UPGRADE_WARNING: 'Couldn't resolve default property of object fibonnacci().
'UPGRADE_WARNING: 'Couldn't resolve default property of object fibonnacci.
fibonnacci = fibonnacci(j -1) + fibonnacci(j -2)
End If
End Function
VB.NET: Visual Basic Upgrade Companion generated code (no upgrade warning!)
Public Function fibonnacci(ByVal j As Byte) As Integer
If j = 0 Or j = 1 Then
Return 1
Else
Return fibonnacci(j -1) + fibonnacci(j -2)
End If
End Function
C#: Visual Basic Upgrade Companion generated code (no upgrade warning!)
public int fibonnacci(byte j)
if (j == 0 || j == 1)
return 1;
else
return fibonnacci(j -1) + fibonnacci(j -2);
}