Enjoy millions of ebooks, audiobooks, magazines, and more, with a free trial

Only $11.99/month after trial. Cancel anytime.

Start-to-Finish Visual Basic 2015
Start-to-Finish Visual Basic 2015
Start-to-Finish Visual Basic 2015
Ebook1,231 pages15 hours

Start-to-Finish Visual Basic 2015

Rating: 5 out of 5 stars

5/5

()

Read preview

About this ebook

Nobody learns a programming language just to brag about writing loops. Instead, languages exist so you can create great software. That’s the purpose of Start-to-Finish Visual Basic 2015, to show you how to write a complete, useful, working application in Visual Basic and .NET.

Each chapter introduces essential Visual Basic concepts, and shows you how to apply them by crafting a full business-level application. With this comprehensive book, you will:

> Understand how to design and implement .NET applications

> Learn the core features of the Visual Basic language

> Access and modify database content using ADO.NET

> Perform advanced development activities, including cryptography and localization

> Master cool VB features, such as Generics, XML Literals, and LINQ

> Get a head start on programming via the downloadable source code

Whether you’re new to programming, or want to add Visual Basic to your existing skillset, Start-to-Finish Visual Basic 2015 will guide you step-by-step through the learning process.

LanguageEnglish
PublisherOwani Press
Release dateApr 1, 2016
ISBN9780996465410
Start-to-Finish Visual Basic 2015
Read preview

Read more from Tim Patrick

Related to Start-to-Finish Visual Basic 2015

Related ebooks

Related articles

Reviews for Start-to-Finish Visual Basic 2015

Rating: 5 out of 5 stars
5/5

2 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Start-to-Finish Visual Basic 2015 - Tim Patrick

    Preface

    Welcome to Start-to-Finish Visual Basic 2015! 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 data types available to you, or interacting with a database. If you already know how to use Visual Basic 6.0 or earlier, that’s fine, but this book doesn’t assume you’ve used that earlier VB platform.

    You want to write programs

    Most programming books teach you to write code in ten-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 ten-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 twenty-five easy-to-read chapters, and had my publisher 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 over three decades, and these days I write custom database-oriented .NET 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 fifty-three pounds and cost $254.38, plus tax. To get every line of source code, you’ll have to download the accompanying sample 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.

    About the 2015 Edition

    If you had a chance to peruse earlier editions of this book, you will find some significant changes in this update. When the book first appeared in 2005, only three years had elapsed since Microsoft first offered the .NET version of Visual Basic. Many readers of books like this were migrating from Visual Basic 6.0 to the .NET variation, and the code discussed in the text reflected that reality.

    Now that more than a decade has passed, there is less of a focus on helping pre-.NET Visual Basic developers transfer their knowledge to .NET. Because of this, some discussions of intrinsic Visual Basic features have been replaced with language-neutral .NET equivalents. In such cases, while the specific syntax in the code will have changed, the functionality is equivalent. This change will also help existing C# developers who need to add Visual Basic to their .NET repertoire.

    The application developed throughout the first edition of the book relied on Windows Forms, a .NET library used to create desktop application with the ease of drag-and-drop programming. For many years it was the dominant tool for creating Microsoft Windows desktop applications. Subsequent editions of Visual Studio introduced new tools and libraries for building desktop apps: Silverlight, XAML, Windows Presentation Framework, the Metro UI, and most recently, the Universal Windows Platform. These newer systems let you create advanced user interfaces, complete with animation and cross-platform capabilities.

    As powerful and flexible as these new libraries are, they also bring with them an increased level of complexity for developers, especially those new to the .NET Framework. The focus of Start-to-Finish Visual Basic 2015 is Visual Basic, the development language. In order to reduce confusion and keep the focus on the language itself, I have opted to keep the mature and stable Windows Forms code base in this edition. Although Windows Forms might not be as glitzy as Windows Store development, it still has access to the full power of Visual Basic, and is therefore a great, low-distraction tool for learning the language.

    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 Visual Studio’s File→New Project menu. Appendix A, Installing the Software, has all of the download and installation details.

    I wrote the project code using Visual Studio 2015 Community Edition, but it will work in all editions of Visual Studio 2015. 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 also uses SQL Server 2014 for its database storage. You can use any edition of SQL Server 2014, including the free Express Edition. Chapter 4 introduces databases and SQL Server 2014. 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 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, Software License Agreement), 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!)

    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 the full sample code 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, Software License Agreement.

    If you feel your use of code examples falls outside fair use or the permissions given here, feel free to contact me at tim@timaki.com.

    Acknowledgments

    The development of Start-to-Finish Visual Basic 2015 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 way back in 2005. 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.

    Claudette Moore, my longsuffering agent for my years until her recent retirement, 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. While she has pulled her hat out of the agenting ring, her former hat-in-ring days will never be forgotten.

    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.

    Chapter 1

    Introducing .NET

    Welcome to .NET! I might as well have said, Welcome to the universe, because like the universe, .NET is huge. And it’s complex. And it’s filled with black holes and other things that don’t always make sense. Yet it (.NET, not the universe) turns out to be a fantastic system in which to develop software applications.

    The .NET Framework was not developed in a vacuum (unlike the universe); Microsoft designed it and its related development languages—especially C# and Visual Basic—to address various issues that plagued Windows software developers and users. To fully understand why .NET was necessary, we need to take a short trip down computer memory lane.

    Before .NET

    Practical, general-purpose computers have been around since the mid-twentieth century. However, they were inaccessible to most people because (a) they cost millions of dollars; (b) they consumed gobs of electricity; (c) maintenance and programming could be done only by highly trained specialists; and (d) they tended to clash with the living room furniture.

    Fast-forward about thirty years. IBM comes out with the personal computer. These desktop computers represented a great advance in technology, but only a minority of people ever used them. They continued to be expensive (thousands of dollars), and maintenance and programming still required significant investments in training. IBM PCs also looked hideous around the living room furniture.

    Then came the Apple Macintosh. With its sleek design and its user-friendly functionality, it introduced the joy of computing to the masses. And while programming it was not always straightforward, it did give nice results. It’s no wonder that Microsoft decided to copy—oops, I mean improve upon—its functionality.

    Microsoft Windows 1.0 brought a greater level of usability to the IBM/Intel computing platform. But it wasn’t a free ride for programmers. MS-DOS development was hard enough without the addition of the message pumps and the hundreds of Application Programming Interface (API) calls needed by Windows programs. Visual Basic 1.0, introduced in 1991, greatly simplified the development process, but with the advent of 32-bit systems, ActiveX and COM components, and the Web, even VB programmers soon felt overwhelmed.

    Throughout the 1990s, the situation only seemed to worsen. Microsoft saw increased competition in the form of the Java™ language and the Linux operating system. Hackers were exploiting buffer overruns and other security issues present in the Windows platform. Users experienced myriad computer problems stemming from conflicting standards, competing data integration technologies, registry bloat, and DLL hell. In frustration, an Excel user’s group set fire to the entire Microsoft campus in Redmond.

    Well, it didn’t get that bad. But Microsoft did see that it needed to address the overall software development and usability issues on its beloved Windows platform. Its solution came in the form of the .NET Framework.

    Back to Introducing .NET

    When Microsoft announced its plans for .NET, it surprised many developers, especially Visual Basic developers, who saw it as a giant step backward for Rapid Application Development. But the release of the .NET Framework version 1.0 in 2002 did bring many needed benefits.

    .NET introduced a unified programming environment

    All .NET-enabled languages compile to Microsoft Intermediate Language before being assembled into platform-specific machine code. Visual Basic, C#, and other .NET languages are wrappers around this common .NET language.