Flylib.com

Books Software

 
 
 

Section 1.5. The Structure of VB.NET Applications

   

1.5 The Structure of VB.NET Applications

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.

Example 1-1. A 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.

   
   

1.6 The Development Environment

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.

Nonetheless, Chapter 4 provides a good introduction to the IDE in some detail. Chapter 10 returns to the IDE to examine the debugger, which will help you find and correct problems in your code.

   
   

Chapter 2. Getting Started with VB.NET

You can use VB.NET to create three different types of programs:

  • Web applications

  • Windows applications

  • Console applications

The .NET platform is web-centric . The VB.NET language was developed to allow .NET programmers to create very large, powerful, high-quality web applications quickly and easily. The .NET technology for creating web applications is called ASP.NET.

ASP.NET, the next generation from ASP (Active Server Pages), is composed of two Microsoft development technologies: Web Forms and Web Services. While the development of fully realized web applications using these technologies is beyond the scope of this book, learning the basics of the VB.NET language will certainly get you started in the right direction. VB.NET is generally acknowledged to be one of the languages of choice for ASP.NET development.

Typically, you'll create an ASP.NET application when you want your program to be available to end users on any platform (e.g., Windows, Mac, Unix). By serving your application over the Web, end users can access your program with any browser.

When you want the richness and power of a native application running directly on the Windows platform, alternatively you might create a desktop-bound Windows application. The .NET tools for building Windows applications are called Windows Forms; a detailed analysis of this technology is also beyond the scope of this book.

However, if you don't need a Graphical User Interface (GUI) and just want to write a simple application that talks to a console window (i.e., what we used to call a DOS box), you might consider creating a console application. This book makes extensive use of console applications to illustrate the basics of the VB.NET language.

Web, Windows, and console applications are described and illustrated in the following pages.

Console applications

A console application runs in a console window, as shown in Figure 2-1. A console window (or DOS box) provides simple text-based output.

Console applications are very helpful when learning a language because they strip away the distraction of the Graphical User Interface. Rather than spending your time creating complex windowing applications, you can focus on the details of the language constructs, such as how you create classes and methods , how you branch based on runtime conditions, and how you loop. All these topics will be covered in detail in coming chapters.

Figure 2-1. A console application
figs/lvbn_0201.gif
Windows applications

A Windows application runs on a PC's desktop. You are already familiar with Windows applications such as Microsoft Word or Excel. Windows applications are much more complex than console applications and can take advantage of the full suite of menus , controls, and other widgets you've come to expect in a modern desktop application. Figure 2-2 shows the output of a simple windows application.

Figure 2-2. A Windows application
figs/lvbn_0202.gif
ASP.NET applications

An ASP.NET application runs on a web server and delivers its functionality through a browser, typically over the Web. ASP.NET technology facilitates developing web applications quickly and easily. Figure 2-3 shows a message from a simple ASP.NET application.

Although most commercial applications will be either Windows or ASP.NET programs, console applications have a tremendous advantage in a VB.NET primer. Windows and ASP.NET applications bring a lot more overhead; there is great complexity in managing the window and all the events associated with the window. (Events are covered in Chapter 18.) Console applications keep things simple, allowing you to focus on the features of the language.

Figure 2-3. An ASP.NET application
figs/lvbn_0203.gif

This book does not ever go into all the myriad details of building robust Windows and ASP.NET applications. For complete coverage of these topics, please see Programming ASP.NET and Programming .NET Windows Applications both by Jesse Liberty and Dan Hurwitz (O'Reilly).