BYTEINSIGHT
GAPVelocity AI Studio helps you move from outdated tech stacks to the latest desktop, web, and cloud platforms—smarter, faster, and with less risk.
Choose a platform to see migration options:
Our comprehensive approach to application modernization, from assessment to production deployment.
Transformation Services
Not Sure Where to Start?
Several data type concepts are incompatible in VB6 and .NET. The restrictions become increasingly complex when interactions between different data types arise (enums with integers, dates with strings, assignments between arrays with different bounds, etc.), and especially when late binding is present through generic data types like Variant, Form, Control, etc.
Several scenarios related to this data type information have been covered by conversion patterns in the VB6 AI Migrator. Some of them are described in this section.
Additional support for the VB6 function TypeName was added in version 4.0.
The TypeName function is converted to the “is’ operator when used TypeName is used in a conditional statement.
Literal string values for types are changed to the corresponding type in .NET.
Private Sub DisplayTypeName(ByVal obj As Object)
If TypeName(obj) = "Integer" Then
MsgBox("Integer")
End If
If TypeName(obj) = "String" Then
MsgBox("String")
End If
If TypeName(obj) = "CommandButton" Then
MsgBox("CommandButton")
End If
If TypeName(obj) = "myClass" Then
MsgBox("myClass")
End If
End Sub
private void DisplayTypeName( object obj)
{
if (obj is int)
{
MessageBox.Show("Integer", Application.ProductName);
}
if (obj is string)
{
MessageBox.Show("String", Application.ProductName);
}
if (obj is Button)
{
MessageBox.Show("CommandButton", Application.ProductName);
}
if (obj is myClass)
{
MessageBox.Show("myClass", Application.ProductName);
}
}
The VB6 AI Migrator has a module for recognizing coercion requirements and generating the appropriate conversions for the expressions involved. Some of these scenarios include:
The arrays conversion can be particularly complex because they can be dimensioned and re-dimensioned several times with different bounds. The option base 0 or 1 is also a source of confusion, changing the default lower bounds that can be combined and interchanged later in some array references.
The .NET arrays must be regular, must have a lower bound equal to zero and cannot change their amount of dimensions, although they might change the dimension magnitudes. In order to resolve these inconsistencies, an analysis is performed upon all the arrays, declarations, redims and accesses, figuring out what the array bounds should be and whether they are used in a regular way or not. This information allows the VB6 AI Migrator to make decisions about how to declare the array in .NET, how to do the re-dimensioning processes and whether to apply corrections to the indexes used to access the array or not.
For the most difficult cases, where a reference to array is used with inconsistent dimensions or inconsistent lower bounds, the class Array is used to represent a much more flexible concept of the data type and all its references are modified accordingly.
The type Integer in VB6 corresponds to a 16-bits integer number, and the equivalent type in .NET would be a short. However it could be better to keep these variables as int in .NET, mainly because so many expressions return int and would need a cast before being assigned to a short variable. Some examples of these expressions are:
The two cases above are so common that many conversions look much better when the Integer variables are converted to int. However, some cases where the behavior of overflowing operations should be preserved require that Integers are converted to the equivalent .NET 16-bit short. In those cases the necessary casting are automatically generated by the VB6 AI Migrator.
The VB6 AI Migrator can be configured to choose any of these two choices. By default it converts integer to integer.
In comparisons, when one of the operands is an enum and the other operand is a numeric value corresponding to an actual value of the enumerate type, the numeric value is changed by the corresponding enum value, and it is translated to its equivalent in .NET, if there’s any. The comparison operator is also changed to either Is or Not Is.
Enum values cannot be sent byref in .NET. A temporal variable is created in those cases to make the application compile and run properly.
A set of rules have been added to generate the appropriate transformations when using enumerates as integers or other primitive types. Other rules correct the uses of other primitives as enums, converting them to the corresponding integer value and, if possible, substituting literal values with the corresponding enumerate field.
Visual basic 6.0 fixed size strings are converted using the InteropServices.MarshalAs attribute:
Dim s as string *20
System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=20) Dim s as string;
System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=20) string s;