Upgrade
Wizard
Convert the Currency data type to Decimal, so the following code:
Dim x As Currency
After the upgrade, it will be changed:
Dim x As Decimal
Date
Visual
The Basic 6.0 Date variable is stored internally in the Double format and can be operated as a Double type variable.
The Date variable is stored as an IEEE 64-bit floating point number, which indicates the Date from January 1, January 1-9, 100 to January 1, December 31, 999 and the time from 0:00:00 to 23:59:59. Any identifiable text Date can be specified as the Date variable.
When other numeric types are converted to Date, the value on the left of the decimal point represents the Date information, while the value on the right of the decimal point represents the time information. Midnight is 0, noon is 0.5. The entire value is negative, indicating the date before January 1, December 30, 1899.
Visual Basic. NET
Date is internally stored as a 64-bit integer, so it cannot be operated directly as a Double .. NET Framework provides the ToOADate and FromOADate functions for conversion between Double and Date. The expression of date as an integer can simplify and accelerate operations on date.
Upgrade
Wizard
The upgrade tool does not detect the situation where all variables are used to store Date as Double, but it usually inserts the appropriate ToOADate or FromOADate method at the position where Double is specified as Date. For example, the following code:
Dim dbl As Double Dim dat As Date Dbl = dat
After the upgrade, it will be changed:
Dim dbl As Double Dim dat As Date Dbl = dat. ToOADate
Fixed Length string
Visual
Basic 6.0 except for the Public variables of the class module, other variables can be declared as fixed-length strings.
Visual Basic. NET
The first version of CLR does not support fixed-length strings. This feature will be added in subsequent versions.
Upgrade
Wizard
In most cases, no problem occurs. For a fixed-length string, run the following code:
Dim MyFixedLengthString As String * 100
After the upgrade, it will be changed:
Dim MyFixedLengthString As New VB6.FixedLengthString (100)
For a full description of this topic, see the White Paper prepare to upgrade the Visual Basic 6.0 Application to Visual Basic. NET ).
Type
Visual
Basic 6.0
The Type statement is used to define user-defined data types.
Visual Basic. NET
The names "Type" and "User-Defined Type" can be confused because classes, enumerations, and interfaces can also be User-Defined types. The types and User-Defined types are legacy from QuickBasic. In QuickBasic, only structures and records can be Defined. CLR uses the Type name to broadly include all data types.
Therefore, in Visual Basic. NET, the Type statement is changed to Structure.
Upgrade
Wizard
The following code changes the Type statement to Structure:
Type MyType MyVariable As Integer End Type
After the upgrade, it will be changed:
Structure MyType Dim MyVariable As Short End Structure
User-Defined type storage
Visual
Basic 6.0 a user-defined data type can contain one or more elements of a certain data type, array, or previously defined user-defined type. In Visual Basic 6.0, they are stored in contiguous memory blocks.
Visual Basic. NET
The format is the most effective. It may be located in a continuous memory or not. The structure can be marked as the sending and blocking processing attribute to ensure that it can be passed as a continuous memory block to the COM component.
Upgrade
Wizard
The API is marked with a TODO annotation for all the locations where the sending and sending processing attributes need to be added. (Attributes are not automatically added. They are required only when the structure is passed to the API .)
True
Visual
The value of Basic 6.0 True is-1.
Visual Basic. NET
The value of True is 1.
In view of coordinated language operations, a consistent representation is required for all languages.
Upgrade
Wizard
If you forcibly convert a Boolean value to a non-Boolean value, the code marks an update warning. For example, the following code:
Dim MyBoolean As BooleanDim MyInteger As Integer MyInteger = MyBoolean
After the upgrade, it will be changed:
Dim MyBoolean As BooleanDim MyInteger As Short UPGRADE_WARNING: Boolean MyBoolean is being converted into a numeric MyInteger = MyBoolean
Empty
Visual
Basic 6.0 variables are initialized to Empty. When used in a numeric expression, the variable is automatically converted to zero. When used in a string expression, the variable is automatically converted to a null string.
Visual Basic. NET
All object variables are initialized to Nothing. When used in a numeric expression, the variable is automatically converted to zero. When used in a string expression, the variable is automatically converted to a null string. Replacing the special Empty value with Nothing can reduce language complexity and enhance language collaboration.
Upgrade Wizard
Null and Null Propagation
Visual
Basic 6.0 Null is a subtype of Variant, indicating that the variable does not contain valid data. Null values are transmitted by expressions and functions ". If any part of the expression is Null, the entire expression is Null. When Null is passed as a parameter to most functions, these functions also return Null.
Visual Basic. NET
Null propagation is not supported. The model that uses ADO. NET to program data is used to check whether the value of a field is Null before retrieving the value of a field. Variables that contain null are sent to CLR as objects of the DBNull type.
Visual Basic. NET is more direct when processing Null: string functions (such as Left () always return strings, as expected.
Upgrade
Wizard
The Null value and the IsNull function are marked with Upgrade warning comments. For example, the following code:
If x Is Null Then MsgBox "Null"
After the upgrade, it will be changed:
UPGRADE_WARNING: Use of IsNull () detected If IsDBNull (x) Then MsgBox "Null"
Def <Type>
Visual
Basic 6.0 DefBool, DefByte, DefInt, DefLng, DefCur, DefSng, DefDbl, DefDec, DefDate, DefStr, DefObj, and DefVar are used to set variables, parameters, and process return types at the module starts with a specified character) the default data type.
Visual Basic. NET
This avoids the use of implicit type declarations, improving code readability and reliability.
Upgrade
Wizard
Insert the explicit declaration of the variable type into the code. For example, the following code:
DefStr a-z
Sub MySub
S = "Hello"
End Sub
After the upgrade, it will be changed:
Sub MySub
Dim s As String
S = "Hello"
End Sub
Local variables in the block
Visual
For Basic 6.0, local variables can be seen from the range of included declared rows to the end of the process.
Visual Basic. NET
Block range of variables supported by Visual Basic. NET. This means that local variables can be seen from the beginning of containing declared rows to the end of declared blocks. For example:
Sub Test (x As Integer)
If x <0 Then
Dim y As Integer =-x
...
Else
...
End If
End Sub
In the preceding example, the variable y is only available in the block where the variable is declared. More specifically, it is only available between its declaration and the Else statement. To use a variable throughout the process, the variable must be declared outside the If/Else/End If control structure.
The block range of variables is a common feature of many structured languages. Process local variables allow defining internal variables of a process to support structured programming. Similarly, block-level variables allow defining internal variables of a code block to support structured decomposition.
Upgrade
Wizard
If the variable is declared in the block, the variable is automatically moved to the module-level range. For example, the following code:
If x = 1 Then
Dim y As Integer
End If
After the upgrade, it will be changed:
Dim y As Integer
If x = 1 Then
End If
New auto-instantiation
Visual
Basic 6.0 form class variable declaration Dim x As New <classn