Microsoft visual basic 2005 step by step (2006)

829 168 1
Microsoft visual basic 2005 step by step (2006)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2006 by Michael Halvorson All rights reserved No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher Library of Congress Control Number 2005933122 Printed and bound in the United States of America QWT Distributed in Canada by H.B Fenn and Company Ltd A CIP catalogue record for this book is available from the British Library Microsoft Press books are available through booksellers and distributors worldwide For further information about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329 Visit our Web site at www.microsoft.com/learning/books/ Send comments to mspinput@microsoft.com Microsoft, Microsoft, ActiveX, DataTips, Excel, FrontPage, IntelliSense, Microsoft Press, MSDN, MS-DOS, Outlook, PowerPoint, Visual Basic, Visual C#, Visual C++, Visual InterDev, Visual J#, Visual J++, Visual Studio, Visual Web Developer, Windows, Windows NT, and Windows Server are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries Other product and company names mentioned herein may be the trademarks of their respective owners The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred This book expresses the author's views and opinions The information contained in this book is provided without any express, statutory, or implied warranties Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book Acquisitions Editor: Ben Ryan Project Editor: Melissa von Tschudi-Sutton Production: Online Training Solutions, Inc Body Part No X11-44966 Companion Content This title includes references to electronic content, such as sample files, sample code, beta software, tools, and other content This content is provided as an additional learning tool to accompany the text Although the references to this content might mention a CD or CD-ROM where these files are available, you can access selected portions of this content online by going to http://www.microsoft.com/mspress/products/mell To view the companion content for a title at this Web site, type in the product ISBN (International Standard Book Number) of the title in the text box and click Go The ISBN for this title is listed below and can also be found on the LOC (Library of Congress) page listed in the Table of Contents ISBN: 0-7356-2131-4 Introduction Welcome to Microsoft Visual Basic 2005 Step by Step, a comprehensive introduction to Visual Basic programming using the Microsoft Visual Basic 2005 software I've designed this practical, hands-on tutorial with a variety of skill levels in mind The result is that new programmers can learn software development fundamentals in the context of useful, real-world applications, and experienced Visual Basic programmers can quickly master the essential tools and programming techniques offered in the Visual Basic 2005 upgrade Complementing this comprehensive approach is the book's structure—4 topically organized parts, 20 chapters, and 54 step-by-step exercises and sample programs By using this book, you'll quickly learn how to create professional-quality Visual Basic 2005 applications for the Microsoft Windows operating system and a variety of Web browsers You'll also have fun! What is Visual Basic 2005? Visual Basic 2005 is a development tool that you can use to build applications that perform useful work and look great within a variety of settings Using Visual Basic 2005, you can create applications for the Windows operating system, the Web, hand-held devices, and a host of other environments and settings The most important advantage of Visual Basic is that it has been designed to increase productivity in your daily development work—especially if you need to use information in databases or create solutions for the Internet—but an important additional benefit is that once you become comfortable with the development environment in Microsoft Visual Studio 2005, you can use the same tools to write programs for Microsoft Visual C++ 2005, Microsoft Visual C# 2005, Microsoft Visual J# 2005, and other third-party tools and compilers Visual Basic NET Versions The first version of Visual Basic NET (Microsoft Visual Basic NET 2002) was released in February 2002 The second release (Microsoft Visual Basic NET 2003) was widely available in March 2003 After a long period of development and integration work, Microsoft released Visual Basic 2005 in late 2005 Visual Basic 2005 is now so tightly integrated with Visual Studio that it is only available as a component in the Visual Studio 2005 programming suite, which includes the Visual C#, Visual C++, and Visual J# compilers and other Microsoft NET development tools However, Visual Studio 2005 is sold in several different product configurations, including Standard Edition, Professional Edition, Team Suite, and Express Edition I've written this book to be compatible with all editions of Visual Basic 2005 and Visual Studio 2005, but especially with the tools and techniques available in Visual Studio Standard Edition and Visual Studio Professional Edition Although Visual Basic 2005 is similar in many ways to Visual Basic NET 2003, there are many important differences and improvements, so I recommend that you complete the exercises in this book using the Visual Basic 2005 software NOTE The Visual Basic 2005 software is not included with this book! The CD- ROM distributed with most versions of this book contains practice files, sample databases, and other useful information that requires the Visual Basic 2005 software (sold separately) for use Finding Your Best Starting Point in This Book This book is designed to help you build skills in a number of essential areas You can use this book if you're new to programming, switching from another programming language, or upgrading from Visual Basic 6 or Visual Basic NET 2003 Use the following table to find your best starting point in this book If you are Follow these steps New To programming Install the practice files as described in the section “Installing the Practice Files on Your Computer” later in this introduction Learn basic skills for using Visual Basic 2005 by working sequentially from Chapter 1 through Chapter 17 Complete Part IV, “Database and Web Programming,” as your level of interest or experience dictates Upgrading From Visual Basic NET 2002 or 2003 Install the practice files as described in the section “Installing the Practice Files on Your Computer.” Complete Chapters 1 through 4, skim Chapters 5 through 17, and complete Chapters 18 through 20 For a discussion of specific features that have changed in this upgrade, read Chapters 1, 4, 5, 7, 8, and 13 From Visual Basic 6 Install the practice files as described in the section “Installing the Practice Files on Your Computer.” Read Chapters 1 through 4 carefully to learn the new features of the Visual Studio 2005 development environment Pay special attention to the “Upgrade Notes: Migrating Visual Basic 6 Code to Visual Basic 2005” sidebars near the beginning of each chapter, which highlight the significant differences between Visual Basic 6 and Visual Basic 2005 Skim Chapters 5 through 13 to review the fundamentals of event-driven programming, using variables, and writing decision structures Give special attention to Chapters 5, 6, 9, and 12 Work sequentially from Chapters 14 through 20 to learn the new Visual Basic 2005 features related to user interface design, database programming, and Web programming Referencing This book after working through the chapters Use the index to locate information about specific topics, and use the table of contents to locate information about general topics Use the Upgrading Index to see a list of the new features in Visual Basic 2005 and how Visual Basic 6 program code should be upgraded Read the Quick Reference at the end of each chapter for a brief review of the major tasks in the chapter The Quick Reference topics are listed in the same order as they're presented in the chapter System Requirements You'll need the following hardware and software to complete the exercises in this book: Microsoft Windows XP Professional Edition with Service Pack 2 or Microsoft Windows XP Home Edition with Service Pack 2, Microsoft Windows Server 2003 with Service Pack 1, or Microsoft Windows 2000 with Service Pack 4 (Microsoft Windows 2000 Datacenter Server is not supported) Microsoft Visual Studio 2005 Standard Edition or Microsoft Visual Studio 2005 Professional Edition 600 MHz Pentium or compatible processor (1 GHz Pentium recommended) 192 MB RAM (256 MB or more recommended) Video (800 x 600 or higher resolution) monitor with at least 256 colors (1024 x 768 High Color 16-bit recommended) CD-ROM or DVD-ROM drive Microsoft Mouse or compatible pointing device NOTE This book and the practice files were tested using Visual Studio 2005 Standard and Visual Studio 2005 Professional You might notice a few differences if you're using other editions of Visual Studio 2005 In particular, if you're using Visual Studio 2005 Express Edition, a few features will be unavailable to you TIP The complete Car Loan Calculator Web site is located in the c:\vb05sbs\chap20 folder Use the Open Web Site command on the File menu to open an existing Web site Click the Start Debugging button Visual Studio builds the Web site and displays it in Internet Explorer Enter 8000 for the loan amount and 0.08 for the interest rate, then click Calculate The result is $250.69 Whenever you add to a project, it is always good to go back and test the original features to verify that they have not been modified inadvertently Your screen looks like this: The new hyperlink (Display Loan Prospects) is visible at the bottom of the Web page Click Display Loan Prospects to load the database table Internet Explorer loads the Instructor and PhoneNumber fields from the Students.mdb database into the grid view object Your Web page looks something like this: The information is nicely formatted and appears useful By default, you'll find that the data in this table cannot be sorted, but you can change this option by selecting the Enable Sorting check box in GridView Tasks If your database contains many rows (records) of information, you can select the Enable Paging check box in GridView Tasks to display a list of page numbers at the bottom of the Web page (like a list you might see in Microsoft Document Explorer or a search engine that displays many pages of “hits” for your search) Click the Back and Forward buttons in Internet Explorer As you learned earlier, you can jump back and forth between Web pages in your Web site, just as you would in any professional Web site When you're finished experimenting, close Internet Explorer to close the Web site You've added a table of custom database information without adding any program code! One Step Further: Setting the Web Site Title in Internet Explorer Haven't had enough yet? Here's one last Web programming tip to enhance your Web site and send you off on your own explorations You might have noticed while testing the Car Loan Calculator Web site that Internet Explorer displayed “Untitled Page” in the title bar when displaying your Web site In other words, your screen looked like this: You can customize what Internet Explorer and other browsers display in the title bar by setting the Title property of the Document object for your Web page Give it a try now Set the Title property With the Default.aspx Web page open in Design mode, click the Document object in Object list box of the Properties window Each Web page in a Web site contains a Document object that holds important general settings for the Web page However, the Document object is not selected by default in the Designer, so you might not have noticed it One of the important properties for the Document object is Title, which sets the title of the current Web page in the browser Set the Title property to “Car Loan Calculator” The change does not appear on the screen, but Visual Web Developer records it internally Click the Start Debugging button Visual Studio opens Internet Explorer and loads the Web site Now a more useful title bar appears, as shown in the following illustration: Now that looks better Close Internet Explorer, and update the Title properties for the other Web pages in your Web site When you're finished experimenting with the Car Loan Calculator, save your changes, and close Visual Studio Congratulations on completing the entire Microsoft Visual Basic 2005 Step by Step programming course! Take a few moments to flip back through this book and see all that you have learned Now you're ready for more sophisticated Visual Basic challenges and programming techniques Check out the resource list in Appendix A, “Where to Go For More Information,” for a few ideas about continuing your learning But take a break first— you've earned it! Chapter 20 Quick Reference To Do this Create a new ASP.NET Web site Click the New Web Site command on the File menu, click ASP.NET Web Site, specify a folder location in the Location list box, and then click OK Switch between Click the Source or Design tabs in the Designer Design mode and Source mode in the Web Page Designer Enter text on a Web page Click the Design tab, and then type the text you want to add Format text on a Web page On the page, select the text that you want to format, and then click a button or control on the Formatting toolbar View the HTML code in your Web page Click the Source tab in the designer Add controls to Display the Web page in Design mode, open the Toolbox a Web page (which automatically contains Visual Web Developer controls), position the insertion point where you want to place the control on the page, and then double-click the control in the Toolbox Change the Use the Properties window to change the object's ID name of an property to a new name object on a Web page Write an event procedure for an object on a Web page Double-click the object to display the code-behind file, and write the event procedure code for the object in the Code Editor Verify the Use one or more validator controls from the Validation format of the tab of the Toolbox to test the data entered in an input data entered by control the user into a control on a Web page Run and test a Web site in Visual Studio Click the Start Debugging button on the Standard toolbar Visual Studio builds the project and loads the Web site in Internet Explorer Create an Click the Add New Item command on the Website menu, HTML page for and then add the new HTML page to the project Create a project and format the HTML page by using the Web Page Designer Create a link to Add a HyperLink control to your Web page, and then set other Web the control's NavigateUrl property to the address of the pages on your linked Web page Web site Display database records on a Web page Add a GridView control to a Web page in the Web Page Designer Establish a connection to the database and format the data by using commands in the GridView Tasks list box (The Choose Data Source command launches the Data Source Configuration Wizard.) Set the title displayed for Web pages on the Internet Explorer title bar For each Web page, use the Properties window to set the Document object's Title property Part V Appendix Appendix Where to Go for More Information This book has presented beginning, intermediate, and advanced Visual Basic 2005 programming techniques with the aim of making you a confident software developer and Microsoft Windows programmer Now that you've experimented with many of the tools and features in Visual Basic 2005, you're ready for more advanced topics and the full breadth of the Microsoft Visual Studio 2005 development suite If you have your sights set on a career in Visual Basic programming, you might also want to test your proficiency by preparing for a certified exam in Visual Basic 2005 development In this appendix, you'll learn about additional resources for Visual Basic programming, including helpful Web sites, a source for certification information, and books that you can use to expand your Visual Basic programming skills Visual Basic Web Sites The Web is a boon to programmers and is definitely the fastest mechanism for gathering information about Visual Basic 2005 and related technologies In this section, I list several of the Web sites that I use to learn about new products and services related to Visual Basic As you use this list, note that the Internet address and contents of each site change from time to time, so the sites might not appear exactly as I've described them Considering the constant ebb and flow of the Internet, it's also a good idea to search for “Visual Basic”, “Visual Studio 2005”, and “VB.NET” occasionally to see what new information is available (For the most specific hits, include the quotes around each search item as shown.) www.msdn.microsoft.com/vbasic/ The Microsoft Corporation Visual Basic home page is the best overall site for documentation, breaking news, conference information, and product support for Visual Basic 2005 This site gives you up-to-date information about the entire Visual Basic product line and lets you know how new operating systems, applications, and programming tools affect Visual Basic development TIP Remember that you can also access MSDN resources quickly from the Visual Studio Start Page within the Visual Studio IDE The Start Page loads updated articles and news content each time you start Visual Studio, so its contents are always changing www.devx.com/ DevX is a commercial Web site devoted to numerous Windows development topics and issues, including Visual Studio and Visual Basic programming Discussion groups of professional Visual Basic programmers provide peerto-peer interaction and feedback for many development issues In addition, DevX vendor partners offer books, controls, and third-party software for sale www.microsoft.com/learning/books/ The Microsoft Learning Web site offers the newest books on Visual Basic 2005 programming from Microsoft Press authors Check here for new books about Microsoft Visual C#, Microsoft Visual C++, and Microsoft Visual J# as well You can also download freebies and send mail to Microsoft Press www.microsoft.com/learning/training/ This is the Microsoft Learning Web site for software training and services, including testing and certification Over the last few years, many Visual Basic programmers have found that they can better demonstrate their development skills to potential employers if they pass one or more certification examinations and earn a Microsoft certified credential, such as the Microsoft Certified Professional (MCP), the Microsoft Certified Systems Engineer (MCSE), or the Microsoft Certified Systems Administrator (MCSA) Visit this Web site to learn more about your certification options www.microsoft.com/communities/ This site of technical communities for many Microsoft software products and technologies offers opportunities to interact with Microsoft employees and your software development peers Through this Web site, you can access blogs, newsgroups, webcasts, technical chats, user groups, and other resources related to Visual Studio development Currently Visual Studio newsgroup topics are listed under the Microsoft MSDN (Developer Newsgroups) category Books for Visual Basic and Visual Studio Programming Printed books about Visual Basic and Visual Studio programming provide in-depth sources of information and self-paced training that Web sites can supplement but not replace As you seek to expand your Visual Basic and Visual Studio programming skills, I recommend that you consult the following sources of printed information (listed here by category) Note that this isn't a complete bibliography of Visual Studio 2005 titles, but it is a list that's representative of the books available in English at the time of the initial release of Visual Studio 2005 I also list books related to database programming, Web programming, Visual Basic for Applications (VBA) programming, and general books about software development and computer science Visual Basic 2005 Programming Programming Microsoft Visual Basic 2005 Core Reference, by Francesco Balena (Microsoft Press, ISBN 0-7356-2183-7) Practical Guidelines and Best Practices for Microsoft Visual Basic and Visual C# Developers, by Francesco Balena and Guiseppe Dimauro (Microsoft Press, ISBN 0-7356-2172-1) OOP: Building Reusable Components with Microsoft Visual Basic NET, by Ken Spencer, Tom Eberhard, and John Alexander (Microsoft Press, ISBN 0-7356-1379-6) This book covers Visual Basic NET 2003 but is still useful Visual Studio 2005 and Microsoft NET Framework Working with Microsoft Visual Studio 2005 Team System, by Richard Hundhausen (Microsoft Press, ISBN 0-7356-2185-3) Debugging, Tuning, and Testing Microsoft NET Framework 2.0 Applications, by John Robbins (Microsoft Press, ISBN 0-7356-2202-7) Database Programming with ADO.NET Microsoft ADO.NET 2.0 Step by Step, by Rebecca Riordan (Microsoft Press, ISBN 0-7356-2164-0) Programming Microsoft ADO.NET 2.0 Core Reference, by David Sceppa (Microsoft Press, ISBN 0-7356-2206-X) Programming Microsoft ADO.NET 2.0 Applications: Advanced Topics, by Glenn Johnson (Microsoft Press, ISBN 0-7356-2141-1) Microsoft SQL Server 2005 Express Step by Step, by Jackie Goldstein (Microsoft Press, ISBN 0-7356-2184-5) Web Programming with ASP.NET Microsoft Visual Web Developer 2005 Express Edition: Build a Web Page Now! by Jim Buyens (Microsoft Press, ISBN 0-7356-2212-4) Microsoft ASP.NET 2.0 Programming Step by Step, by George Shepherd (Microsoft Press, ISBN 0-7356-2201-9) Programming Microsoft ASP.NET 2.0 Core Reference, by Dino Esposito (Microsoft Press, ISBN 0-7356-2176-4) Programming ASP.NET 2.0 Applications: Advanced Topics, by Dino Esposito (Microsoft Press, ISBN 0-7356-2177-2) Beginning ASP.NET 2.0 Databases: Beta Preview, by John Kauffman, Thiru Thangarathinam (Wrox Press, ISBN 0-7645-7081-1) Visual Basic for Applications Programming Microsoft Office Excel 2003 Programming Inside Out, by Curtis Frye, Wayne S Freeze, and Felicia K Buckingham (Microsoft Press, ISBN 0-7356-1985-9) Programming Microsoft Office Access 2003 (Core Reference), by Rick Dobson (Microsoft Press, ISBN 0-7356-1942-5) General Books about Programming and Computer Science Code Complete, Second Edition, by Steve McConnell (Microsoft Press, ISBN 0-7356-1967-0) Code, by Charles Petzold (Microsoft Press, ISBN 0-7356-1131-9) Writing Secure Code, Second Edition, by Michael Howard, David LeBlanc (Microsoft Press, ISBN 0-7356-1722-8) Software Project Survival Guide, by Steve McConnell (Microsoft Press, ISBN 1-57231-621-7) Data Structures and Algorithms Using Visual Basic NET, by Michael McMillan (Cambridge University Press, ISBN 0-521547652) The Art of Computer Programming, Volumes 1-3, by Donald Knuth (Addison-Wesley Professional, ISBN 0-201485419) Data Structures and Algorithms, by Alfred V Aho, Jeffrey D Ullman, John E Hopcroft (Addison-Wesley, ISBN 0-201000237) About the Author Michael Halvorson is the author or co-author of over 30 books, including Microsoft Visual Basic NET Step by Step, Microsoft Office XP Inside Out, Microsoft Visual Basic 6.0 Professional Step By Step, and Learn Microsoft Visual Basic 6.0 Now Michael earned a bachelor's degree in Computer Science from Pacific Lutheran University in Tacoma, Washington, and master's and doctoral degrees in History from the University of Washington in Seattle He was employed at Microsoft Corporation from 1985 to 1993, and he has been an advocate for Visual Basic programming since the product's original debut at Windows World in 1991 Michael is currently an assistant professor of History at Pacific Lutheran University, where he teaches courses in early modern Europe, the Middle Ages, Western Civilization, and interdisciplinary studies In addition to his technical books, he is the editor or co-editor of two recent essay collections, Loharano (The Water Spring): Missionary Tales from Madagascar, and A Lutheran Vocation: Philip A Nordquist and the Study of History at Pacific Lutheran University He lives in Seattle with his wife and two sons ... ISBN: 0-7356-2131-4 Introduction Welcome to Microsoft Visual Basic 2005 Step by Step, a comprehensive introduction to Visual Basic programming using the Microsoft Visual Basic 2005 software I've designed this practical, hands-on tutorial with a variety of... Chapter 1: Visual Basic is now a full member of Visual Studio—it shares the Visual Studio development environment with Microsoft Visual C++ 2005, Microsoft Visual C# 2005, Microsoft Visual J# 2005, and... you become comfortable with the development environment in Microsoft Visual Studio 2005, you can use the same tools to write programs for Microsoft Visual C++ 2005, Microsoft Visual C# 2005, Microsoft Visual J# 2005, and other third-party tools and compilers

Ngày đăng: 25/03/2019, 16:04

Từ khóa liên quan

Mục lục

  • Microsoft® Visual Basic® 2005 Step by Step

  • Copyright

    • Companion Content

    • Introduction

      • What is Visual Basic 2005?

      • Finding Your Best Starting Point in This Book

      • System Requirements

      • Prerelease Software

      • Installing and Using the Practice Files

      • Uninstalling the Practice Files

      • Conventions and Features in This Book

      • Helpful Support Links

      • Support for this Book

      • Part I: Getting Started with Microsoft Visual Basic 2005

        • Chapter 1: Exploring the Visual Studio Integrated Development Environment

          • The Visual Studio Development Environment

          • The Visual Studio Tools

          • The Properties Window

          • Moving and Resizing the Programming Tools

          • Opening a Web Browser Within Visual Studio

          • Getting Help

          • Customizing IDE Settings to Match Step-by-Step Exercises

          • One Step Further: Exiting Visual Studio

          • Chapter 1 Quick Reference

Tài liệu cùng người dùng

Tài liệu liên quan