SKIP THE SHIPPING
Use code NOSHIP during checkout to save 40% on eligible eBooks, now through January 5. Shop now.
Register your product to gain access to bonus material or receive a coupon.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
Sams Teach Yourself Visual Basic® 2010 in 24 Hours
James Foxall
STARTER KIT
DVD includes Visual Basic 2010 Express Edition
In just 24 sessions of one hour or less, you’ll learn how to build complete, reliable, and modern applications with Visual Basic 2010. Using this book’s straightforward, step-by-step approach, you’ll master the entire process, from navigating VB 2010 to deploying finished solutions. You’ll learn how to write efficient object-oriented code; build superior user interfaces; work with graphics, text, and databases; and even control external applications. Each lesson builds on what you’ve already learned, giving you a strong, practical foundation for success!
Step-by-step instructions carefully walk you through the most common Visual Basic 2010 tasks.
Quizzes and Exercises at the end of each chapter help you test your knowledge.
By the Way notes present interesting information related to the discussion.
Did You Know? tips offer advice or show you easier ways to perform tasks.
Watch Out! cautions alert you to possible problems and give you advice on how to avoid them.
Learn how to…
James Foxall is President of Tigerpaw Software, Inc., a 25 year old commercial software company with more than 25,000 users. He is a leading authority on interface and behavior standards for Windows and Office environments and is an expert on improving business processes through technology. He contributes to several journals and magazines, speaks internationally, teaches college courses on Visual Basic, and has been featured widely in print and online media for his technology expertise.
DVD Includes: Microsoft® Visual Basic 2010 Express Edition
On the Web: Access code examples from the book, as well as updates, and corrections as they become available at informit.com/title/9780672331138
Introduction 1
PART I: The Visual Basic 2010 Environment
HOUR 1: Jumping in with Both Feet: A Visual Basic 2010 Programming Tour 5
Starting Visual Basic 2010 ....................................................................................6
Creating a New Project ..........................................................................................7
Understanding the Visual Studio 2010 Environment ........................................10
Changing the Characteristics of Objects ............................................................11
Adding Controls to a Form..................................................................................16
Designing an Interface ........................................................................................17
Writing the Code Behind an Interface................................................................21
Running a Project ................................................................................................25
HOUR 2: Navigating Visual Basic 2010 29
Using the Visual Basic 2010 Start Page ..............................................................30
Navigating and Customizing the Visual Basic Environment ............................32
Working with Toolbars ........................................................................................37
Adding Controls to a Form Using the Toolbox ..................................................38
Setting Object Properties Using the Properties Window ....................................40
Managing Projects ..............................................................................................45
A Quick-and-Dirty Programming Primer ..........................................................51
Getting Help ........................................................................................................53
HOUR 3: Understanding Objects and Collections 57
Understanding Objects ........................................................................................58
Understanding Properties ....................................................................................58
Understanding Methods ......................................................................................65
Building a Simple Object Example Project ........................................................67
Understanding Collections ..................................................................................72
Using the Object Browser ....................................................................................75
00_067233318X_fm.qxd 4/16/10 11:35 AM Page iv
HOUR 4: Understanding Events 79
Understanding Event-Driven Programming ......................................................79
Building an Event Example Project ....................................................................87
Keeping Event Names Current ............................................................................92
PART II: Building a User Interface
HOUR 5: Building Forms: The Basics 95
Changing a Form’s Name ..................................................................................96
Changing a Form’s Appearance ........................................................................97
Showing and Hiding Forms ..............................................................................107
HOUR 6: Building Forms: Advanced Techniques 117
Working with Controls ......................................................................................117
Creating Topmost Nonmodal Windows............................................................134
Creating Transparent Forms..............................................................................134
Creating Scrollable Forms..................................................................................134
Creating MDI Forms ..........................................................................................136
Setting the Startup Form....................................................................................140
HOUR 7: Working with Traditional Controls 145
Displaying Static Text with the Label Control ................................................145
Allowing Users to Enter Text Using a Text Box ................................................146
Creating Buttons................................................................................................154
Creating Containers and Groups of Option Buttons........................................157
Displaying a List with the List Box ..................................................................161
Creating Drop-Down Lists Using the
Combo Box ........................................................................................................168
HOUR 8: Using Advanced Controls 173
Creating Timers ................................................................................................174
Creating Tabbed Dialog Boxes ..........................................................................177
Storing Pictures in an Image List Control ......................................................180
Building Enhanced Lists Using the List View Control ....................................182
Creating Hierarchical Lists Using the
Tree View Control ............................................................................................187
HOUR 9: Adding Menus and Toolbars to Forms 195
Building Menus..................................................................................................196
Using the Toolbar Control ................................................................................207
Creating a Status Bar ........................................................................................213
PART III: Making Things Happen–Programming
HOUR 10: Creating and Calling Code Procedures 217
Creating Visual Basic Code Modules ................................................................217
Writing Code Procedures ..................................................................................219
Calling Code Procedures....................................................................................225
Exiting Procedures ............................................................................................231
Avoiding Infinite Recursion ..............................................................................232
HOUR 11: Using Constants, Data Types, Variables, and Arrays 237
Understanding Data Types ................................................................................238
Defining and Using Constants ..........................................................................242
Declaring and Referencing Variables................................................................244
Working with Arrays..........................................................................................250
Determining Scope ............................................................................................254
Declaring Variables of Static Scope ..................................................................258
Naming Conventions ........................................................................................259
Using Variables in Your Picture Viewer Project ................................................261
HOUR 12: Performing Arithmetic, String Manipulation, and Date/Time Adjustments 269
Performing Basic Arithmetic Operations with Visual Basic ............................270
Comparing Equalities ........................................................................................274
Understanding Boolean Logic ..........................................................................274
Manipulating Strings ........................................................................................278
Working with Dates and Times ........................................................................283
HOUR 13: Making Decisions in Visual Basic Code 293
Making Decisions Using If...Then ................................................................293
Branching Within a Procedure Using GoTo ......................................................304
HOUR 14: Looping for Efficiency 309
Looping a Specific Number of Times Using For...Next ................................309
Using Do...Loop to Loop an Indeterminate Number of Times ......................315
HOUR 15: Debugging Your Code 323
Adding Comments to Your Code ......................................................................324
Identifying the Two Basic Types of Errors ........................................................326
Using Visual Basic’s Debugging Tools ..............................................................329
Writing an Error Handler Using Try...Catch...Finally ............................336
HOUR 16: Designing Objects Using Classes 347
Understanding Classes ......................................................................................348
Instantiating Objects from Classes....................................................................357
HOUR 17: Interacting with Users 367
Displaying Messages Using the MessageBox.Show() Function ......................367
Creating Custom Dialog Boxes ........................................................................373
Using InputBox() to Get Information from a User ........................................377
Interacting with the Keyboard ..........................................................................379
Using the Common Mouse Events ....................................................................382
HOUR 18: Working with Graphics 389
Understanding the Graphics Object ................................................................389
Working with Pens ............................................................................................392
Using System Colors ..........................................................................................393
Working with Rectangles ..................................................................................396
Drawing Shapes ................................................................................................397
Drawing Text......................................................................................................399
Persisting Graphics on a Form..........................................................................400
Building a Graphics Project Example ..............................................................400
PART IV: Working with Data
HOUR 19: Performing File Operations 409
Using the OpenFileDialog and SaveFileDialog Controls ............................409
Manipulating Files with the File Object..........................................................415
Manipulating Directories with the Directory Object ....................................424
HOUR 20: Working with the Registry and Text Files 427
Working with the Registry ................................................................................427
Reading and Writing Text Files ........................................................................439
HOUR 21: Working with a Database 451
Introducing ADO.NET ......................................................................................452
Manipulating Data............................................................................................456
HOUR 22: Controlling Other Applications Using Automation 469
Automating Microsoft Excel ..............................................................................470
Automating Microsoft Word..............................................................................475
PART V: Deploying Solutions and Beyond
HOUR 23: Deploying Applications 481
Understanding ClickOnce Technology ..............................................................481
Using the Publish Wizard to Create a ClickOnce Application ........................482
Testing Your Picture Viewer ClickOnce Install Program ..................................486
Uninstalling an Application You’ve Distributed ..............................................486
Setting Advanced Options for Creating ClickOnce Programs..........................488
HOUR 24: The 10,000-Foot View 491
The .NET Framework ........................................................................................491
Common Language Runtime............................................................................492
Microsoft Intermediate Language ....................................................................493
Namespaces ......................................................................................................494
Common Type System ......................................................................................496
Garbage Collection ............................................................................................496
Further Reading ................................................................................................497
TOC, 9780672331138, 4/19/10