An overview of new features in VB.NET compared to VB 6.0 |
Written on: Feb, 11th 2002. |
Introduction
VB.NET is not your regular new version of VB that added and modified technical features to core technology. VB.NET
is virtually a new programming language, based around new core technology - the .NET. The changes that took place are
so extensive that VB can now compete with Java, C++ and even C#. In this article, we will go through the major changes
that occured to VB.NET when compared to its previous versions.
Data Type Changes
First things first. The biggest change that took place is for Integer. The following table will illustrate the change.
| Integer Type |
VB 6.0 |
VB.NET |
| 8 bit |
Byte |
Byte |
| 16 bit |
Integer |
Short |
| 32 bit |
Long |
Integer |
| 64 bit |
Not Applicable |
Long |
Properties
In VB.NET, we anymore don't have seperate declarations for Get and Set/Let. Now, everything is done in a single property
declaration. This can be better explained by the following example.
Private _message as String
Public Property Message As String
Get
Return _message
End Get
Set
_message = Value
End Set
End Property
|
ByVal is the default
This is a crucial difference betwen VB 6.0 and VB.NET, where the default in VB 6.0 was by reference. But objects
are still passed by reference.
Invoking Subroutines
In previous versions of VB, only functions required the use of parentheses around the parameter list. But in
VB.NET all function or subroutine calls require parentheses around the parameter list. This also applies, even though
the parameter list is empty.
User-Defined Types
VB.NET does away with the keyword Type and replaces it with the keyword Structure
Public Structure Student
Dim strName as String
Dim strAge as Short
End Structure
|
Scoping
VB.NET now supports block-level scoping of variables. If your programs declare all of the variables at the begining of
the function or subroutine, this will not be a problem. However, the following VB 6.0 will cause an issue while upgrading
to VB .NET
Do While objRs.Eof
Dim J as Integer
J=0
If objRs("flag")="Y" then
J=1
End If
objRs.MoveNext
Wend
If J Then
Msgbox "Flag is Y"
End If
|
In the above example the variable J will become out of scope just after the loop, since J was declared inside the While loop.
Exception Handling
The most wanted feature in earlier versions of VB was its error handling mechanism. The older versions relied on error handlers
such as "On Error GoTo and On Error Resume Next. We really had a difficult time in tracking down the precise location of
errors due to this error handling mechanism. VB.NET provides us with a more stuructured approach. The new block structure
allows us to track the exact error at the right time. The new error handling mechanism is refered to as
Try...Throw...Catch...Finally. The following example will explain this new feature.
Sub myOpenFile()
Try
Open "myFile" For Output As #1
Write #1, myOutput
Catch
Kill "myFile"
Finally
Close #1
End try
End Sub
|
The keyword SET is gone
Since everything in VB.NET is an object. So the keyword SET is not at all used to differentiate between a simple variable
assignment and an object assignment. So, if you have the following statement in VB 6.0
Set ObjConn = Nothing
should be replaced as
ObjConn = Nothing.
Constructor and Destructor
The constructor procedure is one of the many new object-oriented features
of VB.NET. The constructor in VB.NET replaces the Class_Initialize in
VB 6.0. All occurance of Class_Initialize in previous versions of VB should now
be placed in a class constructor. In VB.NET, a constructor is added to a class by
adding a procedure called New. We can also create a class destructor, which is
equivalent to Class_Terminate event in VB 6.0, by adding a sub-procedure called
Finalize to our class.
Usage of Return
In VB.NET, we can use the keyword return to return a value from any function.
In previous versions, we used to assign the value back with the help of the function
name itself. The following example explains this:
Public Function Sum(intNum1 as Integer, intNum2 as Integer) as Integer
Dim intSum as Integer
intSum = intNum1 + intNum2
Return intSum
End Function
|
Summary
The above differences between VB 6.0 and VB.NET is only a few. Still there are so many
vital differences between them such as Versioning, Garbage Collection, Assembely etc
etc. We will cover these in an another article.
Links
Book Review - Professional VB.NET
10 Ways to Prepare for VB.NET
Transition from Visual Basic 6.0 to Visual Basic .NET
Send your comments to das@aspalliance.com
Back to Article list
|