Overview of Changes from VB6 to VB.NET, Part 3By Bipin Joshi
In Part 2 we continued our examination of VB.NET's new features, looking
at varaible scoping, default object properties, the
Let keywords, and
error handling. In this third and final part, we'll complete our study of VB.NET's new features.
VB.NET now allows you to create static methods in your classes. Static methods are methods that can be called without requiring the developer to create an instance of the class. For example, if you had a class named
Foo with the non-static method
NonStatic() and the static method
you could call the
Static() method like so:
However, non-static methods require than an instance of the class be created, like so:
To create a static method in a VB.NET class, simply prefix the method definition with the keyword
Procedures and Functions
In VB6 all the procedure parameters are passed by reference (
ByRef) by default. In VB.NET they are
passed by value (
ByVal) by default. Parentheses are required for calling procedures and functions
whether they accept any parameters or not. In VB6 functions returned values using syntax like:
FunctionName = return_value.
In VB.NET you can use the
Return keyword (
Return return_value) to return values
or you can continue to use the older syntax, which is still valid.
In VB6 we used
Property Get and
property Set/Let for creating properties in classes. The
two appeared as separate routines:
In VB.NET the syntax changes quite a bit. Rather than having two separate
Property Get and
Property Let/Set statements, these are combined into one
Property statement. Also,
Set portion of the
Property statement the variable
indicates the value entered by the user when assigning a value to the indicated property.
There are some changes to VB.NET's semantics and syntax, but these are the most important changes that you, as an ASP.NET developer, will come across. The most important things to keep in mind when working with VB.NET to create ASP.NET Web pages are:
- Variables can be typed and are no longer all Variants. That is, if you need an Integer variable,
Dim i as Integerinstead of just
Dim i. (Typing your variables leads to tremendous performance increases over untyped variables.)
- Remember that VB.NET requires that subroutine calls have parenthesis around the calling parameters! That
Response.Write "Hello, World!"will generate an error. Rather, you need to place parenthesis around the parameter you are passing into the function:
- VB.NET no longer supports default properties - you must explicitly specify the property you wish to
access from an object.
- Be careful when declaring arrays. As aforementioned, all arrays in VB.NET have a lower bound of zero, and an upper bound of the number you specify (resulting in one more element than you may have thought you had when creating the array).
About the author
Bipin Joshi is a Software Engineer working in Mumbai (India). His personal web site at www.bipinjoshi.com provides lot of .NET-related information. He also contributes to other Web sites in the form of articles, tutorials and source code. He can be reached at email@example.com.