Few programmers have ever considered
Visual Basic as a real object-oriented programming language, for example because
of its lack of constructors and inheritance.
VB6 code can't access some Win32 and COM's features (e.g.
you require other languages, such as C or C++, for low level programming jobs.
Well, all this will soon be a memory, because VB's next version - Visual Basic
.NET - is a fully object oriented and has all the C++ (or better, C#) features
you have ever dreamt of.
Don't think that there are just some improvements to the language
Microsoft entirely re-designed VB.NET to target the new development platform,
the .NET Framework.
.NET Framework is a new development environment for Windows and Web
applications, and consists of a Common
Language Runtime (CLR) and a Base Class Library (BCL). Becoming
familiar with the .NET platform is important, because it is the infrastructure
on which VB.NET is built. Microsoft delivers four .NET compilers: C++, C#,
VB.NET and JScript (http://msdn.microsoft.com/net).
In theory you might write your code with
Notepad and compile it with VBC.EXE (VB.NET's compiler), but the forthcoming
Visual Studio .NET (whose official release is expected next autumn) provides a
shared graphical environment to design, develop and debug .NET components (Figure
The CLR replaces the VBRUNxx.DLL and
MSVBVMxx.DLL libraries, and it is necessary for all the other .NET languages to
run. The CLR manages several system services on behalf of applications, such
processes, threads and objects' lifetime management.
Preview of Visual Studio .NET
Regardless of the language they choose,
programmers spend most of their time in solving the same issues (e.g. file I/O
or data access). The purpose of BCL is provide developers with a ready-to-use
library for solving the most common programming problems such as OS interaction,
data access (ADO.NET), and user interface (Windows Forms and WebForms).
For instance, you have to invoke the Show() method of System.WinForms.MessageBox
class to show a message box in VB.NET:
VB's MsgBox statement is nothing more than
a wrapper for System.WinForms.MessageBox.Show().
The System.Console class, instead, takes
care of managing console application's I/O:
Dim str As String
str = System.Console.ReadLine
These are just a few examples to
demonstrate that the Win32/COM mixture used so far is going to be replaced by a
class library common to all .NET languages. The BCL comprises hundreds of
classes in a single object model!
All for one and
one for all
.NET languages are equivalent, have the
same capabilities, and can interoperate at the binary level. All languages use the
same set of types and the same calling and parameter passing conventions: the String
type exists in C# as well as VB.NET, and both languages store it in memory in
the same way.
A VB programmer can reuse C# code (and C++
or JScript as well) and vice versa: this simple interface:
public interface CSInterface
void PrintLine(string message);
can be implemented by a VB class:
Public Class VBClass
Sub PrintLine(ByVal message As String) Implements CSInterface.PrintLine
' do something...
You can make a VB.NET class available to
any other language, and VB.NET code can call C# or JScript libraries. VB.NET
is finally a first-class language, as well as C# or C++.
As a consequence, cross-language development and debug are quite
because all languages share the same execution environment, that is the CLR.
Other companies have announced .NET languages, and there are about 20 languages
in the work, not counting Microsoft's ones, including Eiffel and Smalltalk.
Microsoft has designed a series of specifications (known as Common
Specifications, or CLS), which must be followed when designing a .NET compiler
to guarantee the equivalence of all .NET languages. The VB.NET team introduced
changes both in syntax and the semantics of the language to comply with these
CLS specifications. For instance,.NET reports all errors - from math errors to
operating system ones - through exceptions, and the CLS mandates that all .NET
languages can manage them. The Try...Catch...Finally statement replaces
the outdated On Error Goto statement. Here is an example demonstrating file I/O
with exception handling:
' (Imports System.IO)
Dim dout As Stream
Dim path As String = "C:\file.txt"
' open the file
dout = File.OpenWrite(path)
Catch e As FileNotFoundException
' error, file doesn't exist, create a new file
dout = File.Create(path)
' finally close the file