Overview of Changes from VB6 to VB.NET, Part 3
By Bipin Joshi
In Part 2 we continued our examination of VB.NET's new features, looking
at varaible scoping, default object properties, the Set and Let keywords, and
error handling. In this third and final part, we'll complete our study of VB.NET's new features.
Static Methods
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 Static(),
you could call the Static() method like so:
Foo.Static()
|
However, non-static methods require than an instance of the class be created, like so:
'Create an instance of the Foo class
|
To create a static method in a VB.NET class, simply prefix the method definition with the keyword Shared.
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.
Property Syntax
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,
within the Set portion of the Property statement the variable Value
indicates the value entered by the user when assigning a value to the indicated property.
|
Conclusion
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,
use
Dim i as Integerinstead of justDim 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
means
Response.Write "Hello, World!"will generate an error. Rather, you need to place parenthesis around the parameter you are passing into the function:Response.Write("Hello, World!")
- 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).
Happy Programming!
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
bipinjoshi@yahoo.com.



