Академический Документы
Профессиональный Документы
Культура Документы
CHAPTER
1
Introduction to Visual Basic .NET
In this chapter
Understanding Programming and Visual Basic’s Role 12
The Importance of Application Design 14
Tips for a Good Design 15
Big Changes in Visual Basic .NET 18
From Here . . . 19
ISBN: 0-558-13856-X
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.
03 572x CH01 11/29/01 2:13 PM Page 12
Thank you for deciding to make this book part of your library. We hope that it will serve as
your guide to the exciting new world of Microsoft Visual Basic .NET.
(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
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.
03 572x CH01 11/29/01 2:13 PM Page 13
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 Part
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
I
Ch
provide an enormous amount of functionality to distributed applications.
Many distributed applications are known as multi-tier, or n-tier, applications. This term 1
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 pro-
viding 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.
the first language that programmers learned to become familiar with programming basics
before moving on to more powerful languages.
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.
03 572x CH01 11/29/01 2:13 PM Page 14
However, Visual Basic is much more significant than just an upgrade to BASIC. To under-
stand why, you only need to understand the changes that Windows brought to the comput-
ing 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 aver-
age 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 reputa-
tion 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 mun-
dane, repetitive programming tasks. Visual Basic is often referred to as a Rapid Application
Development (RAD) tool.
good idea! Like anything in life, a program that is built on a shaky foundation can be
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.
03 572x CH01 11/29/01 2:13 PM Page 15
plagued with problems. Your program’s purpose is to solve a specific problem, and the
design determines how it will solve that problem. It is very important to spend time on Part
design before you start coding. Investing a significant amount of time in program design will
benefit both you and the users of your programs.
I
Ch
The ideas presented in this section are by no means all-inclusive, but rather one set of gen-
eral guidelines. Your technique, of course, may be totally different.
ask you to change a field caption (which is an easy change in Visual Basic), but on the other
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.
03 572x CH01 11/29/01 2:13 PM Page 16
hand they might involuntarily omit a critical requirement of the system, which totally invali-
dates your design! The symptom of this problem is after delivery of your program the end
user has a lot of questions that begin with “But what about . . . ?”
The way to avoid these problems is to spend a lot of time planning and discussing the
requirements of the program with the end user to make sure that both of you understand
them completely. Altering a design during the planning stages of a project is a lot cheaper
and faster than altering it after the project is finished. A good rule of thumb is to ask ques-
tions until you are tired of it, then keep on going! Even though you may not understand all
aspects of the user’s business, and they will certainly not understand all the technical aspects
of programming, it is important to keep an open line of communication.
One design tool that may help everyone understand the application is the use of a prototype.
A prototype is a partially functional or nonfunctional version of the application to give the
user an idea of what the final product will look like. This is easy to do in Visual Basic and
can be useful in extracting more requirements from the user.
Suppose in the future, the users of the program want to add a delivery date. With the previ-
ous table design, you will have to add a new column to the database, altering the table
design. However, suppose you had originally created the table as follows:
Order# DateType AssociatedDate
12345 ORDER 1/1/99
12345 SHIP 1/2/99
12345 DELIVERY 1/3/99
With this more generic table design, the additional requirement of a delivery date is accom-
plished by simply adding another record to the database. (Of course you may still need to
modify the user interface, but these modifications will be easier because it is based on the
same underlying database.)
➔ Please see Chapter 20, “Database Basics,” for more information on database design.
Although the second design is more flexible, the first one has the potential to be faster,
because everything about an order is stored on one database record instead of three. The
key is to understand the requirements well enough to achieve the appropriate balance of
flexibility and speed.
ISBN: 0-558-13856-X
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.
03 572x CH01 11/29/01 2:13 PM Page 17
This code in the previous function is very simple; it accepts an ID and a new value, and calls
some other functions to update a counter if the new value is greater than the old value.
However, the purpose behind the function is not very clear. Now, read the following version
of the function, which has been rewritten in a clearer style:
Public Sub ChangeCount(astrUserID As String, aintNumLogins AS Integer)
’This function updates the login counter for the given user
lintCurrentLogins = GetCurrentCounter(astrUserID)
➔ For more information on declaring variables, see “Declaring and Naming Variables,” p. 140
Notice that there are comments to explain both the general purpose of the function and any
sections that may not be already clear to the reader. The variables have been declared with a
prefix to indicate the scope (l for local, a for argument) and data type (int for Integer, str for
string). The use of indentation, blank lines, and a multi-line If statement makes the code
visually easier to comprehend. By deciding on techniques such as these you can create code
that people can understand quicker.
you write a function that connects to a database and returns a recordset, you should be able
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.
03 572x CH01 11/29/01 2:13 PM Page 18
to use it on all your database projects. If you keep the modules of your program well sepa-
rated by functional requirements and avoid hard-coding values where appropriate, you can
create code that you can use again and again.
In addition, Visual Studio .NET makes extensive use of eXtensible Markup Language
(XML), a markup language that provides a format for describing structured data. Visual
Studio .NET also utilizes a standardized Integrated Development Environment (IDE),
ISBN: 0-558-13856-X
which is the interface in which you build your applications. This will greatly simplify the
porting of your skills from one Visual Studio .NET language to another.
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.
03 572x CH01 11/29/01 2:13 PM Page 19
From Here . . . 19
■ The next chapter, “Creating Your First Windows Application,” will walk you step-by- 1
step through the process of developing a fully functional application that will run on a
Windows-based PC.
■ Chapter 3, “Creating Your First Web Application,” shows you how to use Visual Basic
.NET to develop programs that can be accessed across the Internet or an intranet via a
Web browser.
■ You will receive a thorough introduction to Visual Basic .NET and the Visual Studio
.NET development environment in Chapter 5, “Visual Basic Building Blocks.”
ISBN: 0-558-13856-X
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.
03 572x CH01 11/29/01 2:13 PM Page 20
ISBN: 0-558-13856-X
Special Edition Using Visual Basic® .Net, by Brian Siler and Jeff Spotts. Copyright © 2002 by Que. Published by Que Publishing.