To read the article online, visit http://www.4GuysFromRolla.com/webtech/053001-1.3.shtml

Overview of Changes from VB6 to VB.NET, Part 3

By Bipin Joshi


  • Read Part 1
  • Read Part 2

  • 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
    Dim objFoo as New Foo()

    'Execute the NonStatic() method
    objFoo.NonStatic()

    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:

    Public Property Get PropertyName() as DataType
      ...
    End Property
    
    Public Property Let PropertyName(value as DataType)
      ...
    End Property
    

    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.

    Public [ReadOnly|WriteOnly] Property PropertyName as DataType
      Get
        Return m_var
      End Get
    	
      Set
        M_var = Value
      End Set
    End 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:

    1. Variables can be typed and are no longer all Variants. That is, if you need an Integer variable, use Dim i as Integer instead of just Dim i. (Typing your variables leads to tremendous performance increases over untyped variables.)
    2. 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!")
    3. VB.NET no longer supports default properties - you must explicitly specify the property you wish to access from an object.
    4. 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!

  • By Bipin Joshi


    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.


  • Article Information
    Article Title: Overview of Changes from VB6 to VB.NET, Part 3
    Article Author: Bipin Joshi
    Published Date: Wednesday, May 30, 2001
    Article URL: http://www.4GuysFromRolla.com/webtech/053001-1.3.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers