Building Applications and Components with Visual Basic .NET
The .NET Framework is a development platform that was released byMicrosoft in the beginning of 2002. Using the .NET Framework is strategicbecause it allows companies to develop software that leverages Microsoft'smost recent innovations for building distributed applications. This platformalso provides features that make it easier, less costly, and more secureto deploy applications in a network environment. Visual Basic .NET is a new programming language that has beendesigned especially for the .NET Framework. Once you learn how to writeand test code with Visual Basic .NET, you will be able to take advantage ofthe .NET Framework's many new features. This, in turn, will allow you tobuild networked applications and reusable component libraries that makethe most of what Microsoft has to offer. For developers with experience using earlier versions of Visual Basic,some parts of the Visual Basic .NET language will seem very familiar. Forexample, Visual Basic .NET uses the same syntax for declaring variablesand for controlling the flow of execution using constructs such as If statementsand While loops. The fact that Visual Basic .NET feels like earlierversions of Visual Basic means that Visual Basic developers can continueto program using the same style as in the past. The similarities between versions also make it easier to port Visual Basic 6 code to Visual Basic .NET. While Visual Basic .NET is in many ways similar to earlier versions ofVisual Basic .NET, it is definitely not the same. Visual Basic .NET is far morepowerful than -;and therefore very different from-;any previous version ofVisual Basic. You should expect a significant learning curve if you are migrating from Visual Basic 6 to Visual Basic .NET, because the new language introduces many programming features that have never been part of Visual Basic. If you're migrating from an object-oriented programming language such as C++ or Java, your transition to Visual Basic .NET will likely be a bit easier, but there are still plenty of details you must learn. It is our intention to provide you with those details. Who Should Read This Book? Building Applications and Components with Visual Basic .NETis meant for developers who want to write applications and component libraries for the .NET Framework using Visual Basic .NET. This book has been written for developers who have previous experience with an earlier version of Visual Basic or VBA. It has also been written for developers who are migrating to Visual Basic .NET from C++ and Java. What Experience Do You Need? The typical reader is assumed to be an intermediate to advanced developerwho has experience with Visual Basic, C++, or Java. You should alreadyknow how to create a simple class definition that contains fields and methods.You should know why it's important to use encapsulation and how todefine certain class members as private. Finally, you should understand thedifference between a class, an object, and an object reference. It's helpful but not essential that you know the basics of computer science.It would be impossible to conduct an in-depth discussion of developingsoftware for the .NET Framework without talking about issues suchas scope, lifetime, the call stack, the heap, and threads. If you lack this kindof background, I ask you to ponder how things work at a lower level. It's also helpful but not essential that you know how the ComponentObject Model COM works. COM supplies the underlying plumbing thatallows Visual Basic 6 developers to build applications using componentDLLs. Understanding COM has made developers much more adept atusing Visual Basic 6. While the .NET Framework replaces COM with anewer, more flexible infrastructure, many of the underlying principlesremain the same. Some principles, however, have changed to make developmenteasier. You must also know about COM to understand how interoperabilityworks between Visual Basic .NET and Visual Basic 6. What Will You Learn? For the average developer who's become comfortable and productive withVisual Basic 6, making the transition to Visual Basic .NET will require anontrivial effort. You must learn an entirely new platform and becomefamiliar with a new set of development tools. You must also learn the VisualBasic .NET programming language. This endeavor poses many challenges,because Visual Basic .NET is much different and far more powerful thanany previous version of Visual Basic. Along the way, you must learn newconcepts, new keywords, and new syntax. The goal of this book is to help you make the transition to Visual Basic.NET as smoothly and quickly as possible. It first introduces the essentialarchitectural pieces of the .NET Framework. It then explores the new programmingfeatures that have been added to the latest version of VisualBasic. Here's a high-level list of topics covered in the book: The .NET Framework and the Common Language Runtime CLR Building applications and component libraries for the CLR The Framework Class Library FCL The Common Type System CTS New object-oriented programming OOP features New Visual Basic keywords and syntax required to support new OOP features Programming with delegates and events Using structured exception handling Managing memory using values and objects Naming, building, deploying, and revising assembly DLLs Interoperating with COM and Visual Basic 6 What's Not in This Book? Building Applications and Components with Visual Basic .NET does not contain many step-by-step instructions. Therefore, this book won't appeal to thosereaders who just want to know how to perform a specific task but don't carewhy. While the authors sympathize with the need for "how," the goal hereis longer-term-;to build your understanding of the "why" behind .NETand Visual Basic .NET. While this book focuses on object-oriented programming with VisualBasic .NET, it does not provide an in-depth discussion of issues relevant toobject-oriented design OOD . You will be introduced to many new OOPfeatures and the syntax required to use them. In its coverage of these topics,however, the book focuses on the syntax and the effect that the syntax hason the behavior of your code. You will need to consult different resourcesif you want to learn about advanced high-level OOD topics such as designpatterns or modeling with UML. This book also does not cover topics related to creating distributedapplications. In particular, it will not teach you how to use ASP.NET or.NET Remoting. While the book does cover details that are important todevelopers who are creating client and server applications alike, you willhave to consult additional resources to learn how to make your applicationscommunicate across the network. If you're looking for a book with a great big example application that youcan use as a starting point, Building Applications and Components with VisualBasic .NETisn't the right book for you, either. Most of the code listings areshort, between 5 and 20 lines. When a code listing is provided, the authorsalways try to use as few lines as possible to focus your attention on a particular point. In particular, the code fragments often omit extraneous thingssuch as error handling. For this reason, the book's style doesn't lend itselfto readers who are looking for designs or code to simply copy-and-pasteinto production applications. When it comes to presenting concepts, the goalhere is to teach you how to fish, as opposed to simply giving you fish. Online Support for This Book I maintain a support site for this book at [a href="http://Barracuda.net/Publications/VBNET" target="new" target=_new>http://Barracuda.net/Publications/VBNET . At this URL, you can download example code that appears thisbook. Using the downloads, you can easily run, test, and debug VisualBasic .NET code that illustrates the key points and syntax discussed in eachchapter. I also plan to use this site to pre-release new chapters that I amwriting for the next edition of this book. As a mortal, I am far from perfect. The book's support site will thereforemaintain a list of errata--that is, typos and technical inaccuracies in the book. If you find an error within this book and you'd like to tell me about it, please forward it in an e-mail message [email protected]. Acknowledgments A useful book is rarely the product of a single person. This certainly was notthe case as I worked on the manuscript for Building Applications and Componentswith Visual Basic .NETover the last two years. Many folks madeincredibly valuable contributions along the way. I would first like to thank Dr. Joe Hummel for joining me on this projectand helping me finish the book months and possibly years before Iwould have completed the work on my own. I thank Joe for his correctionsof my technical inaccuracies, for his rewriting of my damaged prose, andfor his overall contribution to helping me shape the story in this book. Ihope to work with Dr. Joe on many more projects in the future. I would like to thank Francesco Balena and Rocky Lhotka for contributingthe forewords for this book. I feel fortunate to have such goodfriends whom I consider to be living legends. The Visual Basic communityhas certainly benefited from their published works, and we all look forwardto more books from them in the future. You should also look for any opportunityto hear Francesco play the saxophone or hear Rocky tell a joke. Youwill not be disappointed. I also appreciate the candid honesty of my incredible team of energeticreviewers. My thanks go out to Greg Beamer, George Bullock, James W.Cooper, Gerard Frantz, Martin Heller, Rocky Lhotka, Jason Masterman,Fritz Onion, Ethan Roberts, Darshan Singh, Doug Turnure, Jason Whittington,Jim Wilson, Mike Woodring, and Paul Vick. I firmly believe that ahard-core critical review is a technical author's best friend. My philosophyis that if a reviewer has nothing bad to say, he shouldn't say anything at all.These guys certainly didn't let me down in this respect. Thanks again. I would like to thank all the technical people in the industry who havehelped to shape the way I think about software development and the .NETFramework. I will always be grateful to Don Box, who helped me so muchearly in my career. I would also like to say thanks to Craig Andera, BobBeauchemin, Niels Berglund, Scott Bloom, Keith Brown, Calvin Caldwell,Henk de Koning, Peter Drayton, Tim Ewald, Jon Flanders, Andrew Gayter,Justin Gehtland, Ken Getz, Ian Griffiths, Martin Gudgin, Stu Halloway,Simon Horrell, Paul Kirby, John Lam, Jose Mojica, Ted Neward, Jeff Prosise,Brian A. Randell, Brent Rector, Jeffrey Richter, Steve Rodgers, Dave Schmitt,Chris Sells, George Shepherd, Dan Sinclair, and Aaron Skonnard. There aredoubtlessly many other talented people who deserve my thanks from companiessuch as DevelopMentor, Microsoft, and QuickStart. My ability tosolicit feedback and to exchange ideas with all these people throughout thelast decade has been priceless. Last but not least, I'd like to thank the tireless staff at Addison-Wesley,who make publishing a reality. Awarm and heartfelt thanks goes out to myacquisitions editor, Stephane Thomas, for contributing so much energy andenthusiasm throughout the project and for constantly lying to her boss thatI was still on schedule. I would like to thank several other editors for theirassistance during the production phase, including Amy Fleischer, JillHobbs, and Michael Mullen. Finally, I would like to thank John Montgomery,Martin Heller, Stacey Giard, and all the other people at Microsoftwho worked so hard to put together the Microsoft .NET DevelopmentSeries with Addison-Wesley. I feel fortunate to be in such good company. -;Ted PattisonManhattan Beach, CASeptember 2003 0201734958P10062003