Data Type Changes
The .NET Framework has classes that define the Common Type System that allow for data types to be consistent across applications written in different .NET languages. Because of this, Visual Basic needed to change the types of data it supports and numeric ranges of existing data types.
Variant not supported
In VB6, the Variant data type was the default universal data type; this was replaced by the Object data type in VB.NET. The default value for Object data type is Nothing, whereas the default value for Variant data types was Empty.
Dim variable1 as Variant
Changes to:
Dim variable2 as Object
Integer and Long
In VB6, the Integer data type was a 16-bit number, ranging in value from -32,767 to 32,767. The Short data type replaces Integer as a 32-bit number in VB.NET, and the Integer data type now ranges from -2,147,483,648 to 2,147,483,647. The Long data type is now a 64-bit number. Using Integer for 32-bit operations is the most efficient data type.
Dim x as Integer
Dim y as Long
Changes to:
Dim x as Short
Dim y as Integer
Currency not supported
The Currency data type is changed to decimal in VB.NET. Decimal is more accurate for rounding numbers, so the Decimal data type was created to handle currency operations. Currency was a 64-bit number, with 4 digits to the right of the decimal place. The new Decimal data type is a 96-bit signed integer and can have up to 28 digits to the right of the decimal place.
Dim x as Currency
Changes to:
Dim x as Decimal
Strings
Fixed-length strings are no longer supported.
DefType not supported
The DefType statement, which gives a default type for all variables declared without a type, is no longer supported. DefInt, DefStr, DefBool, and DefLng are no longer supported.
Arrays
One of the biggest issues when Microsoft announced the language changes in VB.NET was the lower-dimension arrays. From the beginning, Visual Basic has always allowed the lower bound of an array to be either 0 or 1. The Option Base statement, which is no longer supported, dictated whether all arrays should be treated as 0-based or 1-based. In the end, Microsoft decided that all arrays will have a default lower bound of 0, meaning that existing code using Option Base 1 statement will need to be revisited to ensure that there is no data loss or corruption, because the size of the array will be different.
Arrays cannot be fixed
Arrays cannot be declared as fixed sizes by specifying the lower and upper bounds at design time. You now declare just the upper bound to the array, with zero being the default lower bound.
Dim x (0 to 5) as string ‘ 6 item array
Changes to:
Dim x (5) as string ‘ 6 item array
Or
Dim x as string = new string(5) ‘ 6 item array
ReDim changed
The ReDim statement cannot be used in the declaration of any array variable. in VB.NET, you declare an array using Dim, and then use the ReDim statement to alter the bounds of the array.
The Value of True
In VB6, the value of true is -1. This is the same in VB.NET, however, in the CLR; the value of the true is equal to 1. When passing Boolean variables between languages in the .NET Framework, -1 will be true, and 1 in all other languages.
Operators
Some of the most exciting language changes in VB.NET have come in the category of operators. Table lists the new assignment operators, which will mean less typing for you when you are using operators.
EQV
The EQV operator is replaced with the “=” assignment operator.
Short-circuiting
The AndAlso and OrElse operators have been defined to handle short-circuiting. All other operators will remain the same. In short, circuiting means if the first part of an expression returns false, then remainder of the expression is ignored and false is returned.
Dim x as Integer = 5
Dim y as Integer = 6
Dim z as Integer = 7
ret = x > y AndAlso z > y ‘ Return false, 5 is not greater than 6
Assignment
VB.NET offers some cool new assignment operators.
Dim x as Integer
x = x + 1
Can now be changed to:
Dim x as Integer
x+=1
Operator | Action |
+= | Addition and concatenation |
-= | Subtraction |
*= | Multiplication |
/= and \= | Division |
^= | Exponentiation |
&= | String concatenation |
Null Values
Null propagation is not supported. Value types that are null are passed to functions as the DBNull data types. To test for null values, the IsNull statement is no longer supported. It is replaced with the DBNull statement.
If IsNull (field) then . . .
Changes to:
If IsDBNull (field) then . . .
The IsEmpty statement is not supported. In VB6, the values NULL and Empty could be used to check for a variable that has not been initialized or for a variable that contains no data. Null and Empty are no longer a valid means to check for this information, making IsEmpty obsolete. The nothing keyword should now be used to check for these conditions.
Variable Initialization
Variables can now be initialized to a value on the same line in which they are declared.
Dim x as integer
x = 5
Can be changed to:
Dim x as Integer = 5
Also, now you can declare multiple variables on the same line, with a single type
Dim str1, str2, str3 as String
Language Issues
One of the biggest defy when upgrading to VB.NET will be learning the replacements for existing functions.
IsMissing
The IsMissing function is no longer supported and is replaced with the IsNothing statement.
Date$ and Time$
The Date$ and Time$ functions in VB6 to return a string representation of the current date or time are replaced by the DateString and TimeString methods in VB.NET.
Procedures
Because VB.NET fully supports object-oriented features, there have been critical changes in procedure scope, returning values, and the type of procedures you can use.
Calling procedures
Calling procedures, either subs or functions, now require parentheses for the argument list, even if there are no arguments.
Sub test()
‘code
End Sub
Call test
Changes to:
Call test()
Static procedures
Static procedures are no longer supported. If you use static procedures , you should change them to regular subprocedures and define the variables within the static.
Static Sub Test()
Dim x as Integer
End Sub
Changes to
Sub Test()
Static x as Integer
End Sub
ByVal and ByRef
The default behavior of ByVal and ByRef has changed. In VB6, the default for passing parameters was ByRef. In VB.NET, ByVal is the default mechanism for passing variables to procedures.
While . . . Wend
The While … Wend construct is no longer supported. It is replaced with While … End While.
While x < 5
‘code
Wend
Changes to
While x < 5
‘code
End While
Caption property
The Caption property of label controls and forms is no longer supported. The Text property replaces the Caption property.
Label1.Caption = “VB.NET for developing applications”
Form1.Caption = “New Form”
Changes to:
Label1.Text = “VB.NET for developing applications”
Form1.Caption = “New Form”
Image Control
The image control is replaced with the PictureBox control in VB.NET.
Webclasses
Webclass applications are no longer supported. Web Forms applications should be used to write Web-based applications. The power and functionality provided in using Web Services and ASP.NET applications will give much more flexibility than programming Webclasses applications ever did.
Resource Used: VB.NET (Bible)
Compiled By: Chaudhary Amit V.
Really I understood about the new version of vb6..
ReplyDeleteI understand the diff.
thnks dear