ebook img

Sams Teach Yourself More Visual Basic .NET in 21 Days PDF

599 Pages·2001·13.097 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Sams Teach Yourself More Visual Basic .NET in 21 Days

Lowell Mauer Teach Yourself More Visual Basic .NET 21 in Days 800 East 96th St.,Indianapolis,Indiana,46240 USA www.it-ebooks.info Sams Teach Yourself More Visual Basic ASSOCIATEPUBLISHER Linda Engelman .NET in 21 Days MANAGINGEDITOR Copyright ©2002 by Sams Publishing Charlotte Clapp All rights reserved. No part of this book shall be reproduced,stored in a ACQUISITIONSEDITOR retrieval system,or transmitted by any means,electronic,mechanical,photo- Sondra Scott copying,recording,or otherwise,without written permission from the publish- DEVELOPMENTEDITOR er. No patent liability is assumed with respect to the use of the information Susan Shaw Dunn contained herein. Although every precaution has been taken in the preparation of this book,the publisher and author assume no responsibility for errors or PROJECTEDITOR omissions. Neither is any liability assumed for damages resulting from the use Anthony Reitz of the information contained herein. For information,address Sams Publishing, 201 W. 103rd Street,Indianapolis,IN 46290. COPYEDITOR Rachel Lopez International Standard Book Number:0-672-32271-4 INDEXER Library of Congress Catalog Number:2001093573 Ginny Bess Printed in the United States of America PROOFREADER Suzanne Thomas First Printing:December 2001 TECHNICALEDITORS 05 04 03 02 4 3 2 1 Simon Mordzynski Trademarks Deon Schaffer All terms mentioned in this book that are known to be trademarks or service TEAMCOORDINATOR marks have been appropriately capitalized. Sams Publishing cannot attest to Lynne Williams the accuracy of this information. Use of a term in this book should not be MEDIADEVELOPER regarded as affecting the validity of any trademark or servicemark. Dan Scherf Warning and Disclaimer INTERIORDESIGNER Gary Adair Every effort has been made to make this book as complete and as accurate as possible,but no warranty or fitness is implied. The information provided is on COVERDESIGNER an“as is”basis. The author and the publisher shall have neither liability nor Aren Howell responsibility to any person or entity with respect to any loss or damages aris- ing from the information contained in this book or from the use of the pro- PAGELAYOUT grams accompanying it. Julie Swenson www.it-ebooks.info What’s New in This Edition? With every release of Visual Basic,Microsoft has added new functionality to enhance the applications that can be created. Visual Basic 6 took the first real step toward a client/server development tool that could create robust Windows applications. This newest release of Visual Basic,titled Visual Basic .NET,makes the jump from a mostly Windows-based application system to a truly dynamic development environment that allows you to design both Windows and Web-centric applications. The previous Sams Teach Yourself More Visual Basic in 21 Dayscovered many of the more advanced fea- tures of the Visual Basic language. You are probably wondering,“Why should I buy the new edition of this book?”The answer is simple:Microsoft has done it again. Microsoft has dramatically enhanced Web development and language portability from within Visual Basic .NET by using the .NET Framework as the starting point. In addition,every topic in this book includes additions and enhancements. You will see that many of your old friends in the Visual Basic language and development environment have changed to some degree. You will see how to incorporate these new features,func- tions,and controls into your applications. I think you will find this book both informative and useful as a reference after you start coding your applications. Have fun and good luck! —Lowell Mauer Author,Sams Teach Yourself More Visual Basic .NET in 21 Days www.it-ebooks.info Contents at a Glance Introduction 1 WEEK 1 At a Glance 5 Day 1 Writing Professional Visual Basic Applications 7 2 The Face of a Windows Application 41 3 Creating Simple Forms 77 4 Understanding the .NET Framework 99 5 Working with Objects,Collections,and Array Processing 111 6 Understanding Procedures,Functions,and Logic 137 7 Building Complex Forms 159 WEEK 1 In Review 189 WEEK 2 At a Glance 193 Day 8 Designing a Database Application 195 9 Processing Data 217 10 Accessing the Database 253 11 Enhancing the Application with Custom Objects 289 12 Working with Crystal Reports 303 13 Coping with Error Handling 331 14 Testing and Debugging the Application 355 WEEK 2 In Review 379 WEEK 3 At a Glance 381 Day 15 Programming for the Internet 383 16 Creating a Web Application 407 17 Adding Data Access to the Web 429 18 Building Online Help 443 19 Tuning and Tweaking Performance 461 www.it-ebooks.info 20 Finishing the Application 479 21 Working with Web Services 511 WEEK 3 In Review 533 Appendix 535 Appendix A Answers to Quizzes and Exercises 535 Index 553 www.it-ebooks.info Contents Introduction 1 WEEK 1 At a Glance 5 DAY 1 Writing Professional Visual Basic Applications 7 A Brief Look at What’s New in Visual Basic.NET ................................................8 Changes to the Visual Basic Language ............................................................8 The New Windows Forms ................................................................................9 The New Web Forms ......................................................................................10 Transitioning from Visual Basic 6 ..................................................................10 Taking a Brief Look at the .NET Framework ......................................................12 Understanding the Common Language Runtime ............................................13 Visual Basic and the .NET Framework ..........................................................14 What Makes a Professional Application? ............................................................14 Application Types ............................................................................................15 Picking the Right Application ........................................................................16 Project Life Cycle ............................................................................................16 Starting a Demo Project ........................................................................................25 The Project ......................................................................................................26 Environment Properties ..................................................................................30 Controls Added to the Toolbox ............................................................................30 LinkLabel ........................................................................................................31 NotifyIcon ........................................................................................................32 Error Provider ..................................................................................................32 ToolTip ............................................................................................................33 Controls that Changed ....................................................................................33 Making Controls Come Alive ..............................................................................34 Using Controls Together ................................................................................34 Summary ..............................................................................................................38 Q&A ......................................................................................................................38 Workshop ..............................................................................................................39 Quiz ................................................................................................................39 Exercise ..........................................................................................................39 DAY 2 The Face of a Windows Application 41 What the Common Dialog Is All About ..............................................................42 Why Use It? ....................................................................................................42 Interfacing with the Common Dialog Controls ..............................................43 www.it-ebooks.info viii Sams Teach Yourself More Visual Basic .NET in 21 Days The Many Faces of the Common Dialog Control ................................................45 Open and Save Dialogs ..................................................................................45 Colors ..............................................................................................................52 Accessing Fonts ..............................................................................................55 Setting Print Options ......................................................................................57 Help ................................................................................................................58 The Three Types of Applications ..........................................................................59 SDI ..................................................................................................................62 MDI ................................................................................................................63 Explorer ..........................................................................................................70 Summary ..............................................................................................................74 Q&A ......................................................................................................................75 Workshop ..............................................................................................................75 Quiz ................................................................................................................75 Exercises ..........................................................................................................76 DAY 3 Creating Simple Forms 77 Working with Toolbars ........................................................................................77 Adding a Toolbar ............................................................................................78 Other Toolbar Features ....................................................................................83 Adding Menus ......................................................................................................84 Creating an Application Menu ........................................................................84 Creating and Using Context Menus ................................................................92 Merging Menus ..............................................................................................93 Inheriting Forms ..................................................................................................94 Inheriting Forms in Code ................................................................................94 The Inheritance Picker ....................................................................................95 Summary ..............................................................................................................97 Q&A ......................................................................................................................97 Workshop ..............................................................................................................97 Quiz ................................................................................................................98 Exercise ..........................................................................................................98 DAY 4 Understanding the .NET Framework 99 What Is the .NET Framework? ..........................................................................100 Understanding the Common Language Runtime (CLR) ....................................102 Explaining the Metadata ................................................................................104 CLR Execution ..............................................................................................104 Programming in .NET ........................................................................................107 Identifying the Major Namespaces ..............................................................107 Visual Basic and the .NET Framework ........................................................108 Working with the .NET Tools ............................................................................109 Summary ............................................................................................................110 www.it-ebooks.info Contents ix Q&A ....................................................................................................................110 Workshop ............................................................................................................110 Quiz ..............................................................................................................110 Exercise ........................................................................................................110 DAY 5 Working with Objects, Collections, and Arrays 111 What Are Objects and Collections? ....................................................................112 Objects ..........................................................................................................112 Collections ....................................................................................................113 Using System Objects ..................................................................................114 Accessing Objects ..............................................................................................118 Finding the Object’s Class ............................................................................118 Creating Objects ............................................................................................119 Acting on Objects and Collections ................................................................120 Creating Your Own Class ..............................................................................124 Browsing Your Objects ..................................................................................129 Processing Loops ................................................................................................131 Counter Loops ..............................................................................................131 Conditional Loops ........................................................................................133 Summary ............................................................................................................134 Q&A ....................................................................................................................134 Workshop ............................................................................................................135 Quiz ..............................................................................................................135 Exercise ........................................................................................................135 DAY 6 Understanding Procedures, Functions, and Logic 137 Scoping Out the Variables ..................................................................................138 Defining the Variables ..................................................................................138 Where Do Variables Live? ............................................................................140 Watching Out for Problems ..........................................................................142 Passing Information ............................................................................................143 Subroutines and Functions ............................................................................144 Reference or Value ........................................................................................148 The Vulcan Way or Adding Logic to the Program ............................................150 Changing the Flow ........................................................................................150 Summary ............................................................................................................156 Q&A ....................................................................................................................156 Workshop ............................................................................................................156 Quiz ..............................................................................................................157 Exercise ........................................................................................................157 DAY 7 Building Complex Forms 159 Designing the Form ............................................................................................159 The Good,the Bad,and the Ugly ................................................................160 www.it-ebooks.info x Sams Teach Yourself More Visual Basic .NET in 21 Days What Size Is It? ............................................................................................166 Using the Form Editor Features ....................................................................167 Putting It All Together ........................................................................................169 Menus ............................................................................................................171 Toolbars ........................................................................................................173 Standard Forms ..............................................................................................175 Status Bars ....................................................................................................178 Common Dialog Controls ............................................................................179 The Tab Control ............................................................................................180 Using the Date Controls ....................................................................................181 The MonthCalendar Control ........................................................................181 The DateTimePicker Control ........................................................................185 Summary ............................................................................................................186 Q&A ....................................................................................................................186 Workshop ............................................................................................................186 Quiz ..............................................................................................................187 Exercise ........................................................................................................187 WEEK 1 In Review 189 Professional Applications and the Windows Interface ......................................189 Using Collections and Other VB Concepts ........................................................190 Designing Complex Forms ................................................................................191 WEEK 2 At a Glance 193 DAY 8 Designing a Database Application 195 What Is a Database? ..........................................................................................196 Local Databases ............................................................................................196 Remote Databases ........................................................................................197 Building the Initial Design ................................................................................198 Choosing the Tasks ........................................................................................198 Setting the Limits ..........................................................................................204 Creating the Database ........................................................................................205 Building the Tables ........................................................................................205 Defining the Indexes ......................................................................................208 Building the Application Prototype ....................................................................209 Using the Data Form Wizard ........................................................................211 Adding Forms ................................................................................................214 Summary ............................................................................................................216 Q&A ....................................................................................................................216 Workshop ............................................................................................................216 Quiz ..............................................................................................................216 Exercise ........................................................................................................216 www.it-ebooks.info Contents xi DAY 9 Processing Data 217 Designing a Database ........................................................................................218 Laying Out the Database Structure ..............................................................219 Setting Up Tables and Columns ....................................................................219 Establishing Relationships ............................................................................224 Defining Queries ..........................................................................................225 Using SQL:The Short Course ............................................................................226 Using the SELECT Statement ......................................................................227 Accessing Multiple Tables ............................................................................228 Creating Calculated Values ............................................................................229 Changing the Tables Names ..........................................................................229 Filtering the Data ..........................................................................................229 Using Table Views ........................................................................................231 Working with Stored Procedures ..................................................................233 Using Triggers ..............................................................................................238 Working with the Visual Database Tools ............................................................239 Exploring Data in the Server Explorer ..........................................................240 Creating the Database ....................................................................................241 Adding Tables and Columns ........................................................................241 Adding an Index to a Table ..........................................................................243 Adding Views ................................................................................................244 Adding Triggers and Stored Procedures ......................................................246 Displaying Data from a Table ......................................................................247 Using the Database Designer ........................................................................247 Summary ............................................................................................................250 Q&A ....................................................................................................................251 Workshop ............................................................................................................251 Quiz ..............................................................................................................251 Exercise ........................................................................................................251 DAY 10 Accessing the Database 253 Visual Basic and Data Access ............................................................................253 Data Access Objects ......................................................................................254 ADO versus ADO.NET ................................................................................254 Working with the ActiveX Data Control ............................................................255 Using the ActiveX Data Control ..................................................................257 Displaying the Data on the Form ..................................................................261 Knowing the Current Record ........................................................................262 Programmed Access with the Data Control ..................................................263 ActiveX Data Objects ........................................................................................266 Opening a Database ......................................................................................266 Accessing the Data ........................................................................................268 Introducing ADO.NET ......................................................................................273 www.it-ebooks.info

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.