Visual Basic 2005 Express Edition for Dummies.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
01_597051 ffirs.qxd 10/20/05 1:17 PM Page iii Visual Basic® 2005 Express Edition FOR DUMmIES‰ by Richard Mansfield 01_597051 ffirs.qxd 10/20/05 1:17 PM Page i Visual Basic® 2005 Express Edition FOR DUMmIES‰ 01_597051 ffirs.qxd 10/20/05 1:17 PM Page ii 01_597051 ffirs.qxd 10/20/05 1:17 PM Page iii Visual Basic® 2005 Express Edition FOR DUMmIES‰ by Richard Mansfield 01_597051 ffirs.qxd 10/20/05 1:17 PM Page iv Visual Basic® 2005 Express Edition For Dummies® Published by Wiley Publishing, Inc. 111 River Street Hoboken, NJ 07030-5774 www.wiley.com Copyright © 2006 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permit- ted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and other countries, and may not be used without written permission. Visual Basic is a registered trademark of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REP- RESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CON- TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CRE- ATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CON- TAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FUR- THER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFOR- MATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services, please contact our Customer Care Department within the U.S. at 800-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit www.wiley.com/techsupport. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: 2005927625 ISBN-13: 978-0-7645-9705-3 ISBN-10: 0-7645-9705-1 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 1B/QZ/RR/QV/IN 01_597051 ffirs.qxd 10/20/05 1:17 PM Page v About the Author Richard Mansfield’s recent titles include Office 2003 Application Development All-in-One Desk Reference For Dummies, CSS Web Design For Dummies, Visual Basic .NET Weekend Crash Course, Visual Basic .NET Database Programming For Dummies, Visual Basic .NET All-in-One Desk Reference For Dummies, and Visual Basic 6 Database Programming For Dummies (all from Wiley). From 1981 through 1987, he was editor of COMPUTE! Magazine, during which time he wrote hundreds of magazine articles and two columns. From 1987 to 1991, he was editorial director and partner in Signal Research and began writ- ing books full-time in 1991. He has written 37 computer books since 1982. Of those, four became bestsellers: Machine Language for Beginners (COMPUTE! Books), The Second Book of Machine Language (COMPUTE! Books), The Visual Guide to Visual Basic (Ventana), and The Visual Basic Power Toolkit (Ventana, with Evangelos Petroutsos). Overall, his books have sold more than 500,000 copies worldwide and have been translated into 11 languages. 01_597051 ffirs.qxd 10/20/05 1:17 PM Page vi 01_597051 ffirs.qxd 10/20/05 1:17 PM Page vii Dedication This book is dedicated to my mother, Florence Mansfield. 01_597051 ffirs.qxd 10/20/05 1:17 PM Page viii 01_597051 ffirs.qxd 10/20/05 1:17 PM Page ix Author’s Acknowledgments I’d like to thank the following people for their contributions to this book. Acquisitions Editor Katie Feltman is always a pleasure to work with — knowledgeable, enthusiastic, and good with authors (at least this one, anyway). Project Editor Becky Huehls also deserves praise for her thoroughgoing edit, and the many improvements to the book that resulted. Technical Editor John Mueller is a highly regarded author in the computer book field (and a friend, and coauthor of previous titles with me). I feel lucky that he agreed to review my manuscript for errors in both the code and the concepts. His considerable depth of knowledge contributed to the quality of the book. If you disagree with some of my technical or theoretical observa- tions, assume that John did too, but I wasn’t wise enough to take his advice and change my remarks. I also want to thank Copy Editor Andy Hollandbeck for making many improve- ments. Andy not only knows how to write good English, he’s also more famil- iar than most copy editors with computer programming. Plus, he seems like a good guy in the bargain. Happily, Andy seems to have pretty balanced views about the great serial comma debate, and the current conflict over gerunds. To these, and all the good people at Wiley who contributed in so many addi- tional ways to this book, my thanks for the time and care they took to ensure its quality every step along the way from original idea to final publication. 01_597051 ffirs.qxd 10/20/05 1:17 PM Page x Publisher’s Acknowledgments We’re proud of this book; please send us your comments through our online registration form located at www.dummies.com/register/. Some of the people who helped bring this book to market include the following: Acquisitions, Editorial, and Composition Services Media Development Project Coordinators: Adrienne Martinez, Project Editor: Rebecca Huehls Kathryn Shanks Acquisitions Editor: Katie Feltman Layout and Graphics: Carl Byers, Copy Editor: Andy Hollandbeck Andrea Dahl, Lauren Goddard, Stephanie D. Jumper, Barry Offringa, Technical Editor: John Mueller Mary Gillot Virgin Editorial Manager: Leah Cameron Proofreaders: Leeann Harney, Permissions Editor: Laura Moss Carl William Pierce, TECHBOOKS Media Development Specialist: Travis Silvers Production Services Media Development Manager: Indexer: TECHBOOKS Production Services Laura VanWinkle Media Development Supervisor: Richard Graves Editorial Assistant: Amanda Foxworth Cartoons: Rich Tennant (www.the5thwave.com) Publishing and Editorial for Technology Dummies Richard Swadley, Vice President and Executive Group Publisher Andy Cummings, Vice President and Publisher Mary Bednarek, Executive Acquisitions Director Mary C. Corder, Editorial Director Publishing for Consumer Dummies Diane Graves Steele, Vice President and Publisher Joyce Pepple, Acquisitions Director Composition Services Gerry Fahey, Vice President of Production Services Debbie Stailey, Director of Composition Services 02_597051 ftoc.qxd 10/20/05 1:18 PM Page xi Contents at a Glance Introduction ................................................................1 Part I: The Basics of Visual Basic Express ....................11 Chapter 1: What It’s All About: Visual Basic Express Takes a Bow ...........................13 Chapter 2: Up and Running ............................................................................................23 Chapter 3: At Your Service: Loads of Built-In Helpers ................................................35 Chapter 4: Tackling Essential Tools ..............................................................................51 Part II: Programming the Practical Way ......................75 Chapter 5: Common Tasks .............................................................................................77 Chapter 6: It’s All about My ............................................................................................97 Chapter 7: Whose Type Are You: Managing Variable Types ....................................105 Chapter 8: Superstrings: Managing Arrays ................................................................129 Chapter 9: Pretty Printing ............................................................................................143 Chapter 10: Testing and Deployment ..........................................................................161