Visual Basic 2005 for Programmers by Harvey M. Deitel, Paul J. Deitel |, Multimedia Set | Barnes & Noble
Visual Basic 2005 for Programmers
  • Alternative view 1 of Visual Basic 2005 for Programmers
  • Alternative view 2 of Visual Basic 2005 for Programmers

Visual Basic 2005 for Programmers

by Harvey M. Deitel, Paul J. Deitel


“The discussion of object-oriented programming is one of the best available.”
—Gavin Osborne, Saskatchewan Institute of Applied Science & Technology
“The explanation of UML, intelligently integrated into the book, conveys the heart and soul of true



“The discussion of object-oriented programming is one of the best available.”
—Gavin Osborne, Saskatchewan Institute of Applied Science & Technology
“The explanation of UML, intelligently integrated into the book, conveys the heart and soul of true object oriented architecture and engineering.”
—Jeff Jones, Route Match Software
“The optional ATM OOD/UML case study is excellent! The implementation of the design gives the reader a fantastic model of a real world problem. You hit a home run with this one.”
—Catherine Wyman, Devry-Phoenix
“A superb job of clearly integrating the theory of relational databases and SQL with the application of ADO.NET.”
—Harlan Brewer, SES Consulting
“Really nails most everything you need to know about handling exceptions in VB.”
—Eric Gruber, Microsoft
“Excellent coverage of the most important features and techniques of developing ASP.NET 2.0 applications, with plenty of sample code.”
—Peter Bromberg, Senior Enterprise Architect, VOIP, Inc.
“A very impressive introduction to XML.”
—John Z. Chen, Microsoft
“An excellent chapter on Web services with great examples.”
—Chadi Boudiab, Georgia Perimeter College
“The best description of generics I’ve seen!”
—James Huddleston, Independent Consultant
The practicing programmer’s DEITEL® guide to Visual Basic and the powerful Microsoft .NET Framework

Written for C#, C++, Java or other-high level language programmers, this book applies the Deitel signature live-code approach to teaching programming and explores Microsoft’s Visual Basic language and the new .NET 2.0 in depth. The book is updated for Visual Studio® 2005 and presents Visual Basic concepts in fully tested programs, complete with syntax shading, line-by-line code descriptions, and program outputs. The book features 200+ applications with 16,000+ lines of proven Visual Basic code, and hundreds of programming tips that help you build robust applications.

Start with a concise introduction to Visual Basic fundamentals using an early classes and objects approach, then rapidly move on to more advanced topics, including multithreading, XML, ADO.NET 2.0, ASP.NET 2.0, Web services, network programming, .NET remoting, generics and collections. Along the way you’ll enjoy the Deitels’ classic treatment of object-oriented programming and a new, OOD/UML ATM case study, including a complete Visual Basic implementation. When you are finished, you’ll be well on your way to building next generation Windows applications, Web applications, and Web services.

Paul J. Deitel and Harvey M. Deitel are the founders of Deitel & Associates, Inc., the internationally recognized programming languages content-creation and corporate training organization. Together with their colleagues at Deitel & Associates, Inc., they have written many international best-selling programming languages textbooks and professional books that millions of people worldwide have used to master C, C++, Java, C#, XML, Visual Basic®, Perl, Python, and Internet and Web programming.

The DEITEL® Developer Series presents focused treatments of leading-edge technologies, including .NET development, Java development, Web services, and more.

Practical, Example-Rich Coverage Of:

  • Visual Basic 2005, .NET 2.0, FCL
  • ASP.NET 2.0, Web Forms and Controls
  • Database, SQL, and ADO.NET 2.0
  • Networking and .NET Remoting
  • XML, Web Services
  • Generics, Collections
  • GUI/Windows® Forms
  • OOP: Classes, Inheritance, and Polymorphism
  • OOD/UML ATM Case Study
  • Graphics and Multimedia
  • Multithreading
  • Exception Handling
  • And more...
  • Download code examples
  • Check out the extensive Visual Basic Resource Center
  • Check out the growing list of programming, Web 2.0, and software-related Resource Centers
  • To receive updates on this book, subscribe to the free DEITEL® BUZZ ONLINE e-mail newsletter at
  • Read archived issues of the DEITEL® BUZZ ONLINE
  • Contact for information on corporate training courses delivered on-site worldwide
