1. Home
  2. Computing & Technology
  3. Visual Basic
Visual Basic .NET for Beginners
VB.NET is more .NET than VB
 More of this Feature
• Part 1: Why did they break VB?
• Part 2: Stop Bill From Getting More of Your Money!
 
 Join the Discussion
Log into the About VB Forum Here!
 
 Elsewhere on the Web
• Get the .NET Framework SDK
• The Standardization of .NET
 

So the best place to start learning about VB.NET is .NET.

If I had to point to one thing that makes VB.NET different from VB 6, it would be that VB.NET is totally object oriented (OOP) and VB 6 is just object friendly by comparison. In VB.NET, quite literally, everything is an object.

( What is an object, you ask! Just consult the About Visual Basic Glossary for the answer! )

Let's look at just one example of the difference. This is a good example because it shows you the change in the language syntax as well as the change to total object orientation.

In both VB 6 and VB.NET, it's possible to create a Form object (the windows that make up Windows are examples of Form objects) and assign it to another variable. Here's a short VB 6 program which declares two VB 6 objects. Declaring something as an Object means that it can contain any object in VB 6. So let's see if we can assign our Form f to the Object O.

Dim f As Form
Dim o As Object
o = f

But when you run it, you get an error, "Object variable or With block variable not set".

Really clear and understandable error message, isn't it!

What is happening is that VB 6 doesn't treat everything as an object so it tries to assign a property of the Form object (in this case, the controls collection) to the object o. That has never been initialized so you get the error.

If you want it to work in VB 6, you have to code it this way (the changed keyword is displayed in bold).

Dim f As Form
Dim o As Object
Set o = f

Then VB 6 treats the assignment as an object assignment instead of trying to assign the property. ("OH!!!" Says VB 6, "You wanted the form OBJECT assigned, not the PROPERTY! NOW I understand!!!")

In VB.NET, however, everything is an object. It works just fine the obvious and simple way:

Dim f As Form
Dim o As Object
o = f

When you get into .NET, you discover that the rules are a lot more complex and detailed, but they're also more consistent and once you understand them, they make more sense.

The next 'big difference' is that .NET uses a runtime engine (called the CLR, or Common Language Runtime) that is identical for all .NET languages. VB.NET (and other languages) compile to a code that is called IL Code (Intermediate Language) which is then executed by the CLR.

Now ... Some of you might be saying, "Hey! VB has used a runtime module for years. This isn't new."

True. But this one is compatible across all .NET languages (and even has a published interface, the CLI or Common Language Interface, so anyone could write a language for it). It's also been rewritten from the ground up. It has taken the best ideas from the Java JVM (Java Virtual Machine) and made them even better. (Yah! This is Microsoft "extend and embrace" again! But from your point of view as a consumer, it has resulted in a wondeful product!)

This 'total rewrite' - and the switch to complete OOP - made it possible to implement a whole raft of new language elements. At this point, it takes a 600 page text book (there are some great ones reviewed at About Visual Basic) to even start to cover these new language features in detail. Since this is just an introduction, I will only list a few of the more important ones. Many of these have more detailed articles available here at About Visual Basic. Don't worry if some of the concepts are a bit foreign to you. The goal is just to just briefly give you a view of the highlights. You won't have to pass a test.

  • Inheritance
  • This is the key OOP feature that most people point to as the difference between VB 6 and VB.NET. It was not implemented in VB 6. Although it's a convenient shorthand to say "inheritance" is the key new VB.NET feature, in reality, .NET has implemented dozens, maybe hundreds (depending on how you want to count them) of new object oriented features.

  • Structured Exception Handling
  • For error handling, VB 6 has On Error GoTo and ... well ... I guess that's about it, isn't it? But VB.NET has a whole methodology implemented in the tried and proven Try-Catch logic borrowed from the C world. And it also has the On Error GoTo statement but the Microsoft documentation says that using it is a mortal sin.

  • Multithreading
  • This refers to the ability of a single program to execute different processes concurrently. It's a way of speeding up response when you know that one part of a program takes a long time to run but the rest of the program can be executing without waiting for the result. This is a new feature that is mainly provided by the new CLR runtime (the default remains single threading), and there are new VB.NET language elements that must be used to implement it.

  • Completely Revised Types
  • First, the innovative Variant data type introduced by VB is not supported at all in .NET. Microsoft seems to have finally admitted that it wasn't such a good idea after all. And VB.NET supports strong type checking. Standby's like Integer and Long are longer. Arrays are zero based. In general 'Types' are a much bigger deal in .NET than they were in VB 6.

  • Memory Management
  • I can still remember a conversation I had years ago when Java was a new language. "What is this Java?" I asked. The techie I was talking to said, "It's a language that supports garbage collection."

    Memory management (or 'garbage collection') is the ability of a language to check whether software objects, like program variables, are still needed and to reclaim the memory they were using if they are not. Although it's possible to do garbage collection in your source code, it's almost always a bad idea because VB.NET just handles the job better than your source code can. And VB 6 doesn't.

  • "XCopy" Program Installation
  • AH! Back to the Future! This is the way we used to do it!

    An alternative description of this new feature that you sometimes read is, ".NET eliminates DLL Hell." Due to the way .NET keeps track of program modules, you can install a new system just by copying the files to a folder. But this feature (like many others) is really just one visible result of a more fundamental change. The same feature allows .NET to do automatic version control, side-by-side execution, and generally do a better job of managing the components of your system.

  • GDI+ (the new .NET graphics objects)
  • What can I say in a paragraph? A whole new world. Want to do transparent forms?

  • ADO.NET (the new .NET database objects)
  • Database oriented people like to describe .NET as the system that supports ADO.NET.

Next week, we write some code! And not just any code! We're going to write code using all three of the "cheap" methods that we learned about earlier. Look for it!

Return to the first page > Why did they break VB? > Page 1, 2, 3

Explore Visual Basic

More from About.com

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2008 About.com, a part of The New York Times Company.

All rights reserved.