Special Edition Using Visual Basic.NET

function OpenWin(url, w, h) { if(!w) w = 400; if(!h) h = 300; window.open(url, "_new", "width=" + w + ",height=" + h + ",menubar=no,toobar=no,scrollbars=yes", true); } function Print() { window.focus(); if(window.print) { window.print(); window.setTimeout('window.close();',5000); } }
Team-Fly    

Special Edition Using Microsoft® Visual Basic® .NET

By Brian Siler, Jeff Spotts

Table of Contents
Chapter 1.  Introduction to Visual Basic .NET

Understanding Programming and Visual Basic's Role

Before we jump into the technical details of Visual Basic .NET, we would like to answer some common questions about computer programming in general, and how Visual Basic fits into the overall picture. We also want to get you thinking about some important concepts that apply to computer programming in any language.

What Is a Computer Program?

A computer program(also known as an application) is a series of instructions that enables a computer to perform a specific task. A programming language such as Visual Basic is used to translate instructions, as we humans understand them, into the steps that the computer can comprehend and follow. A computer program can be designed to perform a single, basic task, such as calculating conversions between different units of measure or keeping track of your grocery list. Other computer programs may be far more complex and perform very specialized tasks, such as tracking the satellites orbiting Earth at any given moment.

Traditionally, computer programs have fallen into two very broad categories packaged and custom.

Packaged programs are those that you can purchase in a software store, via mail order, direct from a manufacturer, and so on. Packaged programs (sometimes known as canned programs) are predesigned to accomplish one or more specific tasks. For example, you may purchase Microsoft Word to meet your word processing needs, Symantec's WinFax Pro to enable your computer to send and receive faxes, or McAfee's VirusScan to help prevent viruses from attacking your system. You also may be interested in game programs such as Maxis' The Sims or Microsoft's Flight Simulator. All these programs are among the thousands upon thousands of software packages that are available for Windows-based personal computers (PCs).

Custom programs (also known as proprietary programs) are usually designed for a specific purpose within a particular organization. For example, a company may need an application that tracks product orders from the time they are placed until they are actually shipped. If there is no packaged program available that meets the company's specific needs, a custom program could be developed. One advantage of a custom program in this case is that the program can be continually modified as the company's needs change packaged programs generally can't be modified by the user.

Over the past few years, as use of the Internet has exploded, a new category of software is emerging. This new category of software, known as distributed applications, utilizes the Internet (or other large-scale connectivity, such as a local intranet) to allow several different layers of an application to run at different locations. Application Service Providers (ASPs) allow companies to access programs and store data on their servers. Thanks to the Internet, these services are accessible to nearly everyone. Visual Basic .NET, as part of the larger Visual Studio .NET infrastructure, is Microsoft's attempt to bring these types of applications within the domain of the VB programmer. For example, you can create a Web service with Visual Basic .NET and provide an enormous amount of functionality to distributed applications.

Many distributed applications are known as multi-tier, or n-tier, applications. This term relates to the distribution of the processing power required to execute the program. A multi-tier application involves several "layers" of computers, each of which is responsible for providing a specific portion of the processing that creates or responds to the end user's experience. For example, a user may access a Web-based e-commerce application such as eBay or Amazon.com through his Web browser; in this case, his computer provides the front-end interface. In turn, his Web browser connects to other computers that generate catalog pages, perform product searches, and manage order entry and credit card processing. Typically, in addition to the client's PC, one or more Web servers, database servers, and other applications may be involved. In a case such as this, several layers (tiers) of processing provide the overall experience to the user.

A Brief Programming Language Primer

When you get down to a computer's most basic level, the microprocessor that is at the core of the computer's functionality doesn't understand anything other than numeric instructions. To make matters worse, the only instructions that the processor can understand are incredibly simplistic commands, most of which have to do with moving numbers around between memory locations. These commands that the processor understands are known as machine language, or the most basic language that the machine (the PC) can use.

Machine language is known as a low-level language, because it's all the way down at the processor's level of understanding. As you might imagine, writing programs in machine language is an incredibly daunting task. Fortunately, you don't have to get down to that level to create computer programs. Several higher-level programming languages have been developed to enable us to write programs. These programming languages enable programmers to write instructions in something resembling English; the instructions are then converted into a program containing machine-language instructions that the processor can understand.

Some examples of programming languages that have developed over the years include ForTRAN and COBOL, which are generally used with mainframe computers, as well as BASIC, Pascal, C, and C++, which are commonly used to write programs at the personal computer level.

The Evolution of Visual Basic

Visual Basic is a descendant of BASIC, which has been around for several decades. BASIC (an acronym for Beginners' All-Purpose Symbolic Instruction Code) was originally developed at Dartmouth University in 1964 as a language for beginning programmers. BASIC was often the first language that programmers learned to become familiar with programming basics before moving on to more powerful languages.

However, Visual Basic is much more significant than just an upgrade to BASIC. To understand why, you only need to understand the changes that Windows brought to the computing world. Most readers are familiar with the Windows operating system, which is what made Bill Gates rich and famous. The core idea (which was not invented by Gates but by Xerox) is a graphical operating system using metaphors for computer concepts that the average person can understand. For example, computer files are represented as graphical icons stored in file folders on a desktop the user can view. Each open window has certain expected behavior, such as the ability to scroll or change positions. Although we pretty much take it for granted today, Windows made computers much more intuitive to use and helped bring personal computing to the masses.

As easy as it was to use Windows, writing programs for it in a traditional language could be a major headache. One common test of a programming language is to print the text "Hello World" on the screen. Prior to Windows, this could be accomplished in most languages with just one or two lines of code. However, an early Windows programming book (for the C language) described several screens of code (more than 80 lines) just to create a "Hello World" window. This extra code was required to create a window that interacted and behaved appropriately with the operating system.

Visual Basic, which has evolved into an extremely powerful application development tool, takes a lot of complexity out of programming for the Windows environment. Rather than write code to draw a window or process operating system events, you can graphically design windows using the mouse. Since its introduction, Visual Basic has gradually left its reputation as a beginners' language far behind and become one of the most popular and powerful Windows programming languages. The latest version of Visual Basic, Visual Basic .NET, taps into the world of distributed Web applications and represents perhaps Visual Basic's most ambitious leap forward.

One very nice feature of Visual Basic is that you can use it to create a solid application very quickly. As you'll see throughout this book, Visual Basic makes short work of what would normally be very time-consuming programming tasks. This frees up the programmer to spend his time developing the application's functionality, rather than spending time on mundane, repetitive programming tasks. Visual Basic is often referred to as a Rapid Application Development (RAD) tool.


    Team-Fly    
    Top
     

    Категории