CD contains Microsoft’s Visual Basic 2005 Express Edition

Product Details

Prentice Hall
Publication date:
Deitel Developer Series
Edition description:
Book & CD-ROM
Product dimensions:
7.00(w) x 9.04(h) x 2.48(d)

Related Subjects

Read an Excerpt

“Live in fragments no longer, only connect.”
—Edgar Morgan Foster

Welcome to the world of Windows, Internet and Web programming with Visual Basic, Visual Studio 2005 and the .NET 2.0 platform! This book presents leading-edge computing technologies to software developers and IT professionals.

At Deitel & Associates, we write computer science textbooks for college students and professional books for software developers. We also teach this material in industry seminars at organizations worldwide.

This book was a joy to create. To start, we put the previous edition under the microscope:

  • We audited our presentation against the most recent Microsoft Visual Basic Language Specification—Version 8—which can be downloaded from
  • We fully updated the book to Visual Studio 2005 and .NET 2.0.
  • All of the chapters have been significantly updated and upgraded.
  • We changed to an early classes and objects pedagogy. Now readers build reusable classes starting with a very friendly treatment in Chapter 4.
  • We updated our object-oriented presentation to use the latest version of the UML (Unified Modeling Language)UML™ 2.0—the industry-standard graphical language for modeling object-oriented systems.
  • We added an optional OOD/UML automated teller machine (ATM) case study in Chapters 1, 3–9 and 11. The case study includes a complete Visual Basic code implementation of the ATM in Appendix J.
  • We added several multi-section, object-oriented programming case studies.
  • We incorporated key newfeatures of Microsoft’s latest release of Visual Basic—Visual Basic 2005—and added discussions on generics, .NET remoting and debugging.
  • We significantly enhanced our treatment of

All of this has been carefully scrutinized by a substantial team of .NET industry developers, academic professionals and members of theMicrosoft Visual Basic development team.Who Should Read This Book

We have several Visual Basic publications, intended for different audiences. Visual Basic 2005 for Programmers, 2/e, is part of the Deitel® Developer Series, intended for professional software developers who want a deep treatment of a new technology with minimal introductory material. The book emphasizes achieving program clarity through the proven techniques of structured programming, object-oriented programming (OOP) and event-driven programming. It continues with upper-level topics such as

How to Program Series college textbooks, the Deitel® Developer Series books do not include the extensive pedagogic features and ancillary support materials required for college courses.

Visual Basic 2005 for Programmers, 2/e presents hundreds of complete, working Visual Basic programs and depicts their inputs and outputs in actual screen shots of running programs. This is our signature “live-code” approach—we present concepts in the context of complete working programs.

As you read this book, if you have questions, send an e-mail to; we will respond promptly. For updates on this book and the status of Visual Basic software, and for the latest news on all Deitel publications and services, please visit regularly and be sure to sign up for the free Deitel® Buzz Online e-mail newsletter at For more information about Visual Basic 2005, check out our Visual Basic resource center at For a complete list of our resource centers, visit Basic 2005 for Programmers, 2/e Code Examples

You can download the book’s source code from

