moving to vb.net: strategies, concepts, and code978-1-4302-1149-5/1.pdf · moving to vb.net:...
TRANSCRIPT
Moving to VB.NET: Strategies, Concepts, and Code Copyright ©2001 by Dan Appleman Originally published by Apress in 2001 AII rights reserved. No part ofthis work may be reproduced or transmitted in any form or by any means, electronic or mecbanical, including photocopying, recording. or by any information storage or retrieval system, without the prior written perrnission of the copyright owner and the publisher.
ISBN 978-1-893115-97-2 ISBN 978-1-4302-1149-5 (eBook) DOI 10.1007/978-1-4302-1149-5
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 ofthe trademark.
Editorial Directors: Dan Appleman, Gary Cornell, Karen Watterson
Assistant Editorial Director: Jason Gilmore
Managing Editor: Grace Wong
Technical Reviewer: Scott Stabbert
Editor: Kiersten Burke
Production Editor: Kari Brooks
Page Composition: Susan Glinert
Artist and Cover Designer: Karl Miyajima
Indexer: Julie Kawabata
The information in this book is distributed onan "as is" hasis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author 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.
Contents at a Glance
Introduction ....................................................................................................... xiii
An Important Note Regarding Code in This Book ................................ xix
Acknowledgments .................................................................................................... xxi
Part I
Chapter 1
Chapter 2
Chapter 3
Part II
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Strategies ................................................................................. 1
Where Should You Begin? ......................................................... 3
Facing VB.NET without Fear or Panic ............................... 9
Adoption Strategies ................................................................ 15
Concepts ...................................................................................... 23
.NET in Context ......................................................................... 25
Inheritance .................................................................................. 57
Memory Management in VB. NET ............................................. 103
VB.NET Multithreading .......................................................... 123
Part III Code ............................................................................................... 1B1
Chapter 8 Data Types and Operators ................................................... 183
Chapter 9 Language Syntax ....................................................................... 209
Chapter 10 Objects In-Depth ..................................................................... 257
Chapter 11 Reflection and Attributes ................................................. 315
Interlude .................................................................................................... 339
iii
Contents ata Glance
Part IV The Wonderful World of .NET.. ............................. 341
Chapter 12 .NET Namespaces-The Grand Tour ...................................... 343
Chapter 13 Windows Applications ............................................................ 397
Chapter 14 Internet Applications and Services ............................ .421
Chapter 15 COM Interop and Accessing the Win32 API ................. .453
Chapter 16 Living with .NET ..................................................................... 505
Conclusion ............................................................................................................ 539
Index ...................................................................................................................... 541
iv
Contents
Introduction .................................................................................................... xiii
WhoAre You? ..................................................................................................... xiv Regarding Microsoft .......................................................................................... xiv Regarding Prereleases ........................................................................................ xv Regarding Source Code ..................................................................................... xvi Regarding Desaware ........................................................................................ xvii
An Important Note Regarding Code in This Book ................ xix
Acknowledgments ............................................................................................. xxi
Part I Strategies ....................................................................... 1
Chapter 1 Where Should You Begin? .............................................. 3
The Importance of Context (Keeping Things in Perspective) .......... 4 .NET-Is It Real ar Is It Marketing? .......................................................... 6
Chapter 2 Facing VB.NET without Fear or Panic ............... 9
Oh My Gad, They Broke VBI ................................................................................ 9 Everything You Know Is Now Obsolete ........................................................ 11 The Business of Software Development ...................................................... 13
V
Contents
Chapter 3 Adoption Strategies ...................................................... 15
Time Frames ............................................................................................................. 15 Porting Code .......................................................................................................... 16 Deployment Considerations .............................................................................. 17
NewServer-BasedApplications ........................................................................ 18 Old Server-BasedApplications ......................................................................... 18 ClientApplications ............................................................................................. 19
What about C#? ...................................................................................................... 20 What about Alternatives to .NET from Sources
Other than Microsoft? ................................................................................ 21 Moving On ................................................................................................................. 22
Part II Concepts ............................................................................ 23
Chapter 4 . NET in Context ................................................................. 25
The Virtual Machi ne ........................................................................................... 26 COM Is Dead. Long Live COM? .................................................•........................ 28
COM-Ideas versus Implementation ............................................................... 28 COM+ .................................................................................................................. 34 COM+2.0 ............................................................................................................ 34
The Common Language Runtime .......................................................................... 35 Manifests ............................................................................................................. 36 Intermediate Language (IL) ............................................................................... 38 Goodbye Circular References ............................................................................ 40 Cade at Last ........................................................................................................ 46 The Cade Controversy ....................................................................................... 52
Recap: Why .NET? .................................................................................................. 54
Chapter 5 Inheritance ........................................................................... 57
The Mantra of Code Reuse ................................................................................ 57 A VB6 llnked llst ................................................................................................ 58 A Containment-Based Ilnked llst Using VB.NET ........................................... 66 An Inheritance-Based Ilnked llst Using VB.NET ........................................... 75 A Dual Ilnked llst Example ............................................................................... 77 Dealing with Naming Conflicts ......................................................................... 86
Inheritance in .NET ........................................................................................... 88 Everything Is an Object ...................................................................................... 88 A Look at Forms .................................................................................................. 90
vi
Contents
A Closer Look at Inheritance in VB.NET .................................................. 94 Solving the Fragile Base Oass Problem ............................................................ 98 Method Visibility .............................................................................................. 101
Recap ........................................................................................................................ 102
Chapter 6 Memory Management in VB.NET ................................ 103
Value Objects and Reference Objects ...................................................... 103 Value Objects .................................................................................................... 104 Reference Objects ............................................................................................. 108
Revisiting Garbage Collection .................................................................... 109 Finalizers ........................................................................................................... 112 The Great Non-Deterministic Finalizer Controversy .................................... 113
Off the Deep End-Resurrection Exists .................................................... 117 Recap ........................................................................................................................ 120
Chapter 7 VB.NET Multithreading ................................................ 123
A Quick Introduction to Multithreading ................................................ 124 The Shopping Fiasco ........................................................................................ 125 Multithreading: A Ooser Look ........................................................................ 126 Design: Your First Une of Defense .................................................................. 145 Multithreaded Design: Your Next Best Hope ................................................. 148
The Benefits of Multithreading ................................................................. 166 Efficient Wait States .......................................................................................... 167 Background Operations ................................................................................... 168 Efficient Client Access ...................................................................................... 168 Evaluating Multithreaded Performance ......................................................... 170
Recap ........................................................................................................................ 179
Part III Code ....................................................................................... 181
Chapter 8 Data Types and Operators ........................................ 183
The Numeric Types .............................................................................................. 183 String * 1 versus Char ....................................................................................... 184 Boolean .............................................................................................................. 184 Currency and Decimal ..................................................................................... 186 lntegers, Longs, and Shorts .............................................................................. 187 UnsignedTypes ................................................................................................ 187 AbouttheCLR ................................................................................................... 188
vii
Contents
Non-Numeric Data Types ................................................................................... 188 Goodbye Variants (and Good Riddance) ........................................................ 189 Strings ................................................................................................................ 192 Arrays ................................................................................................................. 193 Dates .................................................................................................................. 195
Enurns ............................................................................................................... 196
Declarations ........................................................................................................ 198
Conversions and Type Checking ................................................................... 198 Conversions and Classes ................................................................................. 201
Conversions and Structures ............................................................................ 203
Operators ............................................................................................................... 203 The AndAlso and OrElse Opera tors ................................................................ 203
String Opera tors ............................................................................................... 205
Concatenation Operators ................................................................................ 206
Eqv and Imp ...................................................................................................... 207
Recap ........................................................................................................................ 207
Chapter 9 Language Syntax ............................................................... 209
Function Calls and Parameters ................................................................... 209 Rational Calling Mechanism .......................................................................... 209
ReturningValues .............................................................................................. 210 ByValisNowDefault ....................................................................................... 211 The ByVal Calling Convention-It's Not What You Think. ........................... 211
Scoping Rules ...................................................................................................... 224 Static Variables ................................................................................................. 228
Error Handling .................................................................................................... 230 The Old Way ...................................................................................................... 230 Structured Exception Handling ...................................................................... 233
Other Language Changes ................................................................................... 243 Control Flow Changes ...................................................................................... 243
Elimination of Differentiated String Functions ............................................. 244
Other Minor Changes ...................................................................................... 245
Commands That Have Vanished ........................................................................ 245 Vanishing Graphics Comrnands ..................................................................... 245 VanishingVariant Commands ........................................................................ 246
Vanishing Math Comrnands ............................................................................ 246 Other Commands That Have Vanished .......................................................... 248
The Microsoft. VisualBasic and Compatibility Namespaces ............. 248 We're Offto See the WIZard ............................................................................. 250 The Compatibility Choice ................................................................................ 251 Strings and Compatibility ................................................................................ 253
File IlO and Compatibility .............................................................................. 254
Recap ........................................................................................................................ 255
viii
Contents
Chapter 1.0 Objects In-Depth ............................................................ 257
The Parts of a o NET Application ............................................................... 257 Application Domains ....................................................................................... 257 Assemblies ......................................................................................................... 261
Scoping in VB o NET .............................................................................................. 262 Namespaces ...................................................................................................... 263 Scoping 1: The Namespace Level. ................................................................... 269 Scoping 2: The Qass Level ............................................................................... 272
More about Classes ............................................................................................ 273 SharedMembers ............................................................................................... 274 MyBase and MyQass ........................................................................................ 275 Nested Classes .................................................................................................. 278
Methods and Properties ................................................................................... 278 Function Overloading ...................................................................................... 278 Constructors ..................................................................................................... 281 Methods versus Properties .............................................................................. 286 Property Procedures ......................................................................................... 288
Events and Delegates ....................................................................................... 295 Events, Callbacks, and COM ............................................................................ 296 Delegates ........................................................................................................... 298 Events (atLast) .................................................................................................. 305
Recap ........................................................................................................................ 314
Chapter 1.1. Reflection and Attributes ..................................... 315
On Compilers and Interpreters .................................................................... 315 One Compiler, Two Compiler ......................................................................... 317 Compile Time versus Runtime ........................................................................ 318 Attributes ........................................................................................................... 319
Reflection ............................................................................................................. 320 Exploring the Manifest ..................................................................................... 320 CustomAttributes ............................................................................................ 324
Binding .................................................................................................................... 329 Early Binding and Dll Hell ............................................................................. 330 Late Binding ...................................................................................................... 331 Late Binding---The Right Way ......................................................................... 333
Dynamic Loading .................................................................................................. 336 Recap ........................................................................................................................ 337
Interlude ............................................................................................................ 339
ix
Contents
Part IV The Wonderful World of . NET .............. 341
Chapter 12 .NET Namespaces-The Grand Tour ........................ 343
The Most Important Things to Keep in Mind When Dealing with the .NET Namespaces ........................................... 343 lt's All about the Frameworks ......................................................................... 343 .NET ls Designed for Visual Basic.NET Programmers .................................. 344
Let the Tour Begin ........................................................................................... 346 Reading the Map .............................................................................................. 347
If It,s Tuesday, It Must Be System ........................................................ 352 Truly Base Qasses ............................................................................................ 352 Core Language Support Classes ...................................................................... 353 Date and Time Qasses ..................................................................................... 355 General-Purpose System Classes .................................................................... 356 Exceptions ......................................................................................................... 359 Attributes .......................................................................................................... 360 Interfaces .......................................................................................................... 361 Other Cool System Oasses .............................................................................. 363
Collections ........................................................................................................... 364 SystemCollectionBase and Custom Collections ........................................... 365
lnside Collections ............................................................................................. 368
Other Collections ............................................................................................. 369 Drawing ................................................................................................................... 371
IfYouAreAccustomed to Usingthe VB6 Graphic Methods .......................... 372 IfYouAreAccustomed to UsingWm32API
Calls for Graphic Operations ................................................................... 372 Goodbye GDI, Hello GDI+ ............................................................................... 373 Bitmaps ............................................................................................................. 375 Strategies for Approaching GDI+ .................................................................... 377
Print ing ................................................................................................................. 378 IlO ..................................................................................................................... 383 Other SystemiO Oasses .................................................................................. 387
Serialization and Data Management .......................................................... 388 Serialization ...................................................................................................... 388 ADO.NET and Xl.\1L .......................................................................................... 392
Recap ........................................................................................................................ 396
Chapter 13 Windows Applications .................................................. 397
A Whole New Forms Package ............................................................................ 398 Recreatable Wmdows ...................................................................................... 398
Graphical Controls ........................................................................................... 399 Consistent Hosts ........ ...... .................... ... ... .............. ... ...... ........ .................. ..... 400
X
Contents
Patterns and System.Windows.Forms ........................................................... 400 System.ComponentModel.Component ......................................................... 402 System.Wmdows.Forms.Control .................................................................... 402 System Wmdows.Forms.ScrollableControl. ................................................... 405 Containers, Forms, and UserControls ............................................................ 407
Navigating the System. Windows. Forms Namespace ................................. 407 Exploring Further .............................................................................................. 410
AutoRedraw-Plus, Events versus Overrides ................................................. 410 ~1 Forms, Parenting, and Ownership ......................................................... 414 Subclassing and theApplication Object.. ....................................................... 416 Forms and Threads ........................................................................................... 417
Recap ........................................................................................................................ 420
Chapter 14 Internet Applications and Services .............. 421
What Is Microsojt.NET? ................................................................................... 421 Programming the Internet .............................................................................. 422
XML .................................................................................................................... 423 Distributed Applications .................................................................................. 426
The • NET Way of Designing Applications ................................................ 427 The Database Tier ............................................................................................. 427 A Traditional Wmdows Application ................................................................ 431 A WebApplication-BasedSolution ................................................................. 433 A WebService-Based Solution ......................................................................... 441 Thinking Distributed ........................................................................................ 443
A Quick Aside with Winsock .......................................................................... 445 A Guest Commentary ............................................................................................ 450 Recap ........................................................................................................................ 452
Chapter 15 COM Interop and Accessing the Win32 API .......................................... 453
COM Interop ........................................................................................................... 454 Calling COM Objects from .NET .................................................................... 456
Error Handling .................................................................................................. 458 Object Release ................................................................................................... 458 Versioning ......................................................................................................... 458
Late Binding ...................................................................................................... 459 Marshaling Structures and Other Parameter Types ...................................... 459 Further Thoughts .............................................................................................. 459
Accessing .NET Objects from COM ............................................................... 460 Creating the Called.ViaCOM Component-First Attempt.. ........................... 463 Creating the Called.ViaCOM Component-secondAttempt.. ...................... 470
xi
Contents
Accessing the Win32 API ................................................................................ 473 The Declare Statement Evolved ...................................................................... 474
The Tirree Most Important Things to Remember When Making API Calls from VB.NET ..................................................... 478
Platforminvocation ......................................................................................... 478
Solving the Marshaling Puzzle ... ... ................... .... ................... ............... .. . ...... 481 Structures .......................................................................................................... 491
Advanced Wm32 API Calls ............................................................................... 494
Recap ........................................................................................................................ 503
Chapter 16 Living with .NET ............................................................ 505
Versioning and .NET ......................................................................................... 505 Nightmare Scenarios ........................................................................................ 506
Paranoid Scenarios .......................................................................................... 508
.NET and Versioning ........................................................................................ 508
Strong Names ................................................................................................... 51 O
Versioning the .NET Runtime ......................................................................... 515
Strong Names and Spoofing ............................................................................ 515
Namespace Confl.icts ....................................................................................... 517
.NET and Side-by-Side Execution ................................................................... 517
Security ................................................................................................................. 518 Goodbye Crashes, Goodbye Vrruses? ............................................................. 518
Assemblies and Security Policies .................................................................... 521 Security Examples ............................................................................................ 524
Security Techniques ......................................................................................... 533
Bits and Pieces .................................................................................................. 533 The Disassembly Dilemma .............................................................................. 534
Deployment ...................................................................................................... 537
Recap ........................................................................................................................ 537
Conclusion ......................................................................................................... 539
Index ...................................................................................................................... 541
xii
Introduction
You'vE PROBABLY BEEN HEARING ABOUT Microsoft's .NET Framework and the new features ofVisual Basic.NET. Perhaps you've read articles about it in magazines. Perhaps you've read promotional material from Microsoft. Perhaps you've even played with one ofthe beta versions.
Regardless of howyou've learned about it, you're probably feeling a bit overwhelmed. It's such a massive change both in language and approach that it's difficult to sort out the reality from the marketing and difficult to decide where o ne should actually start when approaching this new technology.
That's what this book is about.
• It's about the priorities you should use in learning .NET and the strategies you should use in deciding how and when to deploy .NET.
• It's about the concepts you need to know in order to understand the new features ofVisual Basic.NET and how they will influence the way you write code under this new framework.
• And it's about the changes in the Visual Basic language itself.
Even though this is o ne of the earliest books on .NET, it is not intended to be a general survey of the framework or even a comprehensive reference to Vis ual Basic.NET -I'm sure there will be plenty of those books available later. Nor will you tind here a rehash ofthe .NET documentation. The .NET Framework is so large and the changes to Visual Basic.NET so widespread that a comprehensive book would be huge and probably overwhelming (assurning it is even possible to fit one into a single volume). Entire subjects such as the development environment, debugging, and high-level services are deserving ofbooks oftheir own and will be covered here barely or not at ali.
This book is intended tobe o ne of the first books you read on .NET -the o ne that will prepare you to understand the more comprehensive books, Microsoft's documentation, and the inevitable manual rehashes. It is intended to help you to think about this new technology in the context of your own development plans, and to get you up to speed quickly on concepts that will be new to most Visual Basic programmers. It is intended to be concise and easy read yet provide enough depth to make you an expert on the VB.NET language and to lay the foundation for you to become an expert in those areas of the .NET Framework that most interest you.
xiii
Introduction
xiv
Who Are You?
1 am assuming that you are an intermediate to advanced-level Visual Basic programmer. This book is emphatically notintended for people who are new to programming in general, though it should prove useful to non-Visual Basic programrners who are coming to VB.NEf from other languages. It will also be valuable to teamleaders and managers who are making deployment decisions-they'll find that Part One--Strategies directly addresses management and technology issues.
Unlike many similar books, this one is focused entirely on helping current VB6 programmers come up to speed on .NET in general and VB.NEf in particular. Hence, the organization is quite unusual. 1 waste no time explaining basic concepts such as "What is a class?" or "How does a For ... Next loop work?" or "What is a collection?" Believe me, there is plenty to teach without rehashing the things that every VB6 programmer beyond the beginner level knows.
Regarding Microsoft
The world seerns to have recently divided itself into two camps: those who love and support Microsoft and those who hate and despise them Personally, I fall into that somewhat unworldly group who refuses to see Microsoft as a major deity.1 As a result, I sometimes find myself condemned by the non-Microsoft world as a "Microsoft supporter" and condemned by the Microsoft world as someone who "hates Microsoft."
The truth is that I have a lot of respect for Microsoft. 2 They have a great deal of good technology; quite a bit of great technology; and a depressing amount ofbloated technology. They also have a very effective marketing department whose actions 1 often find incomprehensible. I know enough about them to know that they are a chaotic organization-and their decisions are sometimes intluenced as much by intemal politics as technological sophistication (which is true of any company but somehow people think saying this of Microsoft is an insult).
So, I like them I also like to make fun of them-partly because they make a great target but partly because it's a natural and human reaction in dealing with an overwhelming force.3
For the record, I don't hate them 1 like them However, that doesn't mean that I blindly agree with them or believe that they
make the right choices on technology. I certainly don't believe everything they write about "the best way for you to write software" and neither should you. Why?
1. A minor deity perhaps. My point is that Microsoft has joined the ranks of keyboards, programmer's editors, and operating systems as a "religious" issue-one on which I am a confirmed atheist.
2. Some of my best friends work at Microsoft-it's a cliche but true.
3. And if you don't think they're an overwhelming force, just think for a moment about the impact .NET is going to have on your own career.
Because you know as well as 1 do that the best wayforyou to write software changes quickly--Qften in ways that Microsoft itself doesn't anticipate.
In this book, 1 will be sharing my opinions on the .NET Framework and the changes that have been rnade to the Visual Basic language. Some ofthose opinions will differ from what Microsoft says. Some will be controversial. Some will probably turn out tobe wrong. But that's okay. My goal is not that you take everything 1 say as gospel, but that you think about the new technology in the context ofyour own situation-that you evaluate and judge it for yourself. 1 hope my perspective will broaden thewayyoulook at Visual Basic.NEf and ultirnately help you in the process of adopting the technology to suit your own needs.
Regarding Prereleases
Ifyou've followed my prior books and articles, you probably know that there are two types ofbooks 1 bate: manual rehashes and books that are rushed and inaccurate because they're based on prerelease cade.
So here 1 am writing a book based on prerelease cade, which leads to three possibilities:
1. 1 have become a complete hypocrite.
2. I've sold out for the money because an early book sells well even if it's crap.
3. 1 have some good reason for doing this book that isn't obvious but you're at least willing to hear my side of the story.
1 knowwhat you're thinking. The answer is three, right? Of course. But it's also two4-except that 1 sincerely hope and believe that this
book isn't crap. Even though the .NET Framework is not yet released, the overall architecture
and approach of the framework is set, as are the vast rnajority of the namespaces. The Visual Basic.NET language definition is final and seems to work as specified in the documentation. Its architecture is also well defined. According to Microsoft there should be few language changes from Beta 2 until final release.
You don't need to wait until the final release to start learning about them and they are well enough defined at this point for me to write about them.
More important, 1 am very concerned that people will approach these technologies the wrong way ...
• That they'll condemn the language changes to VB.NET unfairly just because they break compatibility with existing cade.
4. Sometimes it's painful to be honest.
lntroduction
XV
Introduction
xvi
• That they'll condemn the Common Language Rtmtime just because it's a huge runtime and VB.NET no longer has native code support.
• That they'll cheerfully start using inheritance and multithreading in ways that will get them into trouble-with code that is unscalable, tmsupportable, or hard to debug.
With this technology, more than any in recent memory, it is critical that you start outright---thatyou tmderstand why Microsoftmadethe choices theydidand whythey are mostlygood choices. You need to understand that inheritance is somethingyou use only after agreat deal of thought-almost as a last resort You need to realize that consequences of a design mistake in a free-threaded environment can be incredibly expensive due to the difficulty of detecting obscure synchronization bugs.
That's the main reason that 1 wanted to get this book out early-because 1 want to help VB programmers get started off correctly. And 1 guess I'm confident enough in my own ability to think that what 1 have to saywill help.
Regarding Source Code
There are quite a few sample programs included with this book. You can download them from the publisher's Web site at http: 1 lwww. apress. corn. The source code is organized by chapter so if you see a reference to a project named 1\volnterfaces in Chapter 5, look under the Source\CHS\ Twolnterfaces directory.
My assumption is that you will use the source code provided from the Web site and not attempt to type in the code printed in the book. There are two reasons for this. First, in many cases, 1 have not included ali of the code needed to run the project-just enough to explain the concept under discussion. That wayyou don't have to wade through endless printed listings. Second, this edition of the book is based on prerelease code and 1 expect that some of the code will break as Microsoft makes changes. I'll update the code as often as 1 canto include these changes. Also, check out the book's Web site at http: 1 lwww. desaware. corn for lists of updates and corrections.
The code printed in the book was tested as a pre-Beta 2 build made available to authors. The code available on the Web site will be Beta 2 code (depending on what Microsoft ends up calling the forthcoming beta) and will include a revision sheet that lists any last minute changes from the printed book to final Beta 2 code (this approach is necessary given the time it takes to actually produce and print a book). The code on the Web site will be updated tobe compatible with future public betas and the final release as soon as possible.
Regarding Desaware
1 always mention Desaware in my books. 1 do so because 1 am first and foremost a software developer. 1 write real code that ships and is currently running on untold thousands of systems. 1 helped cofound Apress in order to find a good home for my books (and ifyou are a software developer who is interested in writing, you'll find no better home----send me an email ifyou're interested).
But Desaware is the home for my software-primarily component software designed to help Visual Basic (and now Visual Studio) developers. At this time, 1 don't knowwhat kinds of products we'll have for VB.NEf -but you can bet we'll have some, so 1 invite you to visit http: 1 lwww. desaware. corn and see whatwe're up to. More important, you'll also find the updates and corrections page for this book on that site-and given the early publication, I'm sure there will be updates as the .NET Framework progresses and is ultimately released.
With that, 1 invite you join me in this introduction to Visual Basic.NET and the .NET Framework.
Dan Appleman May2001 [email protected]
Introduction
xvii
Another Important Note Regarding Code in This Book
All of the cade examples shown in this book have Opti an Strict set to on using the Project Properties dialog box (Build tab).
1 strongly recommend that you always turn Option Strict on for all ofyour VB.NEI' projects.
1 feel so strongly about this that the only place in this book where 1 will even acknowledge the possibility of turning this option off is in Chapter 8, where 1 will do my best to showyou that not only should turning it on be the first thing you do in any program, but also that Microsoft's decisi an to leave it off by default should possibly be counted as their single greatest mistake with regards to VB.NET.
XX
An Important Note Regarding Code in This Book
THE EDmON OF THE BOOK you are bolding is a Beta 2-compliant book. There have been dramatic breaking cbanges between Beta 1 and Beta 2 ofVisual Studio. NET.
Updates and corrections to both the source code and contents of this book will be available on the Web for both fu ture beta releases and for the final release of Vis ual Studio. So, you can be confident that this book will not become obsolete as the release date gets closer.
All code listings in this bookbave been verified against the latest software build available to authors. Every effort bas been roade to make it accurate to the final Beta 2 gold release.
NJTE Thecodedownloadisavatlableonlineathttp:l/www.apress.comandis for purchasers o{this book only. Readers Will rl88d to have this book in hand in order to successfully answer questions that wlll prcwide QCCI!SS to thecods.
The source code available for download bas been tested under the final Beta 2 release. Therefore you sbould not attempt to test code by typing it in from listings in the book but should download the source code from http: 1 lwww. apress. corn.
Be sure to check the Web site at http: 1 lwww. apress. corn or http: 1 lwww. desaware. corn
for the latest updates and corrections. Sample code for this book has been verified only under Wmdows 2000.
Updates and corrections will be provided on the Web site for other operating systems before release of the final product. At the time of publication, Microsoft recommends doing all.NET development on Wmdows 2000.
xix
Acknowledgments
1 HAVE so MANYPEOPLE to thank for their help with this book that it's hard to know where to begin. The entire teamatApress has beenfantastic. Grace Wong continues to work miracles as rnanaging editor and put together a fantastic team for this boole Karl Brooks managed to stay ftexible as the schedule kept changing. Kiersten Burke was exactly the kind of copyeditor 1 like-one with a light touch, yet irnposing discipline and consistency so 1 don't have to. Thanks to Carol Burbo who helped on formatting (great to work with you again). Also thanks to Susan Glinert, Iulie Kawabata, and Karl Miyajima for their contributions in cornposition, indexing, and art respectively. Also kudos to Stephanie Rodriguez for going above and beyond in helping with the early and ongoing prornotion for the book; to Mason Smith and the rest of the Springer team on the sales side; and to Cherryl Schwinges on the scheduling and administrative side. Thanks to Karen Watterson, who sornehow found tirne in her irnpossible schedule to look over rnany of the chapters and offer sage advice. To Iason Gilrnore, who I'rn glad to have on the team even though he had nothing to do with this particular book. And, of course, to Gary Comell-the guy who really rnakes Apress work.
1 can't even begin to express rny gratitude to Scott Stabbert~ne of the finest technical editors I've ever had the pleasure of working with. Aside frorn the obvious help in keeping the book accurate ( especially considering the rnany changes that took place to VB.NET while the book was being written), he showed infinite patience on those occasions when 1 found it necessary to criticize Microsoft -more than 1 would normally expect from a Nlicrosoft employee. And he provided additional insights into the rninds and rnotivations of the developers. Thanks, Scott-1 hope we can work together on sornething again soon Also thanks to sorne others at Microsoft including EricAndre, Drew Fletcher, Dave Mendlen, Ari Bixhom, and Mike lern, for reasons they know and 1 probably can't tell you without getting into trouble.
Thanks to Chris MacAskill, Maggie Cannon, andiudy Kirkpatrickat MightyWords. Their help in getting rny Ebook cornparing VB.NET and C# published also helped get the word out on this book.
As always, this book could not possibly have been published without the strong support of rny family at Desaware. Karyn Duncan, Stjepan Pejic, Marian Kicklighter, Franky Wong, and the rest of the gang: Ariel, Gil, lgor, Oded, and Luk~anks to youall.
And, of course, to rny family outside ofDesaware-to the guys in Dr. SeussAZA who didn't gripe when rny presence at their events consisted of rne sitting in a comer writing on rny laptop. And to Roan, Maya, and Kendra for helping rne carne up for air occasionally. Finally, thanks Morn, for forcing rne to eat now and then; and Dad for everything-plus reviewing every chapter before it was subrnitted.
xxi