Programming avoids null propagation (propagation)
Previous versions of VB support null propagation. Null propagation is provided that null values are used in the table
In the formula, the result of the expression will be null, such as the following example, and the result V will be null
Dim V
V = 1 + Null
V = Null + right$ ("Sometext", 1)
V = Right ("Sometext", 0)
Null propagation will no longer be supported in Visual Basic.NET. Like the statement above
1+null will produce a type error. Additionally, in Visual Basic 6.0, there are two functions that are left-left$ The return value is a variant and can be empty, and the left$ function returns a string type. In Visual Basic.NET, there is only a left function that always returns a string type value
To make your program compatible with Visual Basic 6.0 and Visual Basic.NET, you need to
To include code for null detection in your code, in Visual Basic.NET, the following function will no longer return null values:
CHR Mid
Command Oct
CurDir Right
Date RTrim
Environ Space
Error STR
Hex time
LCase Trim
LTrim UCase
Because the data in the database can contain null values, you need to get the
The data entry code detects whether the value is null.
Use an array with a lower bound of 0
Visual Basic 6.0 allows you to use any integer number as an upper bound of an array
and lower bound. You can also redefine a variant to an array by ReDim. In order to be able to share. NET platform, the Visual Basic.NET array must be in the lower bound of 0, and only one variable can be redefined with the ReDim function before it is previously defined as an array. Although this limits the flexibility of array definitions, this allows you to pass arrays between Visual Basic.NET and other languages under. Net. The following example illustrates the new constraint for defining an array:
Dim A (1 to ten) as Integer ' ERROR: Lower bound must be 0
Dim V
ReDim V (10) ' Error, cannot use ReDim before undefined V is set
Dim B (Ten) as Integer ' correct
ReDim B (5) as Integer ' correct
In addition, in Visual Basic 6.0, Dim (0 to ten) As Integer
An array containing 11 integers, indexed from 0 to 10. Same
is defined under Visual Basic.NET to create an array of 10 integers, indexed from
0 to 9.
Based on the changes above, Option Base 0|1 has been removed from the Visual Basic.NET
deleted.
When your code is upgraded to Visual Basic.NET, an array with a lower bound of 0 will not
Change. If the lower bound of the array is not 0, the array is upgraded to a compatible class, as follows:
Dim A (1 to ten) as Integer
Change to:
Dim A as Object = New VB6. Array (GetType (short), 1,10)
Compatible array analogy the local array is much slower to operate, and it is used in the program
There are also restrictions. For example, you cannot pass a compatible array class as an argument to a function that takes an array as an argument, nor can you pass a compatible class to Visual C # or the Visual C + + class.
For the above reasons, you need to use 0 in your Visual Basic 6.0 code
As an array of lower bounds, avoid using ReDim to define arrays and avoid using the option Base 1 statement.
Use VB constants instead of using the values they represent when writing code, try to use VB constants instead of using the values they represent. For example, to maximize a window at run time, use:
Me.windowstate = vbmaximized ' good:constant name
And do not use:
Me.windowstyle = 2 ' bad:underlying value
Me.windowstyle = X ' bad:variable
In Visual Basic.NET, the values of some properties and constants have changed;
A value such as true is changed from-1 to 1. Most constants change automatically after your code has been upgraded to Visual Basic.NET, but if you're using a constant-represented value instead of a constant name, you'll have to do a lot of manual change work.
Array and fixed-length strings in user-defined data types
To make Visual Basic.NET arrays and data structures fully compatible with visual
Studio.NET, fixed-length strings are no longer supported in the new language. In most cases the person is not a problem because Visual Basic.NET provides a class that is compatible with fixed-length string definitions, then code:
Dim myfixedlengthstring as String * 100
This will become the case after the upgrade:
Dim myfixedlengthstring as New VB6. Fixedlengthstring (100)
However, fixed-length characters are used in data structures (such as user-defined data)
A string class may produce an error. Because the class is not built when user-defined data structures are established. Fixed-length arrays in user-defined data can also have the same problem.
When your code is upgraded, the user-defined data type in the code if there is a solid
Fixed-length arrays and strings, add a comment at the defined position to remind you to initialize the string or array first before using the user-defined data type. However, you can change the fixed-length string definition to a string definition in your Visual Basic 6.0 user-defined type, changing the fixed-length array definition to an uninitialized array
Avoid the problems that arise when the upgrade is generated. For example:
Private Type MyType
MyArray (5) as Integer
Myfixedstring as String * 100
End Type
Sub Bar ()
Dim myvariable as MyType
End Sub
The upgrade will change to:
Private Type MyType
MyArray () as Integer
Myfixedstring as String
End Type
Sub Bar ()
Dim myvariable as MyType
ReDim Myvariable.myarray (5) as Integer
myvariable.myfixedstring = string$ (100, "")
End Sub
Avoid Legacy Features
Avoid using attributes inherited from the original basic, such as the following keywords in the new version language
No longer appear:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.