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
The class variable declaration dim X as new <classname> in BASIC 6.0 forms will generate code every time the compiler references X. This code checks whether X is nothing; if it is nothing, a new instance of the class is created. For example, the following code:
Dim X as new myclass
'...
Call X. mymethod ()
Equivalent:
Dim X as myclass
'...
If X is nothing then
Set x = new myclass
End if
Call X. mymethod ()
Even if the variable has been set to nothing, the variable will be re-instantiated in the next call.
Visual Basic. net
The form variable declaration dim X as new <classname> is equivalent to dim X as <classname> = new <classname>. Variables referenced through this syntax do not generate special code.
Visual Basic. Net declaration as new is more effective than the same declaration in Visual Basic 6.0. Most references to such variables do not require additional overhead. Moreover, the "automatic instantiation" behavior of Visual Basic 6.0 is odd for many programmers who find it.
Upgrade
Wizard
This rarely becomes a problem. However, if the code tries to use a class that has been set to nothing, it will cause a runtime exception. This exception is easily detected. Then, you can easily modify the code to instantiate the new version of the class, as shown in the following example:
Dim X as new myclass
X = nothing
X = new myclass
Object termination
Visual
The basic 6.0 com reference counting mechanism is used for garbage collection object instances. If the object is not in a loop and the object is no longer in use, the reference count immediately detects this situation and runs the final code.
Visual Basic. net
The tracking Garbage Collector starts from the availability and reference of the objects stored in the stack variables, module variables, and shared variables. This tracking process runs as a background task. Therefore, there is an indefinite period between the end of the last reference pointing to the object and adding a new reference.
In some cases, the client must be able to force an object to release resources. CLR specifies that such an object should implement the idisposable interface, which provides the dispose method. When the client ends its use of an object with the dispose method, it can explicitly call the dispose method to release its resources. For example, the dispose method should be disclosed to the object that wraps the database connection.
The tracking garbage collector can correctly release objects in the reference loop. In addition, the performance of the tracking garbage collector is much better than the reference count.
Upgrade
Wizard
In most cases, this change will not cause problems. If your code is open with a resource handle (connection or file handle), you must explicitly close this handle. This issue is easy to detect and can cause runtime errors.
Array
Visual
The basic 6.0 array can be limited by the upper and lower limits of any integer number. If no lower limit is specified in the declaration, the default lower limit is determined using the option base statement.
Visual Basic. net
To work with other languages, the lower limit of all arrays must be zero. In this way, the option base statement is no longer required.
Upgrade
Wizard
Redim
Visual
The fixed size array in BASIC 6.0 Visual Basic 6.0 differs from the variable size array. The fixed-size array is declared through the dim statement. This statement includes the array boundary in this Declaration. The dynamic array is declared in the dim statement without specifying the limit information. Before using a dynamic array, you must use the redim statement to relabel the dynamic array. In Visual Basic 6.0, the redim statement provides a shortcut for dynamic array declaration and space allocation in a single statement. The redim statement is the only statement in Visual Basic 6.0 that can declare and initialize variables simultaneously.
Visual Basic. net
The redim statement is only used to allocate or re-allocate space for arrays, but not for re-allocating arrays. This is because all arrays in Visual Basic. NET are dynamic. in Visual Basic. net, dim statements can be used to declare dynamic arrays and initialize dynamic arrays.
Since all variable declarations can declare variables and specify the initial values of variables, simultaneous declaration and initialization of variables using redim becomes redundant and unnecessary. You only need the dim statement to declare variables to make the language simpler and more consistent.
Upgrade
Wizard
If redim () is used to declare an array, the corresponding declaration is automatically inserted in the code. However, the best way is to insert the dim statement into the array first, because to declare the Array Using redim, You need to upgrade the tool to infer the correct declaration. Using redim also produces inconvenient code, because the array is declared in the same way.
Assignment
Visual
Basic 6.0 has two assignment modes: Let assignment (default) and set assignment. Assign a value to CN using the set statement.
Visual Basic. net
There is only one form of value assignment. X = y means that the value of the variable or attribute y is assigned to the variable or attribute X. The value of an object type variable is a reference to an object instance. Therefore, if X and Y are referenced variables, a value is assigned for reference. This single form of assignment reduces the complexity of the language and makes the code more readable.
Upgrade Wizard
Delete the set and let statements. Parse the default attributes of a strongly typed object and explicitly add the attributes to the code.
For a full description of this topic, see the White Paper prepare to upgrade the Visual Basic 6.0 Application to Visual Basic. net ).
And, Or, XOR, and not
Visual
Basic 6.0 and, Or, XOR, and not operators can perform logical or bitwise operations (depending on expressions ).
Visual Basic. net
And, or, and XOR are only applicable to the boolean type. For the and or operators, if the value of the first operation is sufficient to determine the result of the operator, the calculation is simplified. The new operators bitor, bitand, and bitxor are used for bit logical operations. Bitxxx operator is not simplified.
Upgrade
Wizard
If the and/or statement is non-Boolean or contains a function, method, or attribute, this statement is upgraded to a compatibility function, which is the same as the expression in Visual Basic 6.0. If the and/or statement is Boolean, this statement is upgraded to a local Visual Basic. Net statement.
For a full description of this topic, see the White Paper prepare to upgrade the Visual Basic 6.0 Application to Visual Basic. net ).
Operator priority
Visual
In basic 6.0, the and, Or, XOR, and not operators of logic and bits take precedence over comparison operators.
Visual Basic. net
And, Or, XOR, and not operators have lower priority than comparison operators, so A> B and A <C is considered as (A> B) and (A <C ). The new bitand, bitor, and bitxor operators have higher priority than the comparison operators. Therefore, a bitand & hffff <> 0 is considered to be (a bitand & hffff) <> 0 ).
Since bitand, bitor, and bitnot operators can return numerical results, their priority is higher than that of Relational operators. In this way, the results returned by these operators can be compared with other values.
Upgrade
Wizard
Processed by the Upgrade Wizard. For a full description of this topic, see the White Paper prepare to upgrade the Visual Basic 6.0 Application to Visual Basic. net ).
Call Process
Visual
Basic 6.0 supports two types of process calls: one is a call statement, which must enclose the parameter list in parentheses; the other is a call statement, parameter lists cannot be enclosed by parentheses.
In Visual Basic 6.0, a common condition is that the developer does not use keywords in the call process, but uses parentheses outside the parameter list. Fortunately, when there is more than one parameter, the compiler will detect it as a syntax error. However, when there is only one parameter, brackets outside a single parameter will pass the parameter variable as byval rather than byref. This may cause small bugs that are hard to find.
Visual Basic. net
Brackets are required for the parameter list in all cases.
Upgrade Wizard
Insert parentheses for a process without parentheses.
Static Process
Visual
Basic 6.0 uses the static keyword to declare a process. This keyword indicates the local variables in the Process of reservation between calls.
Visual Basic. net
Static keywords are not supported during the process, and all static local variables must be explicitly declared using static statements.
It is rare to declare all variables in the process as static. Deleting this feature simplifies the language and improves readability, because local variables are always in the stack unless explicitly declared as static.
Upgrade
Wizard
If the process is marked as static, all local variables are changed to static.
Default Value of the parameter byval/byref
Visual
When the basic 6.0 parameter does not specify its default value as byval or byref, its default value is byref.
Visual Basic. net
<When the default value of the parameter is not specified as byval or byref, the default value is byval.
If you specify the default value of a parameter as byval instead of byref, the variables transmitted by the caller are not modified incorrectly. This also makes the default call rule consistent with the value assignment, so that the parameter can be effectively bound to the expression (assign a value to the formal parameter through the expression ).
Avoid confusion caused by Visual Basic 6.0 upgrade to Visual Basic. net. If the parameter declaration you enter does not explicitly specify its default value as byval or byref, IDE automatically adds the byval keyword to it.
Upgrade
Wizard
Add byref to a parameter without the default value of byval or byref.
Ismissing parameters and optional parameters
Visual
The optional Variant Parameter without a default value in BASIC 6.0 will be initialized as a special error code, which can be detected by the ismissing function.
Visual Basic. net
In Visual Basic. net, all optional parameters must specify the default value. This reduces the number of special values in the language and simplifies the language.
Upgrade
Wizard
The ismissing function is replaced by the isnothing function and marked with an update warning comment.
Paramarray Parameters
Visual
Basic 6.0 when a variable is passed to the paramarray parameter, it can be modified through the called function. The byval paramarray element is not supported.
Visual Basic. net
When a variable is passed to the paramarray parameter, it cannot be modified through the called function. The byref paramarray element is not supported.
The most common condition of paramarray parameters is that the variables passed to this parameter are not modified. The byref paramarray parameter is not supported to simplify the paramarray calling rules, because the paramarray parameter will be specified as a normal array. In this way, the paramarray parameter can be extended to any element type, and functions requiring the paramarray parameter can be directly called through arrays (rather than parameter lists.