Programming with Microsoft® Visual Basic® .NET
iii
Contents Introduction Course Material Materialss ...................... ................................ ..................... ...................... ...................... ...................... ...................... ..................... ............ 2 Prerequisi Prerequisites............ tes....................... ...................... ...................... ..................... ..................... ...................... ...................... ...................... ................. ...... 3 Course Outline Outline ..................... ............................... ..................... ...................... ..................... ..................... ...................... ...................... ................ ..... 4 Microsoft Certified Professional Program .............. .............. .............. .............. ... 6 Faciliti Facilities................ es........................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... .................. ....... 8
Module 1: Overview of the Microsoft .NET Platform Overview.......... Overview..................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ............. 1 What Is the Microsoft .NET Platform?................. Platform?... .............. .............. ............... .............. .... 2 What Is the .NET Framework Framework?? ..................... ................................ ...................... ..................... ..................... ...................... ............. 5 What Are the .NET Framework Components?.... .............. ........................... ............. .............. ....... 9 What Are the Visual Basic Basic .NET .NET Enhancements? Enhancements? .......................... ............. ........................... .............. ..... 17 Review Review ..................... ................................ ...................... ...................... ...................... ...................... ...................... ...................... ...................... ............. .. 19
Module 2: Development Environment Features Overview.......... Overview..................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ............. 1 Describing the Integrated Development Development Environment............. .............. .............. ............. . 2 Creating Creating Visual Basic .NET Projects.................. Projects............................. ...................... ...................... ...................... ................ ..... 3 Demonstration: Creating a Visual Visual Basic Basic .NET Project .............. .............. .......... 16 Using Development Environment Features .............. .......................... ............. ........................... .............. . 17 Demonstration: Using the Visual Studio .NET IDE .............. .......................... ............. ............... .. 29 Debugging Debugging Applicati Applications ons ...................... ................................. ...................... ...................... ...................... ...................... .................. ....... 30 Demonstration: Debugging a Project................. Project.... ........................... .............. .......................... ............. ..................... ........ 37 Compilin Compiling g in Visual Visual Basic .NET ..................... ................................ ...................... ...................... ...................... ................. ...... 38 Lab 2.1: Exploring the Development Environment .......................... ............. ........................... .............. ... 41 Review Review ..................... ................................ ...................... ...................... ...................... ...................... ...................... ...................... ...................... ............. .. 46
Module 3: Language and Syntax Enhancements Enhancements Overview.......... Overview..................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ............. 1 Data Types Types ...................... ................................. ...................... ...................... ...................... ...................... ...................... ...................... ................... ........ 2 Using Variables... Variables.............. ...................... ...................... ...................... ..................... ..................... ...................... ...................... ..................... .......... 9 Demonstration: Using Variables and Data Structures ........................... ............. .............. ............ 20 Functions, Subroutines, and Properties....... ........................... ............. .............. .............. .............. ............. . 21 Lab 3.1: Working with Variables and Procedures .............. .............. .............. ... 29 Exception Exception Handling Handling ..................... ................................ ...................... ...................... ...................... ...................... ...................... ............... .... 36 Demonstration: Structured Exception Handling .......................... ............. ........................... .............. ........ 48 Lab 3.2: Implementing Implementing Structured Exception Handling .......................... ............ .............. .......... 49 Review Review ..................... ................................ ...................... ...................... ...................... ...................... ...................... ...................... ...................... ............. .. 52
Module 4: Object-Oriented Design for Visual Basic .NET Overview.......... Overview..................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ............. 1 Designing Designing Classes Classes ..................... ................................ ...................... ...................... ..................... ..................... ...................... ..................... .......... 2 Practice: Deriving Classes from Use Cases .......................... ............ .............. .............. .............. . 10 Object-Oriented Programming Concepts........ .............. ........................... ............. .............. .......... 11 Advanced Object-Oriented Object-Oriented Programming Concepts........... .............. .............. ... 20 Using Microsoft Microsoft Visio........... Visio..................... ..................... ...................... ...................... ..................... ..................... ...................... ............. .. 25 Lab 4.1: Creating Creating Class Diagrams from Use Cases .............. .............. .............. . 33 Review Review ..................... ................................ ...................... ...................... ...................... ...................... ...................... ...................... ...................... ............. .. 42
Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, copyrights, or other intellectual property rights rights covering subject matter matter in this document. document. Except Except as expressly expressly provided provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. © 2002 Microsoft Corporation. All rights reserved. Microsoft, MS-DOS, Windows, Windows NT, ActiveX, BizTalk, FrontPage, IntelliSense, JScript, Microsoft Press, Outlook, PowerPoint, Visio, Visual Basic, Visual C++, Visual C#, Visual InterDev, Visual J#, Visual SourceSafe, Visual Studio, and Windows Windows Media ar e either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners.
Course Number: 2373B Part Number: X08-75365 Released: 02/2002
iv
Programming with Microsoft® Visual Basic® .NET
Module 5: Object-Oriented Programming in Visual Basic .NET Overview........... Overview...................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ........... 1 Defining Defining Classes Classes ..................... ................................ ...................... ...................... ...................... ..................... ..................... ...................... ............. 2 Creating Creating and Destroyin Destroying g Objects Objects .................... ............................... ...................... ...................... ...................... .................. ....... 16 Demonstra Demonstration: tion: Creating Creating Classes Classes ..................... ................................ ...................... ...................... ...................... ................. ...... 26 Lab 5.1: Creating the Customer Class.............. .............. .......................... ............. ....................... .......... 27 Inheritan Inheritance........ ce................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ..................... .......... 34 Demonstration: Inheritance.......... .......................... ............. ........................... .............. ........................... ............. .............. ... 46 Interface Interfaces.................. s............................. ...................... ..................... ..................... ...................... ...................... ...................... ...................... .............. ... 47 Demonstration: Interfaces and Polymorphism..... ............... ............... ............... . 53 Working Working with Classes Classes ..................... ................................ ...................... ...................... ...................... ...................... ...................... ............. 54 Lab 5.2: Inheriting the Package Class.................... Class...... .............. .............. .............. ............... . 68 Review Review ...................... ................................. ....................... ....................... ...................... ...................... ...................... ...................... ...................... ........... 78
Module 6: Using Windows Forms Overview........... Overview...................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ...................... ........... 1 Why Use Windows Windows Forms? Forms? .................... ............................... ...................... ..................... ..................... ...................... .................. ....... 2 Structure Structure