The Visual Basic 2005 Language

There were no huge surprises in the core of the Visual Basic 2005 language itself. If...Then..Else, Do...Loop, all of the old furniture is where you expect it to be. Anyone who hasn't programmed before shouldn't have too much trouble learning, the names of these things are fairly self-explanatory. By default, VB 2005 is in strict mode, so before you use a variable you have to declare it using Dim, for example, Dim myNumber As Integer. You can switch this behaviour off, but I personally prefer to leave it on. It helps you to think the program through and structure it nicely.

There were a couple of interesting additions to the BASIC that I had used before. Exceptions are a way of handling errors. When there is an error executing a function, the function "throws an exception" which can then be caught and inspected to see what's wrong. In VB 2005, you use a Try...Catch...Finally block to deal with exceptions. You put the code you're trying to run in the Try section, the code to handle exceptions in the Catch section, and you can optionally use a Finally section for code that will run whether there's an exception or not. I found this to be a pretty straightforward way of dealing with errors, although it requires careful thought when there is more than one type of exception that might occur. There's no point trying to recover from the wrong kind of error. You can make your own functions throw exceptions too, but again, you have to think it through carefully.

One pretty major change is that Visual Basic 2005 is fully object oriented. This is a very different concept to the old BASIC, and it might take a while to get your head around Object Oriented Programming (OOP) if you're used to the old way of doing things. To put it as simply as I can, instead of doing things to objects, you tell the objects to do it themselves. An object can have built-in functions, which are called "methods", and built-in variables called "properties". Instead of having a function named ShowDialogBox(), you would have a DialogBox object, and you might tell it to show itself by calling its Show method, writing something like DialogBox.Show(). Although you can hack together a program without creating objects yourself, it's worth learning because once you get the hang of OOP your programs start looking a lot more structured and elegant. One criticism of the old VB6 was that it wasn't fully object oriented. Well, VB 2005 is, so you can learn OOP skills that will be transferable to other languages.

With...End With is a neat addition. A lot of the .NET objects, methods and properties have pretty verbose names, and when you are doing various things to an object, the resulting code can be very cluttered (although the IntelliSense cuts the amount of typing down a lot). VB 2005 lets you work on an object without constantly typing its name, so instead of:

OpenFileDialog1.Title = boxTitle
OpenFileDialog1.InitialDirectory = startDir
OpenFileDialog1.ReadOnlyChecked = True

You would write:

With OpenFileDialog1
  .Title = boxTitle
  .InitialDirectory = startDir
  .ReadOnlyChecked = True
End With

I like this feature a lot. Not only does it cut down on the clutter, it also helps you break the program down into handy chunks. That's a good thing for us amateurs. IntelliSense works out what you are trying to type and auto-completes, so you wouldn't actually have to type ".ReadOnlyChecked = True", you could get away with ". r e <space> = t <return>".

VB 2005 is not case-sensitive, so you don't have to worry about capitalizing things correctly. IntelliSense sorts it out for you. C# on the other hand, is case sensitive. I don't really see the advantage of a language being case sensitive. Maybe the professionals like it that way.

I also liked the way that you can create different versions of a method with the same name depending on what inputs you want to pass on to it, which is called overloading. As a simple example you might have to pass a function the location of a file, but sometimes you will be working with full paths, and sometimes with separate directory and filename variables. Rather than messing around sticking the directory and path together, you can simply have two versions of the method, one of which wants a full path while the other wants separate directory and filename. IntelliSense will show the available options to help you choose the right one.

Next I will talk about the .NET Framework.