Learning Visual Basic .NET was written to introduce the .NET version of the Visual Basic language specifically, and the .NET development platform more generally, to programmers with little or no object-oriented programming experience. Along the way, you will learn a great deal about writing high-quality, industrial-strength programs for .NET.
In this brief introduction, you will learn the basics of the Visual Basic .NET language. You will also learn some of the concepts integral to object-oriented programming, which has revolutionized how web and Windows applications are developed.
The goal of this book is to go beyond the syntax of VB.NET (the keywords and punctuation of the language) to examine the semantics of .NET programming with VB.NET (the meaning and structure of the code). VB.NET and the .NET Framework are built on the concepts of object-oriented design and programming, and these concepts will be explained as the book progresses to provide a deeper insight into how .NET programs are organized.
Long, long ago, and far, far away, in a little-known universe of primitive computing, there was a language called Basic, which stood for Beginner’s All-purpose Symbolic Instruction Code. Basic was designed to be as simple and accessible as possible for those unfamiliar with programming.
Visual Basic .NET (VB.NET) is a reengineering of this venerable language, which departs in significant ways from earlier versions of Visual Basic. In fact, some early adopters of VB.NET started calling it VB.NOT. VB.NET has evolved into a full-fledged object-oriented commercial software development package. Yet VB.NET also retains some of the inherent simplicity of its predecessors.
VB.NET has a number of features that help it retain backwards compatibility with Visual Basic 6 (VB6). Other features have been added specifically to adapt Visual Basic to object-oriented programming and to the .NET platform.
VB.NET provides support in the language to find bugs early in the development process. This makes for code that is easier to maintain and programs that are more reliable. VB.NET does not support many features available in other languages (e.g., pointers) that make for unsafe code.
In the past, you might have learned a language like C or Java without much concern about the platform on which you would be programming. These cross-platform languages were as comfortable on a Unix box as they were on a PC running Windows.
VB.NET, however, is a version of the Visual Basic language written specifically for .NET. While .NET may become cross-platform some day soon—a Unix port is already available—for now, the overwhelming majority of .NET programs will be written to run on a machine running Windows.
VB.NET represents a significant step forward for Visual Basic programmers. In the past, VB has been (unfairly) cast as a second-class “toy” language that was not up to the challenge of enterprise-level software development.
Whatever the merits of that accusation for VB6 and its predecessors, it is manifestly untrue for VB.NET. The code produced by Visual Basic .NET is (nearly) identical to that produced by C# or any other compiler designed for .NET. There is no performance or size penalty to writing with Visual Basic .NET.
In fact, the differences between Visual Basic .NET and C# are entirely syntactic. To illustrate, one language uses semicolons, the other does not; one language uses brackets, the other parentheses. The differences are so simple and so straightforward, that converting a C# program to Visual Basic .NET is an entirely mechanical operation, one that can be performed by a simple program—and such programs are already available on the Web.
In fact it is not far from the truth to say that at the most fundamental level there is no Visual Basic .NET language and no C# language. There is, rather, a single .NET language called MSIL (Microsoft Intermediate Language). Both Visual Basic .NET and C# compilers produce MSIL code, and the code they produce is nearly identical! The real meat of .NET programming, whether in Visual Basic .NET or in C#, is the .NET platform.
In July 2000, Microsoft announced the .NET platform, a development framework that provides a new way to create Windows applications. However, .NET goes beyond traditional Windows programming to facilitate creating web applications quickly and easily. And VB.NET is one of the premier languages Microsoft supports for development in this new and exciting .NET space.
Reports are that Microsoft is devoting 80% of its research and development budget to .NET and its associated technologies. The results of this commitment are impressive. For one thing, the scope of .NET is huge. The platform consists of three separate product groups:
A set of languages, including Visual Basic .NET and C#; a set of development tools, including Visual Studio .NET; and powerful tools for building applications, including the Common Language Runtime (CLR) a platform for compiling, debugging, and executing .NET applications.
A set of .NET Enterprise Servers, formerly known as SQL Server 2000, Exchange 2000, BizTalk 2000, and so on, that provide specialized functionality for relational data storage, email, B2B commerce, etc.
New .NET-enabled non-PC devices, from cell phones to game boxes.
The VB.NET language can be used to develop three types of applications you can run on your Windows computer:
Console applications display no graphics
Windows applications use the standard Windows interface
Web applications can be accessed with a browser
This book will focus primarily on the basics of the VB.NET language, mostly using simple console applications to illustrate language fundamentals.
Central to the .NET platform is a development environment known as the .NET Framework. The Framework specifies how .NET programming constructs such as intrinsic types, classes, and interfaces are implemented. You will learn about these constructs in the chapters ahead.
The .NET Framework sits on top of any flavor of the Windows operating system. The most important components of the Framework are the Common Language Runtime (CLR), described in the preceding section, and the so-called Framework Class Library (FCL), which provides an enormous number of predefined types or classes for you to use in your programs. You will learn how to define your own classes in Chapter 8. Complete coverage of all the FCL classes is beyond the scope of this book. For more information on these classes, see VB.NET Language in a Nutshell (Roman, Petrusha, and Lomax, O’Reilly).
The VB.NET language is disarmingly simple, but VB.NET is highly expressive when it comes to implementing modern programming concepts. VB.NET includes all the support for structured, component-based, object-oriented programming that one expects of a modern language.
The goal of VB.NET is to provide a simple, safe, object-oriented, Internet-centric, high-performance language for .NET development. VB.NET is simple because there are relatively few keywords. This makes it easy to learn and easy to adapt to your specific needs.
Keywords are special words reserved by the language and that have a
specific meaning within all VB.NET programs. Keywords include
For, and so forth. You’ll learn
about these keywords in the coming chapters.
VB.NET is considered safe because it provides support in the language to find bugs early in the development process. This makes for code that is easier to maintain and programs that are more reliable.
VB.NET provides full support for object-oriented programming. This book will explain not only how to write object-oriented programs, but will explain why object-oriented programming has become so popular. The short answer is this: programs are becoming increasingly complex, and object-oriented programming techniques help you manage that complexity.
VB.NET was developed for .NET, and .NET was designed for developing web and web-aware programs. The Internet is a primary resource in most .NET applications.
Finally, VB.NET was designed for professional high-performance programming.
At the most fundamental level, a VB.NET application consists of source code. Source code is human-readable text written in a text editor. A text editor is like a word processor, but it puts no special characters into the file to support formatting, only the text. A classic text editor is Notepad.
Example 1-1 shows an example of a very simple source code file.
Module HelloWorld ' every console app starts with Main Sub Main( ) System.Console.WriteLine("Hello world!") End Sub End Module
This program is explained in detail in Chapter 2. For now, observe that the program itself is readable: it is in normal text. The words may be strange and the layout unusual, but there are no special characters; just the normal text produced by your keyboard.
Once you write your program in an editor, you must compile it. For that you need a compiler. You will learn how to use the VB.NET compiler in Chapter 2. Once compiled, your program must be run and tested.
While you can perform all of these tasks using Notepad (or another text editor) and various command-line tools, your programming life will be much easier if you use the Integrated Development Environment (IDE) called Visual Studio .NET. VS.NET was designed with .NET development in mind and greatly simplifies the writing of VB.NET program code.
The Visual Studio .NET Integrated Development Environment provides enormous advantages to the VB.NET programmer. This book tacitly assumes that you’ll use Visual Studio .NET for your work. However, the discussion focuses more on the language and the platform than on the tools.