The examples are in ZIP archive files, so you’ll need a ZIP archive tool such as WinZip (available from to extract the files. The examples are organized in an examples folder with a subfolder for each chapter (e.g., ch01, ch02, etc.). The example folders are named FigXX_YY, where XX represents the chapter number and YY represents the figure number. For examples that span multiple figures, the folder name has the format FigXX_YY_ZZ, where YY and ZZ represent the example’s starting and ending figure numbers. We assume in our Chapter 1 “test-drive” instructions that you extract these examples to the C:\ folder on your computer.Microsoft Visual Basic 2005 Express Edition Software

On November 7, 2005 Microsoft released its Visual Studio 2005 development tools, including the Visual Basic 2005 Express Edition. Per Microsoft’s Web site, Microsoft Express Editions are “lightweight, easy-to-use and easy-to-learn tools for the hobbyist, novice and student developer.” You may use Visual Basic 2005 Express (which is packaged with this book) or a complete version of Visual Studio 2005 to compile and execute the example programs. Visual Basic 2005 Express also can be downloaded from

According to the Microsoft Express Editions FAQ page (, “Effective April 19th, 2006, all Visual Studio 2005 Express Editions are free permanently. SQL Server 2005 Express Edition has always been and will continue to be a free download.”

When you install this software, you will be asked if you wish to install the help documentation and SQL Server 2005 Express—we recommend that you choose to install both. Microsoft provides a dedicated forum for help using the Express edition:
Other Software Requirements

For some examples in Chapter 17, Graphics and Multimedia, we use Microsoft Agent, which can be downloaded from

For Chapter 20, you will need SQL Server 2005 Express Edition, which is available at

Note that you do not need to download SQL Server 2005 Express separately if you select the option to install it during the Visual Basic 2005 Express installation.

Chapters 21 and 22 require either Visual Web Developer 2005 Express (or a complete version of Visual Studio 2005). Visual Web Developer 2005 Express is available at

Like Visual Basic 2005 Express, the other express editions are free for download until November 6, 2006, after which Microsoft may charge a fee for these tools.

For Chapters 21 and 22, you may also want to install the IIS Web server to test the examples. For more information about installing IIS, please visit

If you prefer not to (or cannot) install IIS, you can use the built-in test server in Visual Web Developer 2005 Express to test the examples in Chapters 21 and 22.

For updates on the software used in this book visit or subscribe to our free e-mail newsletter at Also, be sure to check out our Visual Basic resource center ( frequently for new Visual Basic resources.Features in Visual Basic 2005 for Programmers, 2/e

This new edition contains many new and enhanced features.Updated for Visual Studio 2005, Visual Basic 2005 and .NET 2.0

We updated the entire text to reflect Microsoft’s release of Visual Basic 2005. New items include:

  • Screenshots updated to the Visual Studio 2005 IDE.
  • Property accessors with different access modifiers.
  • Viewing exception data with the Exception Assistant (a new feature of the Visual Studio 2005 Debugger).
  • Using drag-and-drop techniques to create data-bound windows forms in ADO.NET 2.0.
  • Using the IDE’s Data Sources window to create application-wide data connections.
  • Using a BindingSource to simplify the process of binding controls to an underlying data source in ADO.NET 2.0.
  • Using a BindingNavigator to enable simple navigation, insertion, deletion and editing of database data on a Windows Form.
  • Using the Master Page Designer to create a common look and feel for ASP.NET Web pages.
  • Using Visual Studio 2005 smart tag menus to perform common programming tasks when new controls are dragged onto a Windows Form or ASP.NET Web page.
  • Using VisualWeb Developer’s built-inWeb server to test ASP.NET 2.0 applications and Web services.
  • Using an

    to bind

  • Using a SqlDataSource to bind a SQL Server database to a control or set of controls.
  • Using an ObjectDataSource to bind a control to an object that serves as a data source.
  • Using the ASP.NET 2.0 “login” and “create new user” controls to personalize access to Web applications.
  • Using generics and generic collections to create general models of methods and classes that can be declared once, but used with many types of data.
  • Using generic collections from the Systems.Collections.Generic namespace.
The My Namespace

One of the new Visual Basic features receiving attention is the My namespace, which makes many common .NET programming tasks more convenient in Visual Basic. Many of the My namespace’s features are beyond the scope of this book. However, we’ve included extensive links to My namespace resources in our Visual Basic resource center

These resources include sample code, technical articles, whitepapers, webcasts, videos, presentations and more. For a quick overview of many My namespace features, check out

For a detailed introduction to the My namespace, check out the following 1-hour and 23-minute presentation from the 2005 Microsoft Professional Developers Conference:
New Interior Design

Working with the creative services team at Prentice Hall, we redesigned the interior styles for our Deitel® Developer Series books. Special typefaces more clearly demonstrate concepts in the text.Syntax Shading

We syntax shade all the Visual Basic code, similar to the way most Visual Basic integrated development environments and code editors syntax color code. This greatly improves code readability—an especially important goal, given that this book contains 16,200+ lines of code.Code Highlighting

Extensive code highlighting makes it easy for readers to spot each program’s featured code segments—we place light rectangles around the key code.Early Classes and Objects Approach

We still introduce basic object-technology concepts and terminology in Chapter 1. In the previous edition, we developed custom classes in Chapter 9, but in this edition, we start doing that in the completely new Chapter 4. Chapters 5–8 have been carefully rewritten with a very friendly “early classes and objects approach.”Carefully Tuned Treatment of Object-Oriented Programming in Chapters 9–11

This edition is clearer and more accessible—especially if you are new to object-oriented programming (OOP). We completely rewrote the OOP chapters, integrating an employee payroll class hierarchy case study and motivating interfaces with an accounts payable hierarchy.Case Studies

We include many case studies, some spanning multiple sections and chapters:

  • The GradeBook class in Chapters 4, 5, 6 and 8.
  • The optional, OOD/UML ATM system in the Software Engineering sections of Chapters 1, 3–9 and 11 and Appendix J.
  • The Time class in several sections of Chapter 9.
  • The Employee payroll application in Chapters 10 and 11.
  • The Guestbook ASP.NET application in Chapter 21.
  • The secure book database ASP.NET application in Chapter 21.
  • The blackjack Web service in Chapter 22.
  • The airline reservation Web service in Chapter 22.
Integrated GradeBook Case Study

To reinforce our early classes presentation, we present an integrated case study using classes and objects in Chapters 4–6 and 8. We incrementally build a GradeBook class that represents an instructor’s grade book and performs various calculations based on a set of student grades—finding the average, finding the maximum and minimum, and printing a bar chart. Our goal is to familiarize you with the important concepts of objects and classes through a real-world example of a substantial class.The Unified Modeling Language (UML)—Using the UML 2.0 to Develop an Object-Oriented Design of an ATM

The Unified Modeling Language™ (UML™) has become the preferred graphical modeling language for designing object-oriented systems. All the UML diagrams in the book comply with the UML 2.0 specification. We use UML class diagrams to visually represent classes and their inheritance relationships, and we use UML activity diagrams to demonstrate the flow of control in each of Visual Basic’s control statements.

This Second Edition includes a new, optional (but highly recommended) case study on object-oriented design using the UML. The case study was reviewed by a distinguished team of OOD/UML academic and industry professionals, including leaders in the field from Rational (the creators of the UML and now a division of IBM) and the Object Management Group (responsible for maintaining and evolving the UML). In the case study, we design and fully implement the software for a simple automated teller machine (ATM). The Software Engineering Case Study sections at the ends of Chapters 1, 3–9 and 11 present a carefully paced introduction to object-oriented design using the UML. We introduce a concise, simplified subset of the UML 2.0, then guide the reader through a first design experience intended for the novice object-oriented designer/programmer. The case study is not an exercise; rather, it is an end-to-end learning experience that concludes with a detailed walkthrough of the complete Visual Basic code. The Software Engineering Case Study sections help readers develop an object-oriented design to complement the object oriented programming concepts they begin learning in Chapter 1 and implementing in Chapter 4. In the first of these sections at the end of Chapter 1, we introduce basic OOD concepts and terminology. In the optional Software Engineering Case Study sections at the ends of Chapters 3–6, we consider more substantial issues as we undertake a challenging problem with the techniques of OOD. We analyze a typical requirements document that specifies the system to be built, determine the classes needed to implement that system, determine the attributes the classes need to have, determine the behaviors the classes need to exhibit and specify how the classes must interact with one another to meet the system requirements. In Appendix J, we include a complete Visual Basic implementation of the object-oriented system that we design in the earlier chapters. We employ a carefully developed, incremental object-oriented design process to produce a UML model for our ATM system. From this design, we produce a substantial working Visual Basic implementation using key programming notions, including classes, objects, encapsulation, visibility, composition, inheritance and polymorphism.Web Forms, Web Controls and ASP.NET 2.0

The .NET platform enables developers to create robust, scalable Web-based applications. Microsoft’s .NET server-side technology, ASP.NET, allows programmers to build Web applications that respond to client requests. To enable interactive Web pages, server-side programs process information users input into HTML forms. ASP.NET provides enhanced visual programming capabilities, similar to those used in building Windows forms for desktop programs. Programmers can create Web pages visually, by dragging and dropping Web controls onto Web forms. Chapter 21, ASP.NET, Web Forms and Web Controls, introduces these powerful technologies.Web Services and ASP.NET 2.0

Microsoft’s .NET strategy embraces the Internet and Web as integral to software development and deployment. Web services technology enables information sharing, e-commerce and other interactions using standard Internet protocols and technologies, such as Hypertext Transfer Protocol (HTTP), Extensible Markup Language (

Object-Oriented Programming

Object-oriented programming is the most widely employed technique for developing robust, reusable software. This text offers a rich treatment of Visual Basic’s object-oriented programming features. Chapter 4 introduces how to create classes and objects. These concepts are extended in Chapter 9. Chapter 10 discusses how to create powerful new classes quickly by using inheritance to “absorb” the capabilities of existing classes. Chapter 11 familiarizes the reader with the crucial concepts of polymorphism, abstract classes, concrete classes and interfaces, which facilitate powerful manipulations among objects belonging to an inheritance hierarchy.

Use of the Extensible Markup Language (


Databases store vast amounts of information that individuals and organizations must access to conduct business. As an evolution of Microsoft’s ActiveX Data Objects (ADO) technology, ADO.NET represents a new approach for building applications that interact with databases. ADO.NET uses

Visual Studio 2005 Debugger

In Appendix C, we explain how to use key debugger features, such as setting “breakpoints” and “watches,” stepping into and out of methods, and examining the method call stack.Teaching Approach

Visual Basic 2005 for Programmers, 2/e contains a rich collection of examples that have been tested on Windows XP. The book concentrates on the principles of good software engineering and stresses program clarity. We avoid arcane terminology and syntax specifications in favor of teaching by example. We are educators who teach leading-edge topics in industry classrooms worldwide. Dr. Harvey M. Deitel has 22 years of college teaching experience and 17 years of industry teaching experience. Paul Deitel has 14 years of industry teaching experience. The Deitels have taught courses at all levels to government, industry, military and academic clients of Deitel & Associates.World Wide Web Access

All of the source-code examples for Visual Basic 2005 for Programmers, 2/e, are available for download from:

Site registration is quick and easy. Download all the examples, then run each program as you read the corresponding text discussions. Making changes to the examples and immediately seeing the effects of those changes is a great way to enhance your Visual Basic learning experience.Objectives

Each chapter begins with a statement of objectives. This lets you know what to expect and gives you an opportunity, after reading the chapter, to determine if you’ve met these objectives.Quotations

The learning objectives are followed by quotations. Some are humorous, philosophical or offer interesting insights. We hope that you’ll enjoy relating the quotations to the chapter material. Many of the quotations are worth a second look after reading the chapter.Outline

The chapter outline helps you approach the material in a top-down fashion, so you can anticipate what is to come, and set a comfortable and effective learning pace.16,232 Lines of Code in 215 Example Programs (with Program Outputs)

Our live-code programs range in size from just a few lines of code to substantial examples containing hundreds of lines of code (e.g., our ATM system implementation contains 597 lines of code). Each program is followed by screenshots of the outputs produced when the program is run, so you can confirm that the programs run as expected. Our programs demonstrate the diverse features of Visual Basic. The code is syntax shaded, with Visual Basic keywords, comments and other program text emphasized with variations of bold, italic and gray text. This makes reading the code easier, especially in the larger programs.807 Illustrations/Figures

An abundance of charts, tables, line drawings, programs and program outputs is included. We model the flow of control in control statements with UML activity diagrams. UML class diagrams model the fields, constructors and methods of classes. We use additional types of UML diagrams throughout our optional OOD/UML ATM case study.350 Programming Tips

We include programming tips to help readers focus on important aspects of program development. We highlight these tips as Good Programming Practices, Common Programming Errors, Error-Prevention Tips, Look-and-Feel Observations, Performance Tips, Portability Tips and Software Engineering Observations. These tips and practices represent the best we have gleaned from a combined six decades of programming, college teaching and professional training experience. The tips provide a basis on which to build good software.Good Programming Practice 1.1

Good Programming Practices call attention to techniques that will help you produce programs that are clearer, more understandable and more maintainable.Common Programming Error 1.1

Developers learning a language tend to make certain kinds of errors frequently. Pointing out these Common Programming Errors reduces the likelihood that you’ll make the same mistakes.Error-Prevention Tip 1.1

When we first designed this tip type, we thought the tips would contain suggestions for exposing bugs and removing them from programs. In fact, many of the tips describe aspects of Visual Basic that prevent bugs from getting into programs in the first place, thus simplifying the testing and debugging processes.Look-and-Feel Observation 1.1

We provide Look-and-Feel Observations to highlight graphical-user-interface conventions. These observations help you design attractive, user-friendly graphical user interfaces that conform to industry norms.Performance Tip 1.1

Programmers like to “turbo charge” their programs. We include Performance Tips that highlight opportunities for improving program performance—making programs run faster or minimizing the amount of memory that they occupy.Portability Tip 1.1

We include Portability Tips to help you write portable code and to explain how Visual Basic achieves its high degree of portability.Software Engineering Observation 1.1

The object-oriented programming paradigm necessitates a complete rethinking of the way we build software systems. Visual Basic is an effective language for achieving good software engineering. The Software Engineering Observations highlight architectural and design issues that affect the construction of software systems, especially large-scale systems.Wrap-Up Section

Each chapter ends with a brief “wrap-up” section that recaps the chapter content and transitions to the next chapter.Extensive Index

We have included an extensive index which is especially helpful when using the book as a reference.“Double Indexing” of Visual Basic Live-Code Examples

Visual Basic 2005 for Programmers, 2/e has 215 live-code examples, which we have double indexed. For every source-code program in the book, we indexed the figure caption both alphabetically and as a subindex item under “Examples.” This makes it easier to find examples using particular features.A Tour of the Optional Case Study on Object-Oriented Design with the UML

In this section we tour the book’s optional case study on object-oriented design with the UML. This tour previews the contents of the Software Engineering Case Study sections (in Chapters 1, 3–9, 11 and Appendix J). After completing this case study, you will be thoroughly familiar with an object-oriented design and implementation for a significant Visual Basic application.

The design presented in the ATM case study was developed at Deitel & Associates, Inc. and scrutinized by academic and industry professionals. Our primary goal was to create a simple design that would be clear to OOD and UML novices, while still demonstrating key OOD concepts and the related UML modeling techniques.

Section 1.9—(Only Required Section of the Case Study) Software Engineering Case Study: Introduction to Object Technology and the UML—introduces the object-oriented design case study with the UML. The section presents basic concepts and terminology of object technology, including classes, objects, encapsulation, inheritance and polymorphism. We discuss the history of the UML. This is the only required section of the case study.

Section 3.9—(Optional) Software Engineering Case Study: Examining the ATM Requirements Document—discusses a requirements document that specifies the requirements for a system that we will design and implement—the software for a simple automated teller machine (ATM). We investigate the structure and behavior of object-oriented systems in general. We discuss how the UML will facilitate the design process in subsequent Soft ware Engineering Case Study s

Meet the Author

Harvey M. Deitel and Paul J. Deitel are the founders of Deitel & Associates, Inc., the internationally recognized programming languages content-creation and corporate training organization. Together with their colleagues at Deitel & Associates, Inc., they have written many international best-selling programming languages textbooks and professional books that millions of people worldwide have used to master C, C++, Java™, C#, XML, Visual Basic®, Perl, Python, and Internet and Web programming.


Paul J. Deitel and Harvey M. Deitel are the founders of Deitel & Associates, Inc., the internationally recognized programming languages content-creation and corporate training organization. Together with their colleagues at Deitel & Associates, Inc., they have written many international best-selling programming languages textbooks and professional books that millions of people worldwide have used to master C, C++, Java™, C#, XML, Visual Basic®, Perl, Python, and Internet and Web programming.

Customer Reviews

Average Review:

Write a Review

and post it to your social network


Most Helpful Customer Reviews

See all customer reviews >