this print for content only—size & color not accurate spine = 1.028" 544 page count BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® Beginning Visual Basic 2005 Express Edition: From Novice to Professional Dear Reader, In the 90s Microsoft did the impossible and released a programming tool that let everyone write programs to run on Windows. I was so excited about that tool, Visual Basic, that I wrote a series of books on it and introduced nearly a quarter of a million people all over the world to programming. Now Microsoft has done it again with the release of the Express tools. With nearly every home having a computer and most people having access to the Internet, being able to take control of the computer and write your own pro- grams is more useful and exciting than ever. So, I decided to do it again too. In this book you’ll find everything you need to program your computer by using Visual Basic 2005 Express, one of the very latest programming tools from Microsoft. I’ve even included Visual Basic 2005 Express on the CD in the book, so this is a one-stop shop to get up to speed fast. If you have never written computer programs before, I’ll show you how much fun and how easy it can be. Perhaps you are a programmer and just need to get up to speed on .NET for work—this book is for you too. I took the same approach with this book that I did with the VB ones, and inside you’ll find a fast-paced guide to the essentials to get you programming fast. You’ll learn the Visual Basic 2005 language and the tools Visual Basic 2005 Express provides. I cover everything from simple console programs to code that talks to the Internet, and even how to write your own database programs. Whatever your reasons for wanting to learn to program with Visual Basic, my book will get you where you want to be quickly, and hopefully with a smile on your face. So dive in and change the way you use computers forever. Peter Wright Author of ADO.NET: From Novice to Pro, Visual Basic .NET Edition Beginning Visual Basic 6 Beginning Visual Basic 6 Objects Beginning Visual Basic 5 Beginning Objects with Visual Basic 5 The Beginner’s Guide to Visual Basic 4.0 The Beginner’s Guide to Visual Basic 3 Beginning Visual C# 2005 Express Edition: From Novice to Professional US $29.99 Shelve in Programming User level: Beginner–Intermediate Wright Visual Basic 2005 Express Edition THE EXPERT’S VOICE ® IN .NET Peter Wright Beginning Visual Basic 2005 Express Edition From Novice to Professional CYAN MAGENTA YELLOW BLACK PANTONE 123 CV ISBN 1-59059-622-6 9 781590 596227 52999 6 89253 59622 7 INCLUDED Companion eBook Available Includes Microsoft Visual Basic 2005 Express Edition Includes Microsoft Visual Basic 2005 Express Edition www.apress.com SOURCE CODE ONLINE Companion eBook See last page for details on $10 eBook version forums.apress.com FOR PROFESSIONALS BY PROFESSIONALS ™ Join online discussions: THE APRESS ROADMAP Pro VB 2005 and the .NET 2.0 Platform, 2E Beginning Visual Basic 2005 Express Edition Expert VB 2005 Business Objects, 2E Beginning Object-Oriented Programming with VB 2005 Beginning DotNetNuke 4.0 Website Creation in VB 2005 Beginning Beginning Visual Basic 2005 Express Edition From Novice to Professional ■■■ Peter Wright 6226.book Page i Tuesday, August 29, 2006 8:22 PM Beginning Visual Basic 2005 Express Edition: From Novice to Professional Copyright © 2006 by Peter Wright All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-622-7 ISBN-10 (pbk): 1-59059-622-6 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Jim Sumser Technical Reviewer: Jason Bock Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade Associate Publisher, Production Director, and Project Manager: Grace Wong Copy Edit Manager: Nicole LeClerc Copy Editors: Sharon Wilkey, Ami Knox Assistant Production Director: Kari Brooks-Copony Senior Production Editor: Laura Cheu Compositor: Pat Christenson Proofreader: Nancy Riddiough Indexer: Broccoli Information Management Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code section. You will need to answer questions pertaining to this book in order to successfully download the code. 6226.book Page ii Tuesday, August 29, 2006 8:22 PM iii Contents at a Glance About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xi About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv ■CHAPTER 1 Welcome to Visual Basic Express . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 ■CHAPTER 2 The Basics of Visual Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 ■CHAPTER 3 Working with Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 ■CHAPTER 4 Classes and Object Orientation in Visual Basic 2005. . . . . . . . . . . . 93 ■CHAPTER 5 More-Advanced Object Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 ■CHAPTER 6 Handling Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 ■CHAPTER 7 How Visual Basic 2005 Express Helps You Code . . . . . . . . . . . . . . 171 ■CHAPTER 8 Building Windows Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 ■CHAPTER 9 Windows and Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 ■CHAPTER 10 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 ■CHAPTER 11 Menus and Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 ■CHAPTER 12 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 ■CHAPTER 13 Lists and Generics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 ■CHAPTER 14 Files and Streams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 ■CHAPTER 15 Working with XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 ■CHAPTER 16 Database Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 ■CHAPTER 17 The Internet and Visual Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449 ■CHAPTER 18 Threading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 ■CHAPTER 19 Where to Now? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 ■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 6226.book Page iii Tuesday, August 29, 2006 8:22 PM 6226.book Page iv Tuesday, August 29, 2006 8:22 PM v Contents About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xi About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv ■CHAPTER 1 Welcome to Visual Basic Express . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Just What Is Express? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Exploring the Visual Basic 2005 Express IDE. . . . . . . . . . . . . . . . . . . . . . . . . 4 Exploring the IDE a Little More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Working with the Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Writing Your Own Web Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 ■CHAPTER 2 The Basics of Visual Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 The Basic Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Source Code and the Two Project Types . . . . . . . . . . . . . . . . . . . . . . 37 Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Inheritance and Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Control Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 ■CHAPTER 3 Working with Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 The Basic Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Integers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Other Number Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Boolean Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Characters and Text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Making Decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 If Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Select Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 6226.book Page v Tuesday, August 29, 2006 8:22 PM vi ■CONTENTS Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 While Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 For Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 ■CHAPTER 4 Classes and Object Orientation in Visual Basic 2005. . . . . 93 Classes and Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Creating Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Using Constructors and Finalizers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Properties and Members. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Getters and Setters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Scoping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Public. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Private. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Shared. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 ■CHAPTER 5 More-Advanced Object Orientation. . . . . . . . . . . . . . . . . . . . . . . 127 Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Virtual Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Abstract Methods and Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Beware Shadows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Casting Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Reference Types and Value Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 ■CHAPTER 6 Handling Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Understanding Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Handling Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Bubbling Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Throwing Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Custom Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 6226.book Page vi Tuesday, August 29, 2006 8:22 PM ■CONTENTS vii ■CHAPTER 7 How Visual Basic 2005 Express Helps You Code . . . . . . . . 171 Building a User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Using Property Smart Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Aligning Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Setting Tab Orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Using IntelliSense . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 Automatically Fixing Namespace Problems . . . . . . . . . . . . . . . . . . . 181 Using Code Snippets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 ■CHAPTER 8 Building Windows Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . 187 How Windows Programs Work. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Common Properties and Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Buttons in All Their Glory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Entering Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 Text Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 The MaskedTextBox Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 Adding ToolTip Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 Choosing Things: Radio Buttons and Check Boxes . . . . . . . . . . . . . . . . . 215 Date Pickers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 ■CHAPTER 9 Windows and Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Windows (or Forms) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 The Main Window and How to Change It . . . . . . . . . . . . . . . . . . . . . 228 Opening and Closing Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Styles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 The Life and Times of a Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 MDI (Multiple Document Interface) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 Using a Simple Message Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 Creating Your Own Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 Common Dialogs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 6226.book Page vii Tuesday, August 29, 2006 8:22 PM viii ■CONTENTS ■CHAPTER 10 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 The ListBox Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 The CheckedListBox Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 The ComboBox Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 The TreeView Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Changing the Visual Appearance of the Tree . . . . . . . . . . . . . . . . . . 285 Responding to Selections and Finding Nodes . . . . . . . . . . . . . . . . . 292 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 ■CHAPTER 11 Menus and Toolbars. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 The Menu Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 Building a Menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Adding Images and Shortcuts to a Menu . . . . . . . . . . . . . . . . . . . . . 299 Menus in an MDI Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 The Context Menu Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 Toolbars and Status Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 ■CHAPTER 12 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Hooking Events by Hand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Creating Custom Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 ■CHAPTER 13 Lists and Generics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 Introducing Generics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 Lists and SortedLists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 Stacks and Queues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 Creating Your Own Generics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 6226.book Page viii Tuesday, August 29, 2006 8:22 PM ■CONTENTS ix ■CHAPTER 14 Files and Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 Working with Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 The FileSystemWatcher Class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 The File and Directory Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366 Working with Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 The Core Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 Working with File Streams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372 Working with Network Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 ■CHAPTER 15 Working with XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 System.Xml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 Searching XML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 Reading XML Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 Writing XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414 ■CHAPTER 16 Database Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 A Quick Walk-Through of the Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 Exploring the Database Creation Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . 424 Writing Database Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 An Overview of Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448 ■CHAPTER 17 The Internet and Visual Basic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449 Introducing the WebBrowser Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449 Working with the WebBrowser Control . . . . . . . . . . . . . . . . . . . . . . . 454 Accessing the Web Through Code . . . . . . . . . . . . . . . . . . . . . . . . . . 456 Handling Other Types of Data with WebClient . . . . . . . . . . . . . . . . . 465 Using Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480 6226.book Page ix Tuesday, August 29, 2006 8:22 PM [...]... able to find plenty of reasons to jump ship completely! So, what exactly do I cover? Chapter 1: Welcome to Visual Basic Express Firing up Visual Basic 2005 Express for the first time can be a little daunting There are a myriad of buttons, menus, and options to twiddle with, and no obvious best place to start In this chapter I’ll walk you through just what it’s like to use the Visual Basic 2005 Express. .. market today at products such as Delphi, JBuilder, C#Builder, and of course Visual Studio NET to instantly spot similarities between those tools and good old-fashioned classic Visual Basic You can see the warm welcoming UI of Visual Basic 2005 Express in Figure 1-1 Visual Basic 2005 Express is the result of the years of experience Microsoft has had with VB as a whole Everything that made Visual Basic. .. BASIC EXPRESS Just What Is Express? Express is the name given by Microsoft to a range of entry-level NET 2.0 development tools Each tool (there are six in all) is focused on allowing you to learn how to develop one specific kind of application For example, Visual Web Developer 2005 Express is focused on developing web applications Visual Basic 2005 Express and Visual C# 2005 Express are both focused... our own full-blown Windows application together What better way to get your head wet than to just dive straight in? Chapter 2: The Basics of Visual Basic In Chapter 2 you’ll start exploring the Visual Basic language itself There are two aspects to the package: the Visual Basic 2005 Express integrated development environment (IDE) and the Visual Basic language In this chapter we’ll turn away from the pretty... CHAPTER 1 ■ WELCOME TO VISUAL BASIC EXPRESS target a base processor compatible with all machines to let the programs run on the widest possible range of hardware Figure 1-1 The clean, welcoming user interface of Visual Basic 2005 Express Visual Basic 2005 is also a fully object-oriented (OO) language now If that means nothing at all to you, don’t worry We’ll go into the full details of object-oriented programming... all of Visual Basic s tools for processing and dealing with exceptions Chapter 7: How Visual Basic 2005 Express Helps You Code Now we get to return to the IDE Visual Basic 2005 Express has a ton of features designed to help you write programs In fact, features such as IntelliSense can actually write some of the code for you, while features in the graphical designer tools let you build standards-conforming... versions of Visual Studio NET, as well as the new Visual Studio 2005 The best way to learn everything the package can do, and to get comfortable with it, is to use it So, if you haven’t installed Visual Basic 2005 Express already, now is the time to do so Exploring the Visual Basic 2005 Express IDE It’s a tired tradition that the first program you write when learning a new programming language or tool is... finished Visual Basic 2005 Express carries this tradition forward It’s just as easy today to write programs for the very latest versions of Windows as it was back then to create programs for Windows 3.0 Visual Basic 2005, though, while strikingly similar to classic Visual Basic in many areas, is radically different in others The language has evolved and is now a truly object-oriented language Because Visual. .. accomplished Visual Basic or Java developer, or perhaps a NET developer looking to learn new things with Express, this is the chapter where you’ll see some of the most obvious and stunning changes that Microsoft has made to its development environments in the Express tools A lot of the functionality in Visual Basic 2005 Express comes from Visual Studio NET 2005, so you’ll get a glimpse into just what... that tool were focused totally on solving the sorts of problems the big boys faced every day Express was a radical U-turn Once again Microsoft was returning to its roots by making available easy -to- use programming tools that sacrificed nothing in terms of power and that would be available to all budgets Since the first ever release of NET, Visual Basic has matured into a wonderfully elegant object-oriented . of ADO.NET: From Novice to Pro, Visual Basic .NET Edition Beginning Visual Basic 6 Beginning Visual Basic 6 Objects Beginning Visual Basic 5 Beginning Objects with Visual Basic 5 The Beginner’s Guide to Visual. level: Beginner–Intermediate Wright Visual Basic 2005 Express Edition THE EXPERT’S VOICE ® IN .NET Peter Wright Beginning Visual Basic 2005 Express Edition From Novice to Professional CYAN MAGENTA YELLOW BLACK PANTONE 123. Objects, 2E Beginning Object-Oriented Programming with VB 2005 Beginning DotNetNuke 4.0 Website Creation in VB 2005 Beginning Beginning Visual Basic 2005 Express Edition From Novice to Professional ■■■ Peter