WindowsDevCenter.com
oreilly.comSafari Books Online.Conferences.

advertisement


AddThis Social Bookmark Button

To VB .NET or Not to VB .NET

by Steven Roman
08/14/2001

Related Reading

VB.NET Language in a Nutshell
By Steven Roman, Ron Petrusha, Paul Lomax

If you are a Visual Basic programmer using VB6 (or earlier), then sooner or later you will need to wrestle with the decision of whether or not to upgrade to VB .NET 1. I say sooner or later because you may be able to postpone the decision for some time, perhaps even a year or more. But the longer you wait, the more likely it is that you will put yourself in the position of having to upgrade in a hurry. Put another way, now is the perfect time to slowly migrate to VB .NET. I consider this a word to the wise.

There are really two decisions to be made here: whether or not to upgrade existing applications and whether or not to develop new applications in VB .NET.

As for existing applications, I have mixed feelings. On the one hand, I try my best to abide by the adage, "Don't fix it if it isn't broken." Indeed, I can't think of any area more suited to this adage than personal computing. If your hardware works, don't fuss with it. If your software works, don't fuss with it. If you programs work, don't fuss with them.

Of course, like all adages, this one is an oversimplification. I have several functioning VB6 programs, such as my Object Model Browser software, that provide structured views of type libraries. I worked very hard developing the Object Model Browser program, digging more deeply than I ever wanted to into the idiosyncrasies of COM and type libraries, and I would hate to have to migrate this program under pressure. (During the writing of VB .NET Language in a Nutshell, I had a few cauchemars in which Microsoft makes the following announcement: "Oh, by the way, on December 31, 2001, VB6 programs will no longer function, so you better get started moving your applications right away. Have a nice day, and don't forget to buy Microsoft!" Fortunately, this was just a nightmare, I hope.)


Check out O'Reilly's new .NET Resource Center for the latest articles and books covering Microsoft's .NET technology.

On the other hand, I am slowly moving my major applications, including the Object Model Browser, to VB .NET, in my spare time, you might say. After all, I can afford now to take my time, and it is a great way to practice VB .NET programming.

So I say, with respect to existing programs, why not choose a good one and start migrating it to VB .NET now, while it is not really necessary to do so? This will give you a valuable edge when the time comes to dump legacy versions of VB. (How many of us have VB3, VB4, VB5, and VB6 on our computers?)

As for new applications, there are much more compelling reasons to begin using VB .NET as soon as possible.

Before articulating a few of them, I should echo something you have probably heard many times, namely, VB .NET is a big change from VB6 and there will be a sharp learning curve at first. Even this issue leaves me with mixed feelings.

On the one hand, I am glad that Microsoft has seen fit to make these changes to VB. For the most part, they are welcome. In fact, I wish Microsoft had not backed off on a few of these language changes between Beta1 and Beta2. For instance, in Beta1, Microsoft added the bitwise operators BitAnd, BitOr, and BitNot and restricted the older And, Or, and Not operators to boolean operands only--as it should be. However, Microsoft subsequently claimed that too many people fussed and so they backed off. I really don't understand this. Many of the changes to VB .NET are going to cause far more grief than this one. Why back off on something as simple and reasonable as this?

On the other hand, I am annoyed at Microsoft for not making many of these changes earlier, or in fact, not incorporating them in the original version of VB. One example is the bitwise- and logical-operator issue. In my opinion, Microsoft should have done this right in the first version of VB!

So, what is so nice about VB .NET?

First, there are the changes to the basic language syntax. Here are a few examples:

  • The variable declaration makes more sense. For instance, the code:

    Dim x, y As Integer
    declares both x and y as Integers.

  • We can now initialize a variable on the same line as its declaration, as in:

    Dim x As Integer = 5
    This also applies to arrays:
    Dim Days() As Integer = {1, 2, 3, 4, 5, 6, 7}

  • There is now a Return statement to be used within functions, as in:

    Public Function Test(x As Integer) As Integer
       If x > 0 Then
          Return x
       Else
          Return (-x)
       End If
    End Function
    

Another big change is in error handling. VB .NET supports the Microsoft C-style, structured error handling: Try...Catch...Finally. Frankly, I'm glad VB still supports the unstructured On Error error handling. I have not yet seen a compelling reason to switch, and so, for now, it's one issue I am not going to worry about.

Perhaps the most talked about change is the addition of two major new object-oriented tricks: inheritance and overloading. For me, inheritance is nice but I don't expect to use it very often. On the other hand, I really like overloading and can't wait to make full use of it.

The real power of the new VB .NET is in the fact that it has full access to the .NET Base Class Library. The .NET Base Class Library (BCL) consists of several thousand classes and other data types (such as interfaces, structures, and enumerations) that are divided into about 90 namespaces. In fact, the VB .NET language itself is implemented as a set of classes belonging to the Microsoft.VisualBasic namespace. (The C# and JScript languages are also implemented as a set of classes in corresponding namespaces.) For the most part, we don't need to use the classes in the Microsoft.VisualBasic namespace directly because VB wraps them up for us nicely. In fact, VB .NET can be defined largely as a wrapper for the classes in the Microsoft.VisualBasic namespace.


Visual Basic and the Kremlinologists--Bill Gates' Tech Ed 2001 keynote speech inspired O'Reilly Visual Basic editor Ron Petrusha to reflect on what many Visual Basic programmers have in common with Cold War Kremlinologists.

The BCL has classes that enhance the power of the language: for example, classes for manipulating arrays, doing bitwise operations on higher data structures, and programming collections such as stacks, queues, and hash tables. The BCL also provides classes that allow VB programmers to access the power of the operating system in a manner similar to that of the Win32 API. For instance, we can get the version of the operating system, manipulate files and folders (in a manner similar to the Scripting Runtime), manipulate the Registry (if you dare), monitor system events, and a lot more.

It is pretty clear that VB .NET is a significant step forward--one that is long overdue. On the other hand, in some sense it doesn't really matter; sooner or later we must all join the Microsoft bandwagon. After all, like it or not, Microsoft has a monopoly. Right?

Footnote

  1. Microsoft recently decreed that technologies with .NET as a suffix, such as ADO.NET, are closed up. However, products with .NET as a suffix, such as VB .NET, are separated by a space.

Steven Roman, Ph.D., has written over 35 books in the areas of mathematics and personal computing. Among his computer books are Access Database Design & Programming, 2nd Edition, Writing Word Macros, Writing Excel Macros, and Win32 API Programming with Visual Basic, all for O'Reilly. He has also written Object Model Browser, a software program that provides structured views of type libraries, which is a great aid to VBA programmers in particular. For more information about Steve Roman's books, articles, and software, please visit his Web site.


O'Reilly & Associates will soon release (August 2001) VB .NET Language in a Nutshell.