Preface

Welcome to Programming Visual Basic 2008! I know you’re going to enjoy it; I’ve read it five times already. You’re probably anxious to get to Chapter 1, but I recommend you read this preface to make sure you paid for the right book.

Who Is Reading This Book?

Writing a book is a lot like writing a Visual Basic application. Well, except for the part about finding a publisher, and working with an editor. And then there’s that pesky rule about correct spelling. Come to think of it, they’re really quite different. But in one way, books and programs are similar: both are written to meet the needs of the user. When writing software applications, the user’s needs drive the organization and features of the final program. When writing a book, like the one you’re looking at now, the needs of the user—that’s you, the reader—drive the organization and features of the final text.

So it was with you in mind that I set out to write this book. Oh, there’s the fame and the prestige, but it’s really about you. You, the person who seeks to understand Visual Basic and the .NET Framework on which it is built. When I thought about you and your needs, I came up with these ideas:

You might know how to program, but maybe not

In the programming world, there are four types of people: (1) those who already program joyfully; (2) those who don’t program, but will learn it and love it; (3) those who don’t program, but will learn it and struggle with it; and (4) those who should return this book immediately to the bookstore. If you are in one of the first three groups, this book is definitely for you. I believe that anyone who can break down a task into its basic step-by-step instructions can successfully program in Visual Basic. If you are unsure about your ability to quantify tasks in this way, you might want to start out with a book on basic programming concepts.

You might know how to program in Visual Basic or .NET, but maybe not

And that’s OK, because this book will teach you. Most of the chapters introduce important topics in Visual Basic and .NET development, such as object-oriented programming concepts, or using the different types of variables available to you, or interacting with a database. If you already know how to use Visual Basic 6 or earlier, that’s great, but it’s not a prerequisite.

You want to write programs

Most programming books teach you to write code in 10-line increments. At least that’s what’s scattered throughout their pages. I’ve put some of those “code snippets” in this book. But I spend my days writing real programs, not 10-line sample programs. If you want to write whole programs, you should learn using whole programs. That’s why I also put a program in my book—a whole program. Over the next several hundred pages, I will develop a real program—a database for a small library—and you will write it with me.

I put all of these ideas into 26 easy-to-read chapters, and had O’Reilly Media glue the pages together for your convenience. When you reach the index, you will have learned how to write complete programs in Visual Basic and .NET. It will be a programming adventure, so let’s get started!

What’s in This Book?

Since we are going to be spending a lot of time together, you probably want to know something about me. Well, my name is Tim Patrick, and for many years I lived just up the street from the big Microsoft campus. I’ve been writing programs for 25 years, and these days I write custom database-oriented Visual Basic applications for small to medium-size businesses. And I’m not alone. Most Visual Basic developers write business-level software. If that’s what you do, or plan to do, you’re in great company.

As you move through the pages of this book, you will read about the major .NET and Visual Basic activities that drive the development of business-level and general consumer applications. If you plan to do some other type of programming, such as game development, this book will be somewhat helpful, but I don’t talk about advanced or specialized features such as interactive 3D models or geometric transformations.

Each chapter discusses a major programming topic, and then follows it up with a practical implementation of that topic: the creation of the Library database program. I don’t show every line of code in the book; if I did, the book would weigh 53 pounds and cost $254.38, plus tax. To get every line of source code, you’ll have to download the accompanying source code from the book’s web site. The code and the book’s text are united in one purpose: to train you in the skilled use of Visual Basic on the .NET platform so that you can develop the highest-quality applications possible. The text and the source code both include valuable resources that you can use every day in your programming life.

What’s in the Software Download?

You’re going to like the download. It contains all the source code for the Library database project. What’s cool is that when you install the source code examples, they become part of Visual Studio. Once they are installed, you can create a new chapter-specific project right from the File → New Project menu in Visual Studio. Appendix A has all of the download and installation details.

I wrote the project code using Visual Basic 2008 Professional Edition. Some portions may not be compatible with earlier .NET versions of the language. None of it is compatible with Visual Basic 6.0 or earlier, so don’t even bother trying. The source code will work with any edition of Visual Basic 2008, including the Express Edition.

The source code also uses SQL Server 2005 for its database storage. You can use any edition of SQL Server 2005, including the Express Edition. Chapter 4 introduces databases and SQL Server 2005. If you will be using the database in an IT department-controlled network environment, you may need to talk with your IT department representative about installing the sample database. The SQL code I use is pretty vanilla, so it should work on previous versions of SQL Server, and you could easily adjust it to work with Oracle, DB2, Microsoft Access, or other common database engines. You can also use the upcoming SQL Server 2008 if you have it available.

You can use the downloadable source code for your own projects, but please give credit where credit is due. There is a license agreement associated with the code (see Appendix B), so please don’t go selling the software as your own work. Just to be on the safe side, I’ve added a few hard-to-find bugs. Just kidding! (No, I’m not!)

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, filenames, and file extensions.

Constant width

Indicates computer coding in a broad sense. This includes all Visual Basic source code, HTML content, XML content, commands, options, source code from other languages, and content generated by Visual Studio tools.

Constant width bold

Indicates commands or other text that the user should type literally. Also used to highlight a particular section of code.

Constant width italics

Indicates text that should be replaced with user-supplied values or values determined by context.

Tip

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact the publisher or me for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation requires that you abide by the terms of the software license agreement found in Appendix B.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Programming Visual Basic 2008, by Tim Patrick. Copyright 2008 Tim Patrick, 978-0-596-51843-1.”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us as .

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/9780596518431

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:

http://www.oreilly.com/

Safari® Books Online

When you see a Safari® Books Online icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

Acknowledgments

The development of Programming Visual Basic 2008 has been a labor of love for me, and I am blessed to have had so many others go through the labor with me. Joan Murray from Addison-Wesley was my editor on the first edition of the book. John Osborn at O’Reilly Media took up the task of guiding the second edition. I have been fortunate to have worked with John on three different book projects, and their success was possible thanks to his gallant efforts.

Several other authors and programmers took time out of their day jobs to review each chapter of the book and point out its deficiencies, which were numerous before their arrival. I especially wish to thank Glenn Berry, Alex Bierhaus, Harry Chen, Ken Getz, Lowell Mauer, and Dan Sullivan for their superb comments. When it came time to focus on Visual Basic’s 2008 release, I also received fantastic input from Chris Williams, Daniel Seara, Ron Petrusha, and Sander Gerz.

Many thanks to Joe Binder, Jay Roxe, Prasadi de Silva, and Eric Knox, all members of the Visual Basic team at Microsoft. Each of them fielded a relentless onslaught of questions about esoteric Visual Basic and .NET features, and provided answers filled with knowledge, patience, and grace.

My agent, Claudette Moore, always deserves her own paragraph in any computer book I write. In fact, she would be a great subject for one of those literary-agent-focused biographies that the public is always clamoring for. Not only does she do a great job at all of the normal agenty things, but she also shares personally in the joys and sorrows of the authors under her charge. Thank you for another fun year in books.

To Maki, my wife, and to Spencer, my son, I give a special wave of thanks. If you’ve ever spent time with authors, you know how cranky they can get. But Maki and Spencer combat crankiness with care and love, and it works. The words thank you seem so inadequate when I owe both of them so much. Thanks be to God because He provided such a tremendous family to me.

Get Programming Visual Basic 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.