Overview of Changes from VB6 to VB.NETBy Bipin Joshi
|To Learn More About ASP.NET...|
This article discusses the important language changes from VB6/VBScript to VB.NET. When creating
ASP.NET pages, you are required to use a .NET-compatible programming language, such as C#, VB.NET, or
JScript.NET. However, there are some significant changes from VB6/VBScript to VB.NET, which this article
addresses. To learn more about ASP.NET in general, be sure to check out the
ASP.NET Article Index!
Also, for more information be sure to check out Microsoft's article: Preparing Your Visual Basic 6.0 Applications for the Upgrade to Visual Basic.NET.
With release of Microsoft .NET platform, Visual Basic has emerged into a fully objected oriented language (dubbed VB.NET). With these radical changes, though, the learning curve between VB6 and VB.NET might be reasonably high even for experienced programmers. In this article I will try to list language changes to Visual Basic along with sample examples wherever appropriate. The list presented here may not be complete but it does cover majority of features. If you are a VB programmer wanting to shift to VB.NET this is a must read for you.
Note that currently (as of May 30th, 2001), ASP.NET is in Beta 1, which is freely downloadable from www.ASP.NET. However, some of the changes discussed in this article are changes that are proposed for the Beta 2 version, which is scheduled to be released to the public on June 17th. These areas that are new to Beta 2 (and therefore will not work with the Beta 1 version of ASP.NET) are marked.
Data Type Changes
The .NET platform provides Common Type System to all the supported languages. This means that all the languages must support the same data types as enforced by common language runtime. This eliminates data type incompatibilities between various languages. For example on the 32-bit Windows platform, the integer data type takes 4 bytes in languages like C++ whereas in VB it takes 2 bytes. Following are the main changes related to data types in VB.NET:
- Under .NET the Integer data type in VB.NET is also 4 bytes in size.
- VB.NET has no currency data type. Instead it provides decimal as a replacement.
- VB.NET introduces a new data type called Char. The char data type takes 2 bytes and can store
- VB.NET do not have Variant data type. To achieve a result similar to variant type you can use Object
data type. (Since every thing in .NET - including primitive data types - is an object, a variable of object type
can point to any data type).
- In VB.NET there is no concept of fixed length strings.
- In VB6 we used the
Typekeyword to declare our user defined structures. VB.NET introduces the
structurekeyword for the same purpose. The rest of the syntax is same. That is:
Consider this simple example in VB6:
In this example VB6 will consider
x as variant and
y as integer, which is somewhat odd
behavior. VB.NET corrects this problem, creating both
y as integers. Furthermore,
VB.NET allows you to assign initial values to the variables in the declaration statement itself:
VB.NET also introduces Read-Only variables. Unlike constants Read-Only variables can be declared without initialization but once you assign a value to it, it can not be changed.
With VB6, you could programmatically define the lower and upper bounds of an array. In VB.NET, however, an array's lower bound is always zero. Also, when defining an array like so:
in actuality, 51 elements are being created, with 0 as the lower bound and 50 as the upper bound! (Note that in Beta 1 of the VB.NET compiler, the above statement would create 50 elements, from bounds 0 through 49.)
In Part 2 we'll continue our examination of VB.NET's new (and breaking) features!