<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-183359631814992490</id><updated>2011-04-21T14:53:10.326-07:00</updated><title type='text'>All About Of The World</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://allaboutoftheworld.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/183359631814992490/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://allaboutoftheworld.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>coboy</name><uri>http://www.blogger.com/profile/12492175175781656489</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-183359631814992490.post-8306169986739968772</id><published>2008-10-25T21:08:00.000-07:00</published><updated>2008-10-25T21:19:10.158-07:00</updated><title type='text'>VISUAL BASICS 6 FOR DUMMIES</title><content type='html'>&lt;div class="post-body entry-content"&gt; A REFERENCE FOR THE REST OF US!&lt;br /&gt;Author of Microsoft Office 2000&lt;br /&gt;For Windows For Dummies&lt;br /&gt;&lt;br /&gt;Hungry Minds (tm)&lt;br /&gt;Best-Selling Books - Digital Downloads - e-Books - Answer Networks - e-Newsletters - Branded Web Sites - e-Learning&lt;br /&gt;New York, NY - Cleveland, OH - Indianapolis,IN&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Visual Basics 6 For Dummies&lt;br /&gt;&lt;br /&gt;Published by&lt;br /&gt;Hungry Minds, Inc.&lt;br /&gt;909 Third Avenue&lt;br /&gt;New York, NY 10022&lt;br /&gt;www.hungryminds.com&lt;br /&gt;www.dummies.com&lt;br /&gt;&lt;br /&gt;Copyright @ 1998 Hungry Minds, Inc. All rights reserved. No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher.&lt;br /&gt;&lt;br /&gt;Library of Congress Catalog Card No.: 98-87098&lt;br /&gt;ISBN: 0-7645-0370-7&lt;br /&gt;&lt;br /&gt;Printed in the United States of America&lt;br /&gt;&lt;br /&gt;16 15 14 13&lt;br /&gt;IB/QT/QX/QR/IN&lt;br /&gt;&lt;br /&gt;Distributed in the United States by Hungry Minds, Inc.&lt;br /&gt;&lt;br /&gt;Distributed by CDG Books Canada Inc. for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty. Ltd. for Australia and New Zealand; by TransQuest Publishers Pie Ltd. for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc. for Taiwan; by ICG Muse, Inc. for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R. Ltda. for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc. for Micronesia; by Chips Computadoras S.A. de C.V. for Mexico; by Editorial Norma de Panama S.A. for Panama; by American Bookshops for Finland.&lt;br /&gt;&lt;br /&gt;For general information on Hungry Minds' 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.&lt;br /&gt;&lt;br /&gt;For sales inquiries and reseller information, including discounts, premium and bulk quantity sales, and foreign-language translations, please contact our Customer Care Department at 800-434-3422, fax 317-572-4002, or write to Hungry Minds, Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256.&lt;br /&gt;&lt;br /&gt;For information on licensing foreign or domestic rights, please contact our Sub-Rights Customer Care Department at 212-884-5000.&lt;br /&gt;&lt;br /&gt;For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470.&lt;br /&gt;&lt;br /&gt;For Information on using Hungry Minds' products and services in the classroom or for ordering examination copies, please contact our Educational Sales Department at 800-434-2086 or fax 317-572-4005.&lt;br /&gt;&lt;br /&gt;For press review copies, author interviews, or other publicity information, please contact our Public Relations department at 317-572-3168 or fax 317-572-4168.&lt;br /&gt;&lt;br /&gt;LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY : THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES.&lt;br /&gt;&lt;br /&gt;Trademarks: Visual Basic is a registered trademark of Microsoft Corporation in the United States and/or other countries. For Dummies, Dummies Man, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, and related trade dress are registered trademarks or trademarks of Hungry Minds, Inc. in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Hungry Minds, Inc. is not associated with any product or vendor mentioned in this book.&lt;br /&gt;&lt;br /&gt;Hungry Minds is a trademark of Hungry Minds, Inc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** About the Author&lt;br /&gt;&lt;br /&gt;At the time of this writing, the author's body temperature was 98.6 degrees Fahrenheit, and he was breathing normally. But beyond the physical characteristics, the author of this book has also has written over a dozen computer books including MORE Visual Basic For Windows For Dummies, Microsoft Office 97 For Windows For Dummies, and MORE Microsoft Office 97 For Windows For Dummies. When he's not writing computer books, he does what other computer authors usually do and writes articles for computer magazines instead. He writes a monthly column for Boardwatch magazine and has written articles for The Net magazine as well.&lt;br /&gt;&lt;br /&gt;When not writing computer books, he often refers to himself in the third person singular form, such as in this current sentence. While such self-referential sentences tend to look authoritative and profound when appearing in print within a book's "About the Author" page, they tend to make people stare in a most peculiar way when spoken out loud in public. Not many people introduce themselves at parties as "Hi, his name is Wallace," and this author, of course, is no exception.&lt;br /&gt;&lt;br /&gt;In his spare time, Wallace can often be seen watching the demolition crews knock down the buildings in San Diego that used to house his former employer. Wallace's only regret is that the demolition crews didn't start much earlier when his former boss and coworkers would still have been inside.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Dedication&lt;br /&gt;&lt;br /&gt;This book is dedicated to all the wonderful people I've met during my mad pursuit in the world of stand-up comedy:&lt;br /&gt;&lt;br /&gt;Budd Friedman, for giving me my first national TV appearance on his show A&amp;amp;E's Evening at the Improv.&lt;br /&gt;&lt;br /&gt;Mark Kuker, for offering delightfully strange, one-nighter gigs in Ruidoso and Deming (home of the annual duck races), New Mexico. Mark and his wife Amanda are two of the best people a comedian could ever hope to work for.&lt;br /&gt;&lt;br /&gt;Steve Schirripa and Don Learned, for giving me my first Las Vegas gig at the Riviera Comedy Club, located in the Riviera Hotel &amp;amp; Casino. The next time you're in Las Vegas, drop by, see a show, and dump some money in the Riviera Casino slot machines. Who knows? Maybe you'll win enough money to buy yourself a new computer.&lt;br /&gt;&lt;br /&gt;Patrick DeGuire and Dat Phan who helped me put together Top Bananas, our company devoted to booking the three of us in corporate comedy events around San Diego. Thanks also goes to Fred Burns, Leo (the man, the myth, the legend) Fontaine, Ron Clark, Dante, Frank Manzano, Chris (the Zooman) Clobber, Bob Zany, Tony Vicich, and George Hirschmann.&lt;br /&gt;&lt;br /&gt;Final thanks go to Gene Perret, Linda Perret (and the rest of the whole happy Perret clan), Liz Sage, and everyone else who has helped me navigate my way through the minefield of inflated egos and hair-trigger temperamental personalities known as show business.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Author's Acknowledgments&lt;br /&gt;&lt;br /&gt;Nobody writes and publishes a book without the help of other people, and this book is no exception. It goes without saying (although I'm going to say it anyway) that two of the most important people responsible for this book are Matt Wagner and Bill Gladstone of Waterside Productions. Thanks guys. I'd give you more than your usual 15 percent cut but if I did, then I wouldn't have anything left over to pay for my groceries.&lt;br /&gt;&lt;br /&gt;Two other people who deserve thanks include Brian Kramer of IDG Books Worldwide, Inc., and Allen Wyatt of Discovery Computing, Inc.&lt;br /&gt;&lt;br /&gt;Next, I have to acknowledge Cassandra (my wife) along with Bo, Scraps, Tasha, and Nuit (my cats) for their support during the long hours I've spent glued to my computer instead of doing anything else around the house.&lt;br /&gt;&lt;br /&gt;A final acknowledgment goes to the friendly people at Complete Design &amp;amp; Remodeling including Wes McKusick and Tom DeLisle who did all the remodeling of my new house while I just wrote them checks.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Publisher's Acknowledgments&lt;br /&gt;&lt;br /&gt;We're proud of this book; please send us your comments through our Online Registration Form located at www.dummies.com.&lt;br /&gt;&lt;br /&gt;Some of the people who helped bring this book to market include the following:&lt;br /&gt;&lt;br /&gt;Acquisitions, Editorial, Media Development&lt;br /&gt;&lt;br /&gt;Project Editor: Brian Kramer&lt;br /&gt;Acquisitions Editor: Sherri Morningstar&lt;br /&gt;Copy Editor: Patricia Yuu Pan&lt;br /&gt;Technical Editor: Allen Wyatt&lt;br /&gt;Media Development Editor: Marita Ellixson&lt;br /&gt;Associate Permissions Editor: Carmen Krikorian&lt;br /&gt;Editorial Manager: Leah P. Cameron&lt;br /&gt;Media Development Manager: Heather Heath Dismore&lt;br /&gt;Editorial Assistant: Donna Love&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Production&lt;br /&gt;&lt;br /&gt;Project Coordinator: Karen York&lt;br /&gt;Layout and Graphics: Traci Ankrom, Lou Boudreau, Kelly Hardesty, Angela F. Hunckler, Jane E. Martin, Brent Savage, Michael A. Sullivan, Dan Whetstine.&lt;br /&gt;Proofreaders: Kelli Botta, Michelle Croninger, Rachel Garvey, Sandra Wilson, Janet M. Withers&lt;br /&gt;Indexer: Sherry Massey&lt;br /&gt;Special Help: Tim Gallan&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;General and Administrative&lt;br /&gt;&lt;br /&gt;Hungry Minds, Inc.: John Kilcullen, CEO; Bill Barry, President and COO; John Ball, Executive VP, Operations &amp;amp; Administration; John Harris, CFO&lt;br /&gt;&lt;br /&gt;Hungry Minds Technology Publishing Group: Richard Swadley, Senior Vice President and Publisher; Mary Bednarek, Vice President and Publisher, Networking and Certification; Walter R. Bruce Ill, Vice President and Publisher, General User and Design Professional; Joseph Wikert, Vice President and Publisher, Programming; Mary C. Corder, Editorial Director, Branded Technology Editorial; Andy Cummings, Publishing Director, General User and Design Professional; Barry Pruett, Publishing Director, Visual&lt;br /&gt;&lt;br /&gt;Hungry Minds Manufacturing: Ivor Parker, Vice President, Manufacturing&lt;br /&gt;&lt;br /&gt;Hungry Minds Marketing: John Helmus, Assistant Vice President, Director of Marketing&lt;br /&gt;&lt;br /&gt;Hungry Minds Production for Branded Press: Debble Stalley, Production Director&lt;br /&gt;&lt;br /&gt;Hungry Minds Sales: Roland Elgey, Senior Vice President, Sales and Marketing; Michael Violano, Vice President, International Sales and Sub Rights&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The publisher would like to give special thanks to Patrick J. McGovern, without whom this book would not have been possible.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++  CONTENTS AT A GLANCE&lt;br /&gt;&lt;br /&gt;Reader's Note:&lt;br /&gt;&lt;br /&gt;INTRODUCTION&lt;br /&gt;&lt;br /&gt;PART I: CREATING A VISUAL BASIC 6 PROGRAM&lt;br /&gt;&lt;br /&gt;Chapter 1: How Visual Basic Works&lt;br /&gt;Chapter 2: Using the Visual Basic User Interface&lt;br /&gt;Chapter 3: Designing Your First User Interface&lt;br /&gt;Chapter 4: Writing BASIC Code&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PART II: CREATING USER INTERFACES&lt;br /&gt;&lt;br /&gt;Chapter 5: User Interface Design 101&lt;br /&gt;Chapter 6: Forms and Buttons&lt;br /&gt;Chapter 7: Boxes and Buttons for Making Choices&lt;br /&gt;Chapter 8: Text Boxes for Typing and Showing Words&lt;br /&gt;Chapter 9: Scroll Bars and Labels&lt;br /&gt;Chapter 10: Pretty Pictures and Objects from Geometry&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PART III: MAKING MENUS&lt;br /&gt;&lt;br /&gt;Chapter 11: Creating and Editing Pull-Down Menus&lt;br /&gt;Chapter 12: Submenus, Growing Menus, and Pop-Up Menus&lt;br /&gt;Chapter 13: Dialog Boxes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PART IV: THE BASICS OF WRITING CODE&lt;br /&gt;&lt;br /&gt;Chapter 14: Event Procedures&lt;br /&gt;Chapter 15: Using Variables&lt;br /&gt;Chapter 16: Responding to the User&lt;br /&gt;Chapter 17: Math 101: Arithmetic, Logical, and Comparison Operators&lt;br /&gt;Chapter 18: Strings and Things&lt;br /&gt;Chapter 19: Defining Constants and Using Comments&lt;br /&gt;Chapter 20: Killing Bugs&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PART V: MAKING DECISIONS (SOMETHING YOU STOP DOING WHEN YOU GET MARRIED)&lt;br /&gt;&lt;br /&gt;Chapter 21: The If-Then and If-Then-Else Statements&lt;br /&gt;Chapter 22: The Select Case Statement&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PART VI: GETTING LOOPY&lt;br /&gt;&lt;br /&gt;Chapter 23: The Do While and Do-Loop While Loops&lt;br /&gt;Chapter 24: The Do Until and Do-Loop Until Loops&lt;br /&gt;Chapter 25: For Next Loops That Can Count&lt;br /&gt;Chapter 26: Nested Loops and Quick Exits&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PART VII: WRITING SUBPROGRAMS (SO YOU DON'T GO CRAZY ALL AT ONCE)&lt;br /&gt;&lt;br /&gt;Chapter 27: General Procedures (Subprograms That Everyone Can Share)&lt;br /&gt;Chapter 28: Passing Arguments&lt;br /&gt;Chapter 29: Functions, a Unique Type of Subprogram&lt;br /&gt;Chapter 30: Getting Some Class with Object-Oriented Programming&lt;br /&gt;Chapter 31: Managing Files&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PART VIII: DATABASE FILES AND PRINTING&lt;br /&gt;&lt;br /&gt;Chapter 32: Creating Database Files&lt;br /&gt;Chapter 33: Using Files from Database Programs You'd Rather Not Use&lt;br /&gt;Chapter 34: Making Your Program Print Stuff&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PART IX: THE PART OF TENS&lt;br /&gt;&lt;br /&gt;Chapter 35: The Ten Visual Basic Topics That Didn't Fit Anywhere Else&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;APPENDIX A: ABOUT THE CD&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ Reader's Note:&lt;br /&gt;This book has been scanned and edited by Jane Etherington. She has marked the beginning of each chapter with a double plus [++], The beginning of each section in the chapters with a double star [**] and each sub-heading with a single star [*]. These markings are to assist the reader in finding their way around the book more easily and rapidly&lt;br /&gt;&lt;br /&gt;The reader may come across such mistakes as: The letter "I" for a number 1 or the letter "L" or any combination of these. Other mistakes may also have been missed. These have been corrected when detected, but inevitably, some may have been missed. It is our hope that these minor errors do not detract from the overall enjoyment that this book gives?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ PART I - CREATING A VISUAL BASIC 6 PROGRAM&lt;br /&gt;&lt;br /&gt;In this part ......&lt;br /&gt;&lt;br /&gt;Writing your own program isn't hard. If you've always been curious about computer programming but wer intimidated by the hard-to-read books, less-than-useful softward, or obtuse and convoluted "explanations" from "experts," then this book is for you.&lt;br /&gt;&lt;br /&gt;Rather than impress you with matematical proofs and theoretical background about computer programming, this book (with the help of Visual Basic) lets you jump right in and start finding out about programming on your own computer all by yourself.&lt;br /&gt;&lt;br /&gt;So grab some snack foods, a few carbonated beverages, a comfortable seat, and get ready to program your computer and make it finally to what you want it to do.......&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 1&lt;br /&gt;&lt;br /&gt;HOW VISUAL BASIC WORKS&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Looking at the Visual Basic development cycle&lt;br /&gt;Creating a Visual Basic user interface&lt;br /&gt;Understanding what BASIC code does&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The whole purpose of writing a program is to make your computer do something useful. People often spend thousands of dollars for one of these machines, so it's important that the computer does something more than consume electricity and take up space on a desk.&lt;br /&gt;&lt;br /&gt;Before you delve into the world of programming, keep two thoughts in mind. First, anyone can write a program. Programming is just a skill, much like swimming, sailing, or shoplifting. If you've ever taught yourself a new hobby or skill, you can teach yourself how to write a program without an extensive mathematics background or a fancy college degree that puts you in debt for the next ten years.&lt;br /&gt;&lt;br /&gt;Second, the key to programming is defining exactly what you want your program to do. Defining what you want your program to do is half the battle (a battle that governments and large corporations routinely lose all the time). The other half of the battle involves taking the time to write your program and making sure it works correctly. (This part of the battle is another place where governments and large corporations fall flat on their faces on a fairly regular basis).&lt;br /&gt;&lt;br /&gt;You can write a program to make your computer do anything you want, short of launching nuclear missiles at your next-door neighbor. (Of course, if you write a program for the Air Force's computers, you may even be able to do that).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Writing a Visual Basic Program&lt;br /&gt;&lt;br /&gt;There is no single correct way to write a program. Theoretically, you can use a million different ways to write a program correctly, just as you can travel from New York to Los Angeles a million different ways. Some people may fly, others may take a train or drive; the more adventurous may walk, hitchhike, or hijack a vehicle. Similarly, you can write the same program a million different ways. However, no matter how you write the program, the result can always be the same.&lt;br /&gt;&lt;br /&gt;As a programmer, your job is to write a program that works correctly and is easy to use. If your program doesn't work, nobody can use it (although you often can sell a few thousand copies to unsuspecting individuals first). If your program isn't easy to use, nobody will want to use it, even if it works perfectly.&lt;br /&gt;&lt;br /&gt;Testing whether your program works is usually simple enough. If your program is supposed to print mailing labels but erases the computer's hard disk instead, then your program obviously doesn't work correctly.&lt;br /&gt;&lt;br /&gt;However, determining whether your program is easy to use is a bit more difficult. What you may consider easy to use may be almost impossible for someone else to understand.&lt;br /&gt;&lt;br /&gt;To create programs that everyone can understand how to use, Visual Basic helps you to easily produce windows, pull-down menus, dialog boxes, and command buttons. These features are the same ones found in Windows 95/98/NT programs. Visual Basic helps you write programs that look and act like other programs on the market.&lt;br /&gt;&lt;br /&gt;Making your program look and act like an existing program can help others learn your program faster. For example, most people can drive a Toyota or a Ford without any problems; the steering wheel and brakes always look and work the same way, even if the windshield wipers and horn may not. The same goes for programs. Pull-down menus contain a program's numerous commands, and you can always use the mouse to highlight and choose commands or objects. So while each program may work differently, they all look and work in similar ways.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* The Visual Basic Development Cycle&lt;br /&gt;&lt;br /&gt;Before writing a Visual Basic program (or any program for that matter), get away from your computer and plan your program using an old-fashioned paper and pencil. After you know what you want your program to accomplish and how you want it to look, then you can start writing your program. Skipping this crucial first step is like building a house without blueprints. You can do it, but it will probably take you longer.&lt;br /&gt;&lt;br /&gt;Writing a Visual Basic program requires nine steps - three steps fewer than those required to overcome and addictive habit. The first eight steps are what programmers call the development cycle. The ninth step is what programmers call job security.&lt;br /&gt;&lt;br /&gt;1. Decide what you want the computer to do.&lt;br /&gt;2. Decide how your program will look on the screen.  (The appearance of your program is its user interface).&lt;br /&gt;3. Draw your user interface using common parts such as windows, menus, and command buttons. (The parts of a user interface are objects or controls).&lt;br /&gt;4. Define the name, color, size, and appearance of each user interface object. (An object's characteristics are its properties).&lt;br /&gt;5. Write instructions in BASIC to make each part of your program do something.  (BASIC instructions are commands).&lt;br /&gt;6. Run your program to see if it works.&lt;br /&gt;7. Cry when your program doesn't work perfectly.  (Required).&lt;br /&gt;8. Fix any errors (or bugs) in your program.&lt;br /&gt;9. Repeat steps 6 through 8 over and over again until you get tired of searching for more bugs.&lt;br /&gt;&lt;br /&gt;Although you don't have to memorize these nine steps, you do have to follow them. Shortcuts aren't an option. Trying to skip from Step 1 to Step 4 is like trying to start a car by using the gas pedal but forgetting to turn the ignition key. You can try it, but you're not goint to get anywhere.&lt;br /&gt;&lt;br /&gt;Believe it or not, Step 1 is actually the hardest and most important step of all. After you know exactly what you want your program to do, it's just a matter of finding ways to do it. Persistence and creativity are helpful, as are lots of caffeine-laden beverages and plenty of sleepless nights in front of the computer screen.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Why Programs Don't Work (Part I)&lt;br /&gt;&lt;br /&gt;Writing a program that works 100 percent correctly all the time is mathematically impossible. First of all, if you write a program that works 100 percent correctly today, there's no way you can guarantee that it will work 100 percent correctly on future computer brands, models, processors, and accessories. As a result, you can never guarantee that your program will work correctly on all types of computers unless you exhaustively test every possible computer configuration in the world.&lt;br /&gt;&lt;br /&gt;Second, not only do you have to test your program with the latest and greatest products (including the ones invented after you wrote your program), but you also have to consider the virtually infinite number of possibilities that your program must face during everyday use.&lt;br /&gt;&lt;br /&gt;For example, your program needs to behae correctly if the user presses any key and then clicks the mouse anywhere on the screen. What if the user clicks the mouse by mistake while tapping a key? What if the user pounds the keyboard in frustration? What if another program happens to interfere with the computer's memory, thus affecting your program? What if..&lt;br /&gt;(well, you get the idea).&lt;br /&gt;&lt;br /&gt;Unless a programmer can plan for an infinite number of possible problems and situations that a program may face during its existence, then writing a program that works 100 percent of the time is impossible.&lt;br /&gt;&lt;br /&gt;What's scarier is that this scenario holds true for every computer operating system in the world (such as Windows 95/98/NT). Therefore, you'll always be writing programs to run on an operating system that doesn't work 100 percent correctly either. This situation is like building a house on a foundation of quicksand and then wondering why your house keeps failing apart.&lt;br /&gt;&lt;br /&gt;Because no one has an infinite amount of time to test an infinite number of possible problems, computer programs always (yes, always) will have bugs that keep them from working 100 percent correctly. That includes every program you write and every program that Microsoft's millionaire programmers may write. That's why when you write a program, set aside plenty of time for testing so you can kill any potentially fatal bugs before you give your program to someone else.&lt;br /&gt;&lt;br /&gt;So the next time you're using a program that doesn't work right, now you'll know that ifs not your fault; it's the programmer's fault.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Making a neat user interface&lt;br /&gt;&lt;br /&gt;The user interface is what someone sees when your program is running. Every program has a user interface in one form or another. Some programs have elaborate, colorful windows, while other programs have a sparse appearance - as if the programmer were afraid that screen phosphor may be in short supply one day.&lt;br /&gt;&lt;br /&gt;A Visual Basic user interface consists of forms and objects. A form is nothing more than a window that appears on the screen. Most Visual Basic programs have at least one form, although most programs likely will use several forms.&lt;br /&gt;&lt;br /&gt;Objects are items that appear on a form, such as a command button, scroll bar, option button, or check box. An object lets the user give commands to your program. If you really wanted, you could create a program with only one form and no objects, but it wouldn't be very useful or interesting.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Defining properties to make your user interface unique&lt;br /&gt;&lt;br /&gt;After you create a form and draw some objects on it, the next step is to define the properties of each form and object. An object's properties determine the object's name, color, size, location, and appearance on the screen.&lt;br /&gt;&lt;br /&gt;Different objects have different properties. Each time you draw an object on a form, Visual Basic assigns default property values, which define a generic object that no one can really use. If you want to customize an object, you need to define one or more properties for each object that your program uses. Chapter 3 provides a quick introduction to changing an object's properties.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Writing BASIC code&lt;br /&gt;&lt;br /&gt;When you're happy with the way your program looks, the next step involves writing BASIC commands (also known as code) to make your program actually work. (Don't worry. If you change your mind and want to edit the appearance of your user interface, you can go back and alter it at any time.)&lt;br /&gt;&lt;br /&gt;The whole purpose of Visual Basic code is to tell objects on a form what to do when the user does something. For example, if the user clicks on an OK or Cancel command button, nothing happens unless you've written BASIC commands to tell your computer exactly what to do.&lt;br /&gt;&lt;br /&gt;Any time a user presses a key, moves the mouse, or clicks the mouse button, it's called an event. Whenever an event occurs, your BASIC commands tell the computer, "Hey stupid, something just happened. Let's do something about it!"&lt;br /&gt;&lt;br /&gt;Essentially, writing a Visual Basic program means drawing your user interface and then writing BASIC code to make it work. If you can handle these two steps without losing your mind, you can start writing your very own programs using Visual Basic. Chapter 4 provides a short introduction to writing real-life BASIC code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Why programs don't work (Part II)&lt;br /&gt;&lt;br /&gt;Most programs are written by professional programmers who may have studied programming for years. Does this mean that every program they write will always work? Of course not. This is the world of computers where nothing works right, remember?&lt;br /&gt;Besides the fact that the skill level among professional programmers can vary widely, professional programmers are often called upon to write programs for tasks that they don't understand themselves. For example, programmers may know nothing about accounting yet be hired to write a program to control a bank's electronic-fund-transfer system. Likewise, programmers with no skill or experience in flying may be hired to write a program to control the landing, takeoff, and flight of a 747 jumbo jet. Programmers with no knowledge of medicine may be required to write a program to control a medical instrument that administers doses of radiation to cancer patients. How can you work in a field where you have no experience and still get paid a lot of money? Easy, you become a programmer.&lt;br /&gt;&lt;br /&gt;Hiring a programmer with no knowledge of the task she's trying to solve is like hiring a translator to translate Greek into French without that person's knowing how to read or write in either language. Given this paradox in the programming world, is it any wonder that planes crash, banks lose money, and hotels can't keep our reservations straight?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 2&lt;br /&gt;&lt;br /&gt;USING THE VISUAL BASIC USER INTERFACE&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Loading Visual Basic&lt;br /&gt;Getting to know the Visual Basic user interface&lt;br /&gt;Opening, closing, and moving windows around&lt;br /&gt;Quitting Visual Basic&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Before diving into the depths of Visual Basic programming, take a deep breath and examine the program's user interface. After all, if you don't know how to use the Visual Basic user interface, you won't be able to write your own Visual Basic programs.&lt;br /&gt;&lt;br /&gt;To use Visual Basic, you need to know the following three functions:&lt;br /&gt;&lt;br /&gt;How to load Visual Basic from Windows 95/98/NT&lt;br /&gt;How to use Visual Basic to write your own programs&lt;br /&gt;How to exit out of Visual Basic&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Loading Visual Basic&lt;br /&gt;&lt;br /&gt;To load Visual Basic, just follow these simple steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Start button of the Windows 95/98/NT taskbar. A pop-up menu appears.&lt;br /&gt;&lt;br /&gt;2. Click on Programs, click on the Microsoft Visual Basic 6 folder (or the Microsoft Visual Studio folder), and then click on Microsoft Visual Basic 6.&lt;br /&gt;Visual Basic displays a New Project dialog box.&lt;br /&gt;&lt;br /&gt;To load Visual Basic quickly, create a desktop shortcut by following these steps: Right-click on the Windows desktop, click on New, click on Shortcut, click on the Browse button, search for the VB6.EXE file, click on the Next&gt; button, type Visual Basic 6, and click on the Finish button.&lt;br /&gt;&lt;br /&gt;After the New Project dialog box appears, you have two options. You can&lt;br /&gt;&lt;br /&gt;Start writing a brand new program.&lt;br /&gt;Load an existing program so you can modify it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Starting a new program&lt;br /&gt;&lt;br /&gt;After you have the New Project dialog box displayed, you have several choices as to the type of program you want to create. (The Learning and Standard Editions of Visual Basic do not display all the following types of programs in the New Project dialog box.)&lt;br /&gt;&lt;br /&gt;Standard EXE: Creates a stand-alone program that you can copy, give away, or sell to others. Examples of stand-alone programs are Microsoft Word, Lotus 1-2-3, and Netscape Navigator. Stand-alone programs have an EXE file extension.&lt;br /&gt;&lt;br /&gt;ActiveX DLL: Creates a file that has a .DLL file extension. ActiveX DLL files are not meant to be used by themselves. Instead, these types of files contain subprograms designed to function as building blocks when creating a stand-alone program.&lt;br /&gt;&lt;br /&gt;ActiveX EXE: Creates a file that has an .EXE file extension. Unlike a stand-alone EXE file, an ActiveX EXE file is designed to work as an OLE server, which is nothing more than a program designed to share information with another program.&lt;br /&gt;&lt;br /&gt;ActiveX Control: Creates a file that has an .OCX file extension. Unlike an ActiveX DLL or ActiveX EXE file, an ActiveX Control file usually provides both subprograms and a user interface that you can reuse in other programs.&lt;br /&gt;&lt;br /&gt;ActiveX Document DLL: Creates a file that has a .DLL file extension. An ActiveX Document DLL file is designed to help you run programs on a Web site.&lt;br /&gt;&lt;br /&gt;ActiveX Document EXE: Creates a file that has an .EXE file extension. An ActiveX Document EXE file can display a Visual Basic form within an Internet Web browser.&lt;br /&gt;&lt;br /&gt;AddIn: Enables you to create an addin program specially designed to work with the Visual Basic user interface.&lt;br /&gt;&lt;br /&gt;VB Application Wizard: Helps you create a skeleton Visual Basic standalone EXE program quickly and easily.&lt;br /&gt;&lt;br /&gt;Data Project: Creates a program for devising a database report, which lets you see your database information in a pretty and organized way.&lt;br /&gt;&lt;br /&gt;DHTML Application: New to Visual Basic 6, this program creates a DHTML (Dynamic HyperText Markup Language) document suitable for posting on a Web Site.&lt;br /&gt;&lt;br /&gt;IIS Application: Creates a file for use with Microsoft Internet Information Server - another new Visual Basic 6 feature.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To choose one of these options from the New Project dialog box, just click on the option you want and click on OK.&lt;br /&gt;&lt;br /&gt;If you choose File-&gt;New Project (or press Ctrl+N), Visual Basic displays a New Project dialog box that does not contain the Existing or Recent tabs.&lt;br /&gt;&lt;br /&gt;Creating ActiveX, DHTML, IIS, and Data Project files is fairly advanced, so don't worry about such files until you figure out how to create a simple (Standard EXE) Visual Basic program first.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Loading an existing program&lt;br /&gt;&lt;br /&gt;Most of the time you are goint to want to load an existing program so you can modify it. To load an existing program, click on the Existing tab. Visual Basic displays folders so you can choose the specific Visual Basic program you want to load.&lt;br /&gt;&lt;br /&gt;If you want to load a program that you've loaded in the past, click on the Recent tab. Visual Basic politely displays a list of all the programs you recently loaded. Just click on the Visual Basic program you want to edit and then click on Open.&lt;br /&gt;&lt;br /&gt;If you choose File-&gt;Open Project (or press Ctrl+O), Visual Basic displays an Open Project dialog box that does not contain the New tab.&lt;br /&gt;&lt;br /&gt;If you click on the File menu, Visual Basic kindly displays a list of programs that you last edited. By clicking on one of these program names, you can load the program without going through the Open Project dialog box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Welcome to the Visual Basic User Interface&lt;br /&gt;&lt;br /&gt;After you decide to start a new Visual Basic program or edit an existing one, the Visual Basic user interface appears in its full glory. Of course, before you can draw your program's user interface and write BASIC code, you have to know how to use the user interface of Visual Basic itself. The eight main parts of the Visual Basic user interface appear in Figure 2-2, although all parts don't necessarily have to be visible at any given time.&lt;br /&gt;&lt;br /&gt;1. Pull-down menus: Provide access to every available Visual Basic command, although these menus can be confusing and intimidating to use.&lt;br /&gt;&lt;br /&gt;2. Toolbar: Displays icons that represent the most commonly used Visual Basic commands - which may still be confusing and intimidating to use.&lt;br /&gt;&lt;br /&gt;3. Toolbox: Displays the types of objects (such as a command button or check box) that you can draw on a form. The Toolbox may not list all possible objects you can draw on a form. To get a complete list of objects you can display in your Toolbox, press Ctrl+T.&lt;br /&gt;&lt;br /&gt;4. Project explorer: Lists all the files that make up a single Visual Basic program.&lt;br /&gt;&lt;br /&gt;5. Properties window: Displays the properties of the currently selected form or object.&lt;br /&gt;&lt;br /&gt;6. Form layout window: Enables you to arrange the location where your forms appear on the screen.&lt;br /&gt;&lt;br /&gt;7. Form: Provides a window where you can draw objects to design your program's user interface.&lt;br /&gt;&lt;br /&gt;8. Immediate window: Enables you to debug your Visual Basic program.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When you're designing your user interface, you use the Toolbox to draw objects on a Form. After you draw your objects, the next step is to customize the appearance of each object by using the Properties window. Finally, after you're happy with the way your program's user interface looks, you can define the location of the interface on the screen by using the Form layout window.&lt;br /&gt;&lt;br /&gt;To see more of the Visual Basic user interface, change your screen resolution by following these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Start button on the Windows 95/98/NT taskbar.&lt;br /&gt;2. Choose Settings-&gt;Control Panel.  A Control Panel window appears.&lt;br /&gt;3. Double-click on the Display icon.  A Display Properties window appears.&lt;br /&gt;&lt;br /&gt;As an alternative to Steps 1 through 3, just point the mouse cursor anywhere on your Windows 95/98/NT desktop, click the right mouse button, and click on Properties.&lt;br /&gt;&lt;br /&gt;4. Click on the Settings tab.&lt;br /&gt;&lt;br /&gt;5. Click on the Desktop area horizontal scroll bar and drag the slider toward the right.&lt;br /&gt;The screen resolution (such as 800 x 600 pixels) appears underneath the horizontal scroll bar.&lt;br /&gt;&lt;br /&gt;6. Click on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Closing and opening windows&lt;br /&gt;&lt;br /&gt;If the Visual Basic user interface seems cluttered, don't be afraid to modify it. Because most parts of the Visual Basic user interface consist of windows, you may want to close them to give yourself more screen space. Then, when you need to use the interface windows again, just open them back up again.&lt;br /&gt;&lt;br /&gt;To close a window in the Visual Basic user interface, click on the Close box of the window you want to close.&lt;br /&gt;&lt;br /&gt;To open a window and make it appear in the Visual Basic user interface, choose View and then click on the window you want to open, such as the Code or Properties window.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Resizing and moving your windows&lt;br /&gt;&lt;br /&gt;Rather than close a window and make it disappear completely, you may prefer to resize or rearrange the window instead.&lt;br /&gt;&lt;br /&gt;To resize a window, move the cursor over the edge of the window until the cursor turns into a doubIe-headed arrow. Next, hold down the left mouse button, drag the mouse, and release the left mouse button when the window is the shape you want the window to be.&lt;br /&gt;&lt;br /&gt;To move a window, move the cursor over the title bar of a window, hold down the left mouse button. Drag the mouse and then release the left mouse button when the window is in the desired location.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Docking your windows&lt;br /&gt;&lt;br /&gt;With so many windows cluttering up the screen, you can see how easily the windows overlap one another and just get in the way. To help solve this problem, Visual Basic offers a docking feature.&lt;br /&gt;&lt;br /&gt;Docking simply means that Visual Basic neatly stacks your windows to one side of the screen. To dock (or undock) a window, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Move the mouse cursor over the title bar of the window you want to dock (or undock).&lt;br /&gt;&lt;br /&gt;2. Double-click the left mouse button.  Visual Basic automatically docks (or undocks) your chosen window.&lt;br /&gt;&lt;br /&gt;In case you don't want Visual Basic to dock (or undock) your windows at all, you can turn off the docking feature. To turn the docking feature on or off for a particular window, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose Tools-&gt;Options.  An Options dialog box appears.&lt;br /&gt;&lt;br /&gt;2. Click on the Docking tab.&lt;br /&gt;&lt;br /&gt;3. Click on a check box to place a check mark in or remove a check mark from that check box. A check mark means that the docking feature is turned on for that particular window. An empty check mark means that the docking feature is (surprise!) turned off.&lt;br /&gt;&lt;br /&gt;4. Click on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Quitting Visual Basic&lt;br /&gt;&lt;br /&gt;No matter how much you may love using Visual Basic, eventually you need to turn off the computer and go to sleep (or at least pass out on the keyboard for an hour or two). To exit Visual Basic, use one of these three methods:&lt;br /&gt;&lt;br /&gt;1. Choose File-&gt;Exit.&lt;br /&gt;2. Press Alt+Q&lt;br /&gt;3. Click on the Close box of the Visual Basic user interface window.&lt;br /&gt;&lt;br /&gt;If you haven't saved the currently displayed Visual Basic program, Visual Basic displays a dialog box, giving you one last chance to save your work before the material is gone for good. Just click on Yes to save your work (or No to lose any changes you have made since the last time you saved the file).&lt;br /&gt;&lt;br /&gt;As long as your computer hasn't crashed, Visual Basic smoothly exits and dumps you back to the Windows 95/98/NT desktop.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 3&lt;br /&gt;&lt;br /&gt;DESIGNING YOUR FIRST USER INTERFACE&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this chapter:&lt;br /&gt;&lt;br /&gt;Understanding the common parts of a user interface.&lt;br /&gt;Drawing a user interface.&lt;br /&gt;Changing the properties of your user interface.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As I discuss in Chapter 1, you must go through a number of steps in order to create a Visual Basic program from start to finish. While the earliest of these steps deal with designing and creating the user interface, this chapter focuses on the fundamental steps in writing a Visual Basic program:&lt;br /&gt;&lt;br /&gt;Drawing the user interface&lt;br /&gt;Defining the user interface properties&lt;br /&gt;Writing BASIC code&lt;br /&gt;&lt;br /&gt;So before you can write your first program in Visual Basic, you need to know how you can create a user interface.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Common Parts of a User Interface&lt;br /&gt;&lt;br /&gt;Despite the different varieties of user interfaces available, most graphical user interfaces share similar features such as displaying text or pictures in a window. A window can fill the entire screen or just part of it. Two or more windows can appear on the screen at the same time, either overlapping like cards or side by side like tiles. For some odd reason, Visual Basic calls a window a form.&lt;br /&gt;&lt;br /&gt;When you first create a form, it's entirely blank. To make your form useful, you have to draw objects on the form. An object can be a command button, a text box, a picture, or an option button. The user communicates with your program by clicking, typing, or manipulating the objects displayed on a form.&lt;br /&gt;&lt;br /&gt;By themselves, objects do absolutely nothing but look nice. To make them functional, you have to write BASIC code (Which you can read about in Chapter 4).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** A short history of user interfaces&lt;br /&gt;&lt;br /&gt;In the old days of computers (back in the '50s), using a computer meant opening up the computer and rearranging some wires. Not only did you have to know how to program a computer to use it, but you also had to know how to connect the computer's wires together without electrocuting yourself in the process.&lt;br /&gt;&lt;br /&gt;To use a computer in the '60s, you had to type commands to punch holes in cards and then feed the stack of punch cards into the computer. Because typing commands perfectly on cards wasn't something that most people considered exciting, using a computer was slow, tedious, and boring.&lt;br /&gt;&lt;br /&gt;In the 70s, scientists connected a TV set to the computer and called the whole thing a computer terminal. For the first time,you could type a command directly into the computer and the computer could respond right away. This was the first attempt at creating a user interface that people could actually use and understand.&lt;br /&gt;&lt;br /&gt;Of course, these first crude user interfaces consisted of nothing more than a blank screen and a blinking dot, called a cursor. To get the computer to do anything, you had to type the proper commands. Unfortunately, if you didn't know the right commands to type, the computer would refuse to work and make you feel stupid. Once again, using a computer became slow, tedious, and boring.&lt;br /&gt;&lt;br /&gt;In a desperate attempt to make computers simpler to use, computer programmers soon invented something called a graphical user interface or GUI (pronounced "gooey"). Basically, a GUI displays menus and icons that the user can choose by clicking on commands with the mouse.&lt;br /&gt;&lt;br /&gt;Apple Computer created the first commercial GUI when it introduced the Macintosh, but Microsoft quickly created its own GUI (dubbed Microsoft Windows). Unfortunately, GUls can still make a computer slow, tedious, and boring to use, so when this happens, blame the computer industry. This won't solve any problems, but at least you can make yourself feel better emotionally for a minute or two.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Drawing objects with Visual Basic&lt;br /&gt;&lt;br /&gt;To draw objects on a form, you need to use the Toolbox, which normally appears on the left side of the screen (unless you move it somewhere else). The Toolbox contains little drawings that represent the various objects you can draw on a form.&lt;br /&gt;&lt;br /&gt;To draw any object on a form, you always have to follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object in the Toolbox to tell Visual Basic what you want to draw on a form.&lt;br /&gt;&lt;br /&gt;2. Move the mouse pointer onto the form where you want to draw the object.&lt;br /&gt;&lt;br /&gt;3. Hold down the left mouse button and drag the mouse to draw your chosen object on the form.&lt;br /&gt;&lt;br /&gt;As a fast way to draw an object on a form, just double-click on an Icon in the Toolbox and Visual Basic draws your chosen object in the center of the form automatically.&lt;br /&gt;&lt;br /&gt;Designing your user interface is a lot like doodling. Although Part II of this book explains more about using specific objects and how they work, for now just remember two things: All programs need a user interface, and Visual Basic uses forms and objects to help you create a user interface quickly and easily.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* The two ways to create a user interface&lt;br /&gt;&lt;br /&gt;When you want to create a user interface with Visual Basic, you can either:&lt;br /&gt;&lt;br /&gt;Use the VB Application Wizard to create user interface for you automatically&lt;br /&gt;Create your own user interface from scratch&lt;br /&gt;&lt;br /&gt;So which way is better? If you need to create a Windows 95/98/NT program that offers standard File, Edit, Window, and Help pull-down menus, let Visual Basic create your user face for you automatically.&lt;br /&gt;&lt;br /&gt;However, if you re just creating a simple program that doesn't need pull-down menus, creating your own user interface all by yourself is going to be easier.&lt;br /&gt;&lt;br /&gt;Whichever way you decide to create a user interface, you can always add, delete, or modify your user interface at a later date.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Drawing your first user interface from scratch&lt;br /&gt;&lt;br /&gt;In case you don't feel like going through the following 14 steps, the enclosed CD-ROM has the HELLO1.VBP file stored in the Chapter 3 directory for you to examine and study.&lt;br /&gt;&lt;br /&gt;To get acquainted with Visual Basic right away, the following are some steps you can use to create a real-life user interface from scratch:&lt;br /&gt;&lt;br /&gt;1. In Windows 95/98/NT, start Microsoft Visual Basic if you haven't done so already. If Visual Basic is running already, then choose File-&gt;New Project.&lt;br /&gt;Visual Basic displays a New Project dialog box, asking you what type of program you want to create.&lt;br /&gt;&lt;br /&gt;2. Click on the Standard EXE Icon and click on Open.&lt;br /&gt;Visual Basic displays a blank form titled Form 1. (If you want Visual Basic to create a user interface for you automatically, click on the VB Application Wizard icon at this step, but don't click on the icon now. The end of this chapter explains how to use the VB Application Wizard.)&lt;br /&gt;&lt;br /&gt;3. Move the mouse cursor over the bottom right corner of the form (directly over the small rectangle, called a handle, that appears In the center of the right edge) so the mouse cursor turns into a left and right pointing arrow. Hold down the left mouse button and drag the mouse to make the form larger.&lt;br /&gt;&lt;br /&gt;4. Choose View-&gt;Toolbox to make the Toolbox appear on the left side of the screen.&lt;br /&gt;(Skip this step if the Toolbox is visible already.)&lt;br /&gt;&lt;br /&gt;5. Click on the Command button Icon In the Visual Basic Toolbox.&lt;br /&gt;&lt;br /&gt;6. Move the mouse over the form, then drag the mouse to draw a command button.&lt;br /&gt;&lt;br /&gt;7. Click on the Option button icon in the Toolbox and draw an option button. Repeat this process two more times to draw three option buttons.&lt;br /&gt;&lt;br /&gt;8. Click on the Image box icon and draw an image box.  Repeat this process two more times to draw three image boxes.&lt;br /&gt;&lt;br /&gt;9. Click on the Text box icon and draw a text box.  Repeat this process two more times to draw three text boxes.&lt;br /&gt;&lt;br /&gt;10. Choose File-&gt;Save Form 1 or press Ctrl+S. A Save File As dialog box appears, asking what you want to name the file. (You may want to click on the Save In list box to choose a specific folder to save your Visual Basic project and forms.)&lt;br /&gt;&lt;br /&gt;11. Type HELLO and select Save.  This action saves your form in a file called HELLO.FRM.&lt;br /&gt;&lt;br /&gt;12. Choose File-&gt;Save Project.  A Save Project As dialog box appears, asking what you want to name your project.&lt;br /&gt;&lt;br /&gt;13. Type HELLO and click on Save.  This action saves your entire Visual Basic project in a file called HELLO.VBP.&lt;br /&gt;&lt;br /&gt;14. Choose File-&gt;Exit (or press Alt+Q) if you want to exit from Visual Basic.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Congratulations! You've just created a generic Visual Basic user interface. If your user interface looks a little less than impressive, this is because you haven't customized the user interface for your program.&lt;br /&gt;&lt;br /&gt;To customize a Visual Basic user interface, you have to define the properties for each object on your forms.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Defining the Properties of Your User Interface&lt;br /&gt;&lt;br /&gt;Drawing your user interface creates the initial appearance of your Visual Basic program. To finish defining your program's user interface, you next have to define the properties for each object on your user interface.&lt;br /&gt;&lt;br /&gt;But do you really need to define these properties? Yes and no. Visual Basic automatically sets default property values for all the objects on your user interface. However, these default values make your program look pretty ugly. So if you want to make your user interface more attractive, you must define the properties for your objects.&lt;br /&gt;&lt;br /&gt;While each object typically has 10 to 30 different properties that you can change, you don't have to modify every single property. Most of the time, you just need to modify two or three properties of each object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* What properties do&lt;br /&gt;&lt;br /&gt;Before you change the properties of any object, you may want to know what the heck properties do in the first place. Essentially, properties define the characteristics of an object such as its name, size, shape, and color on the screen.&lt;br /&gt;&lt;br /&gt;The name of an object is for your convenience only. Visual Basic automatically gives all objects boring names like Text1 or Command3. However, when you need to refer to specific objects, it's much easier if you have descriptive names for each object used by your program.&lt;br /&gt;&lt;br /&gt;An object's size, location, and color define its appearance on the screen. The whole purpose of an object's appearance is to make your user interface look pretty.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing property settings&lt;br /&gt;&lt;br /&gt;You can change the property settings of an object at two separate times:&lt;br /&gt;&lt;br /&gt;During design time&lt;br /&gt;During run time&lt;br /&gt;&lt;br /&gt;Design time is when you're drawing your user interface but before you actually run your program.&lt;br /&gt;&lt;br /&gt;Most of the time, you want to change an object's property settings at design time. The most important property to change at design time is the name of the object.&lt;br /&gt;&lt;br /&gt;Run time is when your program uses BASIC code to change an object's properties while your program is actually running. Of course, before your program can change an object's properties, you have to write BASIC code that tells your program exactly which object's properties you want to change.&lt;br /&gt;&lt;br /&gt;Changing a property during run time enables you to create animation or display messages on the screen, such as error messages, program status messages, or warning messages alerting the user that the computer is going to blow up in ten seconds.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Changing property settings at design time:&lt;br /&gt;&lt;br /&gt;Several properties are assigned to every object. To change the property of an object, make sure you have a form displayed within Visual Basic and then follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object whose properties you want to change.&lt;br /&gt;&lt;br /&gt;2. In the Properties window, click on the property that you want to change. If the Properties window is not visible, press F4 to make the window appear.&lt;br /&gt;&lt;br /&gt;3. Type or choose a new setting for the property.&lt;br /&gt;&lt;br /&gt;Simple, don't you thing? When you need to change multiple properties for one or more objects, this book displays a table similar to the following:&lt;br /&gt;&lt;br /&gt;Object                 Property        Setting&lt;br /&gt;&lt;br /&gt;Form           Name            frmHello&lt;br /&gt;          Caption        Hello, world!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The following steps detail what this table is telling you to do:&lt;br /&gt;&lt;br /&gt;1. Click on the Form object.&lt;br /&gt;&lt;br /&gt;2. Click on the Name property in the Properties window.&lt;br /&gt;&lt;br /&gt;3. Type frmHello to change the value of the Name property.&lt;br /&gt;&lt;br /&gt;4. Click on the Caption property in the Properties window.&lt;br /&gt;&lt;br /&gt;5. Type Hello, world! To change the value of the Caption property.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Defining the properties of your first user interface:&lt;br /&gt;&lt;br /&gt;In case you don't feel like following the next 17 steps, the enclosed CD-ROM has the HELLO2.VBP file stored in the Chapter 3 directory for you to examine and study.&lt;br /&gt;&lt;br /&gt;To define the properties of your user interface, follow these steps:&lt;br /&gt;&lt;br /&gt;1. In Windows 95/98/NT, start Microsoft Visual Basic.&lt;br /&gt;Visual Basic displays the New Project dialog box. If Visual Basic is already running, choose File-&gt;Open Project.&lt;br /&gt;&lt;br /&gt;2. Click on the Recent tab.&lt;br /&gt;&lt;br /&gt;3. Click on the HELLO file (which is the HELLO.VBP file) and click on Open.&lt;br /&gt;Visual Basic loads your HELLO.FRM form on the screen.&lt;br /&gt;&lt;br /&gt;4. Click on Option 1 to highlight the option button, which causes little rectangles to appear around the edges of the option button.&lt;br /&gt;&lt;br /&gt;5. Click on the Properties window, click on the Name property and type optGrin. Click on the Caption property and type I'm happy!&lt;br /&gt;&lt;br /&gt;6. Click on the Image 1 image box. (This appears near the top of the form.)&lt;br /&gt;&lt;br /&gt;7. Click on the Properties window, click on the Name property and type imgGrin.&lt;br /&gt;&lt;br /&gt;8. Click on the Properties window and click on the three dots (...) in the Picture property. Visual Basic displays a Load Picture dialog box.&lt;br /&gt;&lt;br /&gt;9. Open the Icons folder. (You may have to dig through the Graphics folder in your Visual Basic folder to find the Icons folder.) Next, open the Misc folder within the Icons folder. Visual Basic displays a Load Picture dialog box.&lt;br /&gt;&lt;br /&gt;10. Double-click on the FACE03 icon.  Visual Basic displays a really happy face in the image box.&lt;br /&gt;&lt;br /&gt;11. Click on the Visible property and then click on the downward-pointing arrow and choose False.&lt;br /&gt;&lt;br /&gt;12. Click on the Text1 text box.&lt;br /&gt;&lt;br /&gt;13. Click on the Border Style property and then click on the downward-pointing arrow and choose 0-None.&lt;br /&gt;&lt;br /&gt;14. Click on the Name property and type txtGrin.&lt;br /&gt;&lt;br /&gt;15. Double-click on the Text property and then press Backspace to clear the Text property so no text appears.&lt;br /&gt;&lt;br /&gt;16. Finish changing the properties for the rest of the objects according to Table 3-1.&lt;br /&gt;&lt;br /&gt;17. Choose File-&gt;Save Project to save all your changes.&lt;br /&gt;&lt;br /&gt;Congratulations! You just defined all the necessary properties for your first user interface.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;||&lt;br /&gt;TABLE 3-1&lt;br /&gt;Properties to Change to Finish Designing Your User Interface&lt;br /&gt;&lt;br /&gt;Object - Form&lt;br /&gt;Property - Name; Caption&lt;br /&gt;Setting - frmHello; Hello, world!&lt;br /&gt;&lt;br /&gt;Object - Option 2&lt;br /&gt;Property - Name; Caption&lt;br /&gt;Setting - optSmile; I'm okay.&lt;br /&gt;&lt;br /&gt;Object - Option 3&lt;br /&gt;Propety - Name; Caption&lt;br /&gt;Setting - optFrown; I'm sad&lt;br /&gt;&lt;br /&gt;Object - Image 2&lt;br /&gt;Property - Name; Picture; Visible&lt;br /&gt;Setting - imgSmile; FACE02; False&lt;br /&gt;&lt;br /&gt;Object - Image 3&lt;br /&gt;Property - Name; Picture; Visible&lt;br /&gt;Setting - imgFrown; FACE01; False&lt;br /&gt;&lt;br /&gt;Object - Text2&lt;br /&gt;Property - Name; Border Style; Text&lt;br /&gt;Setting - txtSmile; 0-None; (Empty)&lt;br /&gt;&lt;br /&gt;Object - Text3&lt;br /&gt;Property - Name; Border Style; Text&lt;br /&gt;Setting - txtFrown; 0-None; (Empty)&lt;br /&gt;&lt;br /&gt;Object - Command1&lt;br /&gt;Property - Name; Caption&lt;br /&gt;Setting - cmdExit; Exit&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. What are the two common parts of almost every user interface?&lt;br /&gt;&lt;br /&gt;a. The easy-to-use interface and the 500page manual that explains how easy the interface is to use&lt;br /&gt;b. Menus that nobody can understand and commands that nobody can use&lt;br /&gt;c. Useless icons that don't make any sense and text that doesn't explain anything&lt;br /&gt;d. Forms and objects&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. How can you change property settings of an object?&lt;br /&gt;&lt;br /&gt;a. You can't, Property settings have to want to change first.&lt;br /&gt;b. Use constant threat and intimidation.&lt;br /&gt;c. Use the Property window while designing the user interface (known as design time) or write BASIC code to change the properties while the program is running (known as run time).&lt;br /&gt;d. Stick a magnet next to your monitor and watch the images warp and wreck your computer screen.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Letting Visual Basic Create a User Interface Automatically&lt;br /&gt;&lt;br /&gt;If you actually went through the steps to create a user interface from scratch, you can see how tedious and time-consuming this process can be. Because computers are supposed to save you time (so you have more time to play computer games), Visual Basic offers a VB Application Wizard.&lt;br /&gt;&lt;br /&gt;The VB Application Wizard creates a skeleton program complete with pulldown menus, toolbars, and dialog boxes. If you want to create a program that requires a user interface similar to Microsoft Word, Excel, or PowerPoint, you can save time by letting the VB Application Wizard make your user interface instead.&lt;br /&gt;&lt;br /&gt;To see how the VB Application Wizard works, follow these steps:&lt;br /&gt;&lt;br /&gt;1. In Windows 95/98/NT, start Microsoft Visual Basic. (If you already have Visual Basic running, choose File-&gt;New Project.)&lt;br /&gt;Visual Basic displays the New Project dialog box.&lt;br /&gt;&lt;br /&gt;2. Double-click on the VB Application Wizard icon.&lt;br /&gt;&lt;br /&gt;The Introduction window of the Application Wizard appears. This window asks for a profile to use. Profiles are skeleton settings so you can customize the VB Application Wizard. For now, just keep the profile option as (None).&lt;br /&gt;&lt;br /&gt;3. Click on Next&gt;.  The Application Wizard - Interface Type window appears&lt;br /&gt;&lt;br /&gt;4. Click on the Multiple Document Interface (MDI) option button and click on Next&gt;.&lt;br /&gt;&lt;br /&gt;The Application Wizard - Menus window appears. (If you want, click on a different option button for Step 4 to see what a Single Document Interface [SDI] and Explorer Style user interface look like.)&lt;br /&gt;&lt;br /&gt;5. Click on Next&gt; to accept the default selection.&lt;br /&gt;&lt;br /&gt;The Application Wizard - Customize Toolbar window appears.  By dragging and dropping icons, you can create your own toolbars.&lt;br /&gt;&lt;br /&gt;6. Click on Next&gt; to accept the default selection.&lt;br /&gt;&lt;br /&gt;The Application Wizard - Resources window appears. Resource files can help you develop foreign language versions of your program. Rather than force you to retype your program's text (such as manus and dialog box captions) in different languages, a resource file stores the information in a separate file so you can just use a different resource file for each foreign language.&lt;br /&gt;&lt;br /&gt;7. Click on Next&gt; to accetp the default selection.&lt;br /&gt;&lt;br /&gt;The Application Wizard - Internet Connectivity window appears. This is where you can specify whether you want your program to be able to access the Internet.&lt;br /&gt;&lt;br /&gt;8. Click on Next&gt; to accept the default selection.  The Application Wizard - Standard Forms window appears.&lt;br /&gt;&lt;br /&gt;9. Click on the About Box check box and then click on Next&gt;.&lt;br /&gt;&lt;br /&gt;The Application Wizard - Data Access Forms window appears. This is where you can specify what type of database files you want your program to use.&lt;br /&gt;&lt;br /&gt;10. Click on Next&gt; to accept the default selection.  The Application Wizard - Finished! Window appears.&lt;br /&gt;&lt;br /&gt;11. Click on the Finish button.  Visual Basic displays an Application Created dialog box.&lt;br /&gt;&lt;br /&gt;12. Click on OK.&lt;br /&gt;&lt;br /&gt;13. Press F5 to run the skeleton program that the VB Application Wizard created for you.  The program appears.&lt;br /&gt;&lt;br /&gt;14. Choose Help-&gt;About.  An About Project1 dialog box appears.&lt;br /&gt;&lt;br /&gt;15. Click on OK.&lt;br /&gt;&lt;br /&gt;16. Click on any icon on the toolbar or on any of the pull-down menus to see what happens.&lt;br /&gt;&lt;br /&gt;17. Choose File-&gt;Exit when you're done playing around with this skeleton program.&lt;br /&gt;&lt;br /&gt;18. Choose File-&gt;New Project.  A dialog box appears, asking if you want to save your newly created user interface.&lt;br /&gt;&lt;br /&gt;19. Click on No.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As you can see, the VB Application Wizard can quickly create a user interface that includes pull-down menus and a toolbar. However, you still need to customize the user interface and write BASIC code to make the program do anything worthwhile. The VB Application Wizard simply gives you a head start in creating your user interface.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 4&lt;br /&gt;&lt;br /&gt;WRITING BASIC CODE&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Discovering the basics about BASIC code&lt;br /&gt;Choosing an object and writing a procedure&lt;br /&gt;Writing BASIC code for your program&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To have your computer do anything, you have to give it step-by-step instructions. If you skip a step or give unclear instructions, your computer doesn't know what to do. (Actually, the computer knows what to do - it just doesn't do what you want it to.)&lt;br /&gt;&lt;br /&gt;Programmers call a single instruction a command. A typical BASIC command looks like the following:&lt;br /&gt;&lt;br /&gt;Taxes = Income * FlatTaxRate&lt;br /&gt;&lt;br /&gt;You call a series of commands code. A typical series of commands looks like this:&lt;br /&gt;&lt;br /&gt;Income = 90000&lt;br /&gt;FlatTaxRate = .95&lt;br /&gt;Taxes = Income * FlatTaxRate&lt;br /&gt;&lt;br /&gt;A collection of code that makes your computer do something useful (such as play a game, calculate your taxes, or display flying toasters on your screen) is called a program.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want to speak the language of programmers (even though programmers are notorious for never saying much of anything), you have to know programming etiquette.&lt;br /&gt;&lt;br /&gt;You never write a program; you write code. Heaven forbid if you say, "Let me look at your series of commands." Cool programmers are likely to blush at your faux pas. Instead, you ought to say, "Let me look at your code."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** What Is BASIC Code?&lt;br /&gt;&lt;br /&gt;To get your computer to do anything, you have to give the machine instructions that it can understand. Because you're using Visual Basic, you have to use the BASIC programming language.&lt;br /&gt;&lt;br /&gt;Like all computer languages, BASIC has special commands called reserved keywords. Some examples of reserved keywords are as follows:&lt;br /&gt;&lt;br /&gt;Loop           Function     Sub          End&lt;br /&gt;Do         Integer         Case          If&lt;br /&gt;Else         Select         Then          For&lt;br /&gt;&lt;br /&gt;BASIC code consists of nothing more than BASIC reserved keywords creatively strung together to form a program. Whenever the computer sees a reserved keyword, the computer automatically thinks, "Oh, this is a special instruction that I already know how to obey."&lt;br /&gt;&lt;br /&gt;A program can be as short as a single reserved keyword or as long as several million reserved keywords. Short programs generally don't do anything more interesting than display something such as Hello, world! on the screen. Long programs usually do much more, but these programs are often as confusing to read as an IRS tax form.&lt;br /&gt;&lt;br /&gt;Theoretically, you can write one long program consisting of a million or more reserved keywords. However, any programmer attempting to do so is likely to go insane long before completing the task.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Writing a program one step at a time&lt;br /&gt;&lt;br /&gt;To make programming easier, most programmers divide a large program into several smaller ones. After you finish writing each of the smaller programs, you paste the pieces together to make a complete program.&lt;br /&gt;&lt;br /&gt;When you divide a large program into several smaller ones, these smaller programs are subprograms. In Visual Basic lingo, subprograms are event procedures (although some programmers may call them subroutines). Visual Basic also has special subprograms called functions, which you can read about in Chapter 29, and general procedures, which you can read about in Chapter 27.&lt;br /&gt;&lt;br /&gt;Procedures tell each object on your form how to react to something that the user does. Each object can have zero or more procedures that tell the object how to respond to the user.&lt;br /&gt;&lt;br /&gt;One event procedure may tell the computer what to do if the user clicks on an object (such as a command button) with the mouse. Another event procedure may tell the computer what to do if the user presses a certain key while the object is highlighted.&lt;br /&gt;&lt;br /&gt;Not every object needs event procedures. The only objects that need event procedures are those that the user can click on or choose in some way, such as command buttons, check boxes, or radio buttons.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Choosing objects and Events&lt;br /&gt;&lt;br /&gt;Before you can write an event procedure for an object, you have to tell Visual Basic:&lt;br /&gt;&lt;br /&gt;The name of the object to use&lt;br /&gt;The event you want the object to respond to&lt;br /&gt;&lt;br /&gt;Visual Basic gives you two ways to choose an object:&lt;br /&gt;&lt;br /&gt;The simplest way is to click on an object (such as a command button) on your form and press F7 (or just double-click on the object in the first place) to switch to the Code window. Visual Basic then kindly displays the most likely procedure that you need for that object.&lt;br /&gt;&lt;br /&gt;The second way is almost as easy. Each time you draw an object on a form, Visual Basic stores the name of that object in a list called the Object list. The Object list appears at the top of the Code window. To open this list, press F7. Next, scroll through the Object list until you find the object for which you want to write a procedure.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To choose an event to use, click on the Procedure list, which also appears at the top of the Code window next to the Object list. The Procedure list contains all possible events that you can write a procedure to respond to.&lt;br /&gt;&lt;br /&gt;Just scroll through this list until you find the event for which you need to write a procedure. The most common event to use is the Click event.&lt;br /&gt;&lt;br /&gt;After you choose an object from the Object list and an event from the Procedure list, Visual Basic displays the first and last lines of the procedure. You're now ready to start writing code for this procedure.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Writing Visual Basic Event Procedures&lt;br /&gt;&lt;br /&gt;Before you can write a Visual Basic event procedure for an object, you have to draw the object on a form first.&lt;br /&gt;&lt;br /&gt;Next, you have to change the properties of each object to give them unique names you can remember. If you don't do this, you're stuck with the generic names that Visual Basic provides by default for everything, such as Option1 or Text3.&lt;br /&gt;&lt;br /&gt;Do you know what happens if you write an event procedure for a particular object and then later change that object's name? Visual Basic gets confused and thinks that you've created a brand-new object, which means that the renamed object won't have any event procedures attached to it. So if you're going to rename an object, do this renaming before you write any event procedures for that object.&lt;br /&gt;&lt;br /&gt;To write a Visual Basic event procedure, click on the object that you want to write an event procedure for and then open the Code window. (To open the Code window, press F7, choose View-&gt;Code, or double-click on the object.) After the Code window appears, you can start typing your procedure or code.&lt;br /&gt;&lt;br /&gt;But wait! Visual Basic doesn't just display a blank window. Visual Basic automatically types Private Sub, which is followed by the object's name, an underscore, an event (such as Click), and a set of parentheses ( ) that may be empty or that may contain stuff inside of it. (You can find out more about the stuff inside of parentheses in Chapter 28).&lt;br /&gt;&lt;br /&gt;If you click on an object named cmdExit and then open the Code window, Visual Basic displays the following:&lt;br /&gt;&lt;br /&gt;Private Sub cmdExit_Click( )&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The first line of this Visual Basic procedure begins with Private Sub, which is short for a subprogram that belongs exclusively to a specific object. In this case, the subprogram belongs to the object named cmdExit.&lt;br /&gt;&lt;br /&gt;Next, Visual Basic types your object's name. If you forgot to change the name property of your object, Visual Basic uses a default name such as Text2. Otherwise, Visual Basic displays your object's name (for example, cmdExit).&lt;br /&gt;&lt;br /&gt;Following your object's name is an underscore, which separates your object's name from its event. An event is something the user does to communicate with the computer. In this example, the event is Click, which means that the user clicked the mouse on the object named cmdExit.&lt;br /&gt;&lt;br /&gt;Next comes an empty set of parentheses. Sometimes, the parentheses contain data that the subprogram uses from the routine that called this subroutine. An empty pair of parentheses says that this subprogram does not need any special data passed to it from another part of your program.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Translating this procedure into English, the first line means, "This is a subprogram for the object named cmdExit, and the subprogram tells the computer what to do if the user clicks on the cmdExit object."&lt;br /&gt;&lt;br /&gt;The last line of this Visual Basic event procedure consists of two words: End and Sub. This line tells the computer, "This is the end of all the commands that belong in this subprogram." Rather than type all that, Visual Basic uses the simpler&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Right now, this Visual Basic procedure does nothing. To make the procedure do something, you have to add commands between the first line and the last line. Before you start adding commands, you need to know what BASIC commands (also known as code) can do.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. What are reserved keywords?&lt;br /&gt;&lt;br /&gt;a. Words you say when you have a reservation in a fancy restaurant where water costs $25 a glass.&lt;br /&gt;b. What shy people want to say.&lt;br /&gt;c. Special instructions that every programming language has.&lt;br /&gt;d. Words that you waritto sayto the face of someone you don't like.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. How can you write a large program without losing your mind?&lt;br /&gt;&lt;br /&gt;a. Divide the program into subprograms, otherwise known in Visual Basic as procedures (such as event or general procedures).&lt;br /&gt;b. Watch others write the program and then steal their homework.&lt;br /&gt;c. You mean I actually have to write a program?&lt;br /&gt;d. If you're thinking of writing a large program, you've probably already lost your mind.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* What can BASIC code do?&lt;br /&gt;&lt;br /&gt;BASIC code is generally used to do the following:&lt;br /&gt;&lt;br /&gt;Calculate a result&lt;br /&gt;Modify the properties (appearance) of another object&lt;br /&gt;&lt;br /&gt;If you want to calculate the number of people who live in wooden cabins, subscribe to Soldier of Fortune, and own cats, Visual Basic can calculate this as long as you provide all the necessary data.&lt;br /&gt;&lt;br /&gt;After you calculate a result, you probably want to show the result on the screen. To do so, you have to modify the properties of an object on your user interface. For example, if you want to display a message on the screen, you first need to draw a text box object on a Visual Basic form.&lt;br /&gt;&lt;br /&gt;You then have to name this text box with something such as txtMessage. Finally, to display anything in this text box, you have to modify the Text property of the txtMessage text box, such as:&lt;br /&gt;&lt;br /&gt;txtMessage.Text = "This is hard to explain."&lt;br /&gt;&lt;br /&gt;This command displays the message "This is hard to explain" in the txtMessage text box on the screen.&lt;br /&gt;&lt;br /&gt;Of course, Visual Basic code can't change all the properties of an object. You can only change some properties (such as the object's name) during design time by using that object's property window.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* How a Visual Basic event procedure works&lt;br /&gt;&lt;br /&gt;In Visual Basic, the instructions in an event procedure run only when a specific event occurs, such as when the user clicks on an object. The same set of instructions can run over and over again each time the user clicks on an object. The only time a Visual Basic program ends is when an object's procedures specifically tell the program to end.&lt;br /&gt;&lt;br /&gt;As an example, look at the simplest Visual Basic procedure that is necessary for every program to stop completely. For a simple "Hello, world!" program, this procedure looks like the following:&lt;br /&gt;&lt;br /&gt;Private Sub cmdExit_Click( )&lt;br /&gt; Unload Me&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The code in this procedure contains a Visual Basic reserved keyword called Unload and a variable called Me. The Me variable represents the form, so this procedure tells Visual Basic, "Unload the currently displayed form from memory." Because this program only consists of one form, this command effectively stops the program from running.&lt;br /&gt;&lt;br /&gt;This procedure runs only when the user clicks on the cmdExit object. If you look at the cmdExit object on your user interface, you see that the object is a command button labeled Exit.&lt;br /&gt;&lt;br /&gt;As an alternative to using the command Unload Me to end aVisual Basic program, you can also use the command End instead, like in the following:&lt;br /&gt;&lt;br /&gt;Private Sub cmdExit_Click( )&lt;br /&gt;  End&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;So which method should you use? The End command forces your program to stop running immediately, which can be like stopping your car by crashing it into a wall. For a gentler, kinder approach to stopping your program, Microsoft wholeheartedly recommends that you use the Unload Me command instead.&lt;br /&gt;&lt;br /&gt;If you run this program, the following is what happens:&lt;br /&gt;&lt;br /&gt;1. Visual Basic displays your user interface on the screen, including a command button named cmdExit. This name does not appear on the user interface. Instead, the command button's Caption property appears, which is the word Exit.&lt;br /&gt;&lt;br /&gt;2. Clicking on the Exit button causes Visual Basic to ask, "Hey, what's the name of this object on which the user just clicked?"&lt;br /&gt;&lt;br /&gt;3. In a huff, Visual Basic quickly notices that the Exit button's name is cmdExit.&lt;br /&gt;&lt;br /&gt;4. Then Visual Basic asks, "Are there any instructions here that tell me what to do if the user clicks on the cmdExit object?" Happily, Visual Basic finds the Private Sub cmdExit_Click ( ) procedure.&lt;br /&gt;&lt;br /&gt;5. Visual Basic then examines the first instruction of the cmdExit_Click ( ) procedure. In this case, the instruction is Unload&lt;br /&gt;Me, which tells Visual Basic to unload the form. Because this is the only form in the program, this effectively stops the program.&lt;br /&gt;&lt;br /&gt;6. Visual Basic stops running the program and removes it from the screen. Naturally, all this happens in the blink of an eye, and your computer looks as though it's responding instantly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Writing BASIC Code for your First Visual Basic Program&lt;br /&gt;&lt;br /&gt;For those who just like jumping right into the program without typing all the BASIC code, load the HELLO.VBP program from the enclosed CD-ROM in the back of the book.&lt;br /&gt;&lt;br /&gt;Because experience is always the best teacher, the following steps show you how to write real-life BASIC code that you can use to impress your friends. You can find out how to write BASIC code for the HELLO.VBP program in Chapter 3.&lt;br /&gt;&lt;br /&gt;Don't worry about understanding everything you're typing. The purpose of this exercise is just to show you how simple creating a program in Visual Basic can be.&lt;br /&gt;&lt;br /&gt;1. Start Microsoft Visual Basic if you haven't already done so. (Or choose File-&gt;Open Project.)&lt;br /&gt;&lt;br /&gt;Visual Basic displays a New Project or Open Project dialog box.&lt;br /&gt;&lt;br /&gt;2. Click on the Recent tab, click on HELLO, and click on Open.&lt;br /&gt;&lt;br /&gt;If the HELLO.FRM form does not appear on the screen, click on the frmHello form in the Project Explorer window and click on the View Object icon. (You can skip this step if you already have the form displayed on the screen from Chapter 3)&lt;br /&gt;&lt;br /&gt;3. Click on the optGrin option button displayed in the upper-left corner of the form. (This is the button that says "I'm happy!")&lt;br /&gt;&lt;br /&gt;4. To Open the Code window, press F7 or choose View-&gt;Code.&lt;br /&gt;&lt;br /&gt;5. Type in the Private Sub optGrin_Click( ) procedure so that it looks like the following:&lt;br /&gt;&lt;br /&gt;Private Sub optGrin_Click( )&lt;br /&gt; imgFrown.Visible = False&lt;br /&gt; imgSmile.Visible = False&lt;br /&gt; imgGrin.Visible = True&lt;br /&gt; txtSmile.TEXT = ""&lt;br /&gt; txtGrin.TEXT = "I'm going,to Disney World!"&lt;br /&gt; txtFrown.TEXT = ""&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;6. Click on the downward-headed arrow in the Object list box at the top of the Code window and then choose the optSmile object.&lt;br /&gt;&lt;br /&gt;Visual Basic displays an empty Private Sub optSmile_Click() procedure.&lt;br /&gt;&lt;br /&gt;7. Type in the Private Sub optSmile_Click( )procedure so that it looks like the following:&lt;br /&gt;&lt;br /&gt;Private Sub optSmile_Click( )&lt;br /&gt;  imgFrown.Visible = False&lt;br /&gt;  imgSmile.Visible = True&lt;br /&gt;  imgGrin.Visible = False&lt;br /&gt;  txtSmile.TEXT = "Hello, world!'&lt;br /&gt;  txtGrin.TEXT = ""&lt;br /&gt;  txtFrown.TEXT = ""&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;8. Click on the downward-pointing arrow in the Object list box at the top of the Code window and then choose the optFrown object.&lt;br /&gt;&lt;br /&gt;Visual Basic displays an empty Private Sub optFrown_Click( ) procedure.&lt;br /&gt;&lt;br /&gt;9. Type in the Private Sub optFrown_Click( ) procedure so that It looks like the following:&lt;br /&gt;&lt;br /&gt;Private Sub optFrown_Click( )&lt;br /&gt;  imgFrown.Visible = True&lt;br /&gt;  imgSmile.Visible = False&lt;br /&gt;  imgGrin.Visible = False&lt;br /&gt;  txtSmile.TEXT = ""&lt;br /&gt;  txtGrin.TEXT = ""&lt;br /&gt;  txtFrown.TEXT = "Good-bye, cruel world."&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;10. Click on the Object list at the top of the Code window and then choose the cmdExit object.&lt;br /&gt;&lt;br /&gt;Visual Basic displays an empty Private Sub cmdExit_Click( ) procedure.&lt;br /&gt;&lt;br /&gt;11. Type in the Private Sub cmdExit_Click( )procedure so that it looks like the following:&lt;br /&gt;&lt;br /&gt;Private Sub cmdExit_Click( )&lt;br /&gt;  Unload Me&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;12. Press F5 to run your program or choose Run-&gt;Start.&lt;br /&gt;&lt;br /&gt;If you typed everything correctly, Visual Basic displays your user interface on the screen.&lt;br /&gt;&lt;br /&gt;13. Click on the option button next to the label "I'm sad."&lt;br /&gt;&lt;br /&gt;Visual Basic displays a face on the screen, along with the message Good-bye, cruel world.&lt;br /&gt;&lt;br /&gt;14. Click on the option button next to the label "I'm okay."&lt;br /&gt;&lt;br /&gt;Visual Basic displays a smiley face on the screen, along with the message Hello, world!.&lt;br /&gt;&lt;br /&gt;15. Click on the option button next to the label "I'm happy!"&lt;br /&gt;&lt;br /&gt;Visual Basic displays a really happy face on the screen, along with the message - I'm going to Disney World!.&lt;br /&gt;&lt;br /&gt;16. Click on the Command button labeled Exit.&lt;br /&gt;&lt;br /&gt;Visual Basic quits running your program and returns you to Visual Basic.&lt;br /&gt;&lt;br /&gt;You finally completed the Hello, World! Example. Now, you can see how you can use Visual Basic to create a friendly user interface quickly and easily&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ PART II&lt;br /&gt;&lt;br /&gt;CREATING USER INTERFACES&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this part ..........&lt;br /&gt;&lt;br /&gt;A user interface allows other people to use your program. The clumsier the user interface, the harder your program is to use. So if you make your user interface simple and logical, you can bet that more people will be able to use your program.&lt;br /&gt;&lt;br /&gt;This is the fun part of the book. You aren't forced to type any bizarre code, comprehend arcane commands, or memorize ridiculous keystrokes. In this part of the book, you get to doodle on your computer screen while actually finding out how to write your own programs at the same time.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 5&lt;br /&gt;&lt;br /&gt;USER INTERFACE DESIGN 101&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this chapter .......&lt;br /&gt;&lt;br /&gt;Detailing tips for creating a user interface&lt;br /&gt;Drawing objects on the user interface&lt;br /&gt;Moving, deleting, and copying objects&lt;br /&gt;Making objects unavailable&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To make oneself understood to the people, one must first speak to their eyes.&lt;br /&gt;Napoleon Bonaparte&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First of all, nobody really wants to use your program. Most people would rather play at the beach, watch TV, or make out. However, people do want the results that your program can produce. If they could get these same results by other means with less work, they would. But because they can't, they're willing to use your program.&lt;br /&gt;&lt;br /&gt;This means that people really want your program to read their minds and then magically do all their work for them automatically. Because that's not possible, the best you can hope for is to make your program as easy to use as possible. If a completely incompetent moron (your boss) can use your program, then most other people are going to be able to use your program as well.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Before You Create Your User Interface&lt;br /&gt;&lt;br /&gt;Creating a user interface doesn't mean just slapping together some pretty pictures in a colorful window and hoping that the user can figure out how your program works. Your program's user interface must make your program easy to use. To help you create a user interface, here are some points to keep in mind.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Know your user&lt;br /&gt;&lt;br /&gt;Before designing your user interface, ask yourself who is going to use your program. Are your typical users data-entry clerks who understand computers, or managers who understand only paper procedures and are learning to use a computer for the first time?&lt;br /&gt;&lt;br /&gt;When you decide who your users are, design your user interface so that it mirrors the way the users already work, regardless of whether the user interface seems totally inefficient or alien to anyone else. Accountants readily accept spreadsheets because the row-and-column format mimics green sheets of ledger paper. Likewise, typists prefer word processors because a word processor mimics a blank sheet of paper.&lt;br /&gt;&lt;br /&gt;But imagine if all word processors looked like spreadsheets with rows and columns. Any typist trying to use this kind of word processor would quickly feel lost and confused (although accountants may feel right at home with such a word processor).&lt;br /&gt;&lt;br /&gt;The more a programmer understands the user, the more likely the interface is going to be used and accepted. The only person the user interface really has to satisfy is the user.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Orient the user&lt;br /&gt;&lt;br /&gt;Not surprisingly, people get lost wandering through today's supermalls, which contain multiple levels and two different time zones. How do you feel when you have no idea where you are and no idea where you can go from your current position?&lt;br /&gt;&lt;br /&gt;This feeling of helplessness is the reason why lost kids cry uncontrollably and confused computer users curse under their breath. (This is also the reason why malls install directories with the big red X that says, "You are here.")&lt;br /&gt;&lt;br /&gt;A good user interface must orient people so that they know where they are in your program and how to get out if they want. Some user interfaces display a message at the bottom of the screen, such as "Page 2 of 5." In this case, the user knows exactly how many pages are available for viewing and which page currently appears on the screen.&lt;br /&gt;&lt;br /&gt;Your user interface is a map to your program. Make sure that your user interface shows just enough information to orient users but not too much to confuse them.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Make the choices obvious&lt;br /&gt;&lt;br /&gt;In addition to letting users know where they are in a program, a good user interface must also make all choices obvious to the user. If your user interface displays "Page 4 of 25" at the bottom of the screen, how can the user know what to do to see the next or previous page? One solution may be to show forward- and backward-pointing arrows in each bottom corner of the page. Another solution may be Next Page and Previous Page buttons.&lt;br /&gt;&lt;br /&gt;As long as your program shows the user which options are available next and which keys to press or where to click the mouse, the user feels a sense of control and confidence when using your program.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Be forgiving&lt;br /&gt;&lt;br /&gt;The key here is useful feedback. If your program takes an arrogant attitude and displays scolding messages like "File MPR.DLL missing" whenever the user presses the wrong key or clicks the mouse in the wrong area, the user may feel intimidated if your program doesn't explain what the error message means and how he or she can avoid the error in the first place.&lt;br /&gt;&lt;br /&gt;So be kind. Have your program hide or dim any buttons or menu commands that are unavailable to the user. If the user does press the wrong key or click the mouse in the wrong area, have your program display a window and explain what the user's options are. Users love a program that guides them, which means you can spend a lot less time answering phone calls for technical support.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Keep it simple&lt;br /&gt;&lt;br /&gt;Most programs offer users two or more ways to choose a specific command. You can click on a button, choose a command from menus, or press certain keystroke combinations (Ctrl+F2, for example). Of these three methods, clicking directly on the screen is the easiest procedure to remember and pressing bizarre keystroke combinations is the hardest.&lt;br /&gt;&lt;br /&gt;Make sure that commonly used commands can be accessed quickly through a button or a menu. Not all commands must be or need to be accessed through a keystroke combination.&lt;br /&gt;&lt;br /&gt;Although keystroke combination commands are faster to use, these commands are harder to learn initially. Make keystroke combinations easy to remember whenever possible. For a Save command, Ctrl+S is easier to remember than something totally abstract like Shift+F12. People can easily remember that S stands for Save, but who has any idea what F12 represents?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Designing Your Visual Basic User Interface&lt;br /&gt;&lt;br /&gt;When you write a Visual Basic program, you first have to design the user interface. Essentially, a Visual Basic user interface consists of objects that you place on the screen and arrange in some semblance of organization so that the screen looks pretty.&lt;br /&gt;&lt;br /&gt;The common elements of a Visual Basic user interface consist of the following:&lt;br /&gt;&lt;br /&gt;Forms (also known as windows)&lt;br /&gt;Buttons (such as command buttons and radio buttons)&lt;br /&gt;Boxes (such as text boxes and check boxes)&lt;br /&gt;Labels&lt;br /&gt;Pictures (such as icons and graphics)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To design your user interface, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Create a form.&lt;br /&gt;2. Choose the object you want to draw from the Toolbox. (See Table 5-1.)&lt;br /&gt;3. Draw the object on the form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* TABLE 5-1&lt;br /&gt;Tools in the Visual Basic Toolbox&lt;br /&gt;&lt;br /&gt;Tool Name - Pointer&lt;br /&gt;What this Tool Does - Selects objects&lt;br /&gt;&lt;br /&gt;Tool Name - Picture box&lt;br /&gt;What this Tool Does - Draws a box to display graphics&lt;br /&gt;&lt;br /&gt;Tool Name - Label&lt;br /&gt;What this Tool Does - Drawa a box to display text&lt;br /&gt;&lt;br /&gt;Tool Name - Text box&lt;br /&gt;What this Tool Does - Draws a box that can display text and let the user type in text&lt;br /&gt;&lt;br /&gt;Tool Name - Frame&lt;br /&gt;What this Tool Does - Groups two or more objects together&lt;br /&gt;&lt;br /&gt;Tool Name - Command button&lt;br /&gt;What this Tool Does - Draws a command button&lt;br /&gt;&lt;br /&gt;Tool Name - Check box&lt;br /&gt;What this Tool Does - Draws a check box&lt;br /&gt;&lt;br /&gt;Tool Name - Option (or radio) button&lt;br /&gt;What this Tool Does - Draws a radio button&lt;br /&gt;&lt;br /&gt;Tool Name - Combo box&lt;br /&gt;What this Tool Does - Draws a combo box&lt;br /&gt;&lt;br /&gt;Tool Name - List box&lt;br /&gt;What this Tool Does - Draws a list box&lt;br /&gt;&lt;br /&gt;Tool Name - Horizontal scroll bar&lt;br /&gt;What this Tool Does - Draws a horizontal scroll bar&lt;br /&gt;&lt;br /&gt;Tool Name - Vertical scroll bar&lt;br /&gt;What this Tool Does - Draws a vertical scroll bar&lt;br /&gt;&lt;br /&gt;Tool Name - Timer&lt;br /&gt;What this Tool Does - Places a timer on a form&lt;br /&gt;&lt;br /&gt;Tool Name - Drive list box&lt;br /&gt;What this Tool Does - Draws a drive list box that displays all the disk drives available&lt;br /&gt;&lt;br /&gt;Tool Name - Directory list box&lt;br /&gt;What this Tool Does - Draws a directory list box that displays a directory on a particular disk drive&lt;br /&gt;&lt;br /&gt;Tool Name - File list box&lt;br /&gt;What this Tool Does - Draws a file list box that displays files in a specific directory&lt;br /&gt;&lt;br /&gt;Tool Name - Shape&lt;br /&gt;What this Tool Does - Draws a geometric shape such as a circle or a square&lt;br /&gt;&lt;br /&gt;Tool Name - Line&lt;br /&gt;What this Tool Does - Draws a line&lt;br /&gt;&lt;br /&gt;Tool Name - Image box&lt;br /&gt;What this Tool Does - Draws a box to display graphics&lt;br /&gt;&lt;br /&gt;Tool Name - Data control&lt;br /&gt;What this Tool Does - Draws a control to link a program to a database file&lt;br /&gt;&lt;br /&gt;Tool Name - OLE&lt;br /&gt;What this Tool Does - Draws a box to insert an OLE object&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Drawing an object&lt;br /&gt;&lt;br /&gt;To draw any object, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the icon in the Visual Basic Toolbox that represents the object you wan to draw (command button, picture box, label, and so on).&lt;br /&gt;&lt;br /&gt;2. Move the mouse to the place on the form where you want to draw the object.&lt;br /&gt;The cursor turns into a crosshair shape.&lt;br /&gt;&lt;br /&gt;3. Click and drag the mouse to where you want to draw your object and then release the mouse button.&lt;br /&gt;&lt;br /&gt;If you want to draw an object on a form in a hurry, double-click on the object's Icon in the Toolbox. For example, if you want to draw a command button quickly, just double-click on the command button icon in the Toolbox, and Visual Basic draws the command button for you automatically.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Using the Properties Window&lt;br /&gt;&lt;br /&gt;After you draw an object on a form, the next step is to define the properties for that object. To define an object's properties, you have to use the Properties window. In case the Properties window doesn't appear on your screen, you can make the window appear by using one of the following three commands:&lt;br /&gt;&lt;br /&gt;Press F4.&lt;br /&gt;Choose View -&gt;Properties Window.&lt;br /&gt;Click on the Properties Window Icon in the toolbar.&lt;br /&gt;&lt;br /&gt;The Properties window can display properties in two ways:&lt;br /&gt;&lt;br /&gt;Alphabetical: Lists an object's properties alphabetically from A to Z.&lt;br /&gt;Categorized: Organizes properties into categories, such as properties that affect an object's appearance, behavlor, or position on the screen.&lt;br /&gt;&lt;br /&gt;After you open the Properties window, follow these steps to view the properties of any object in your Visual Basic program:&lt;br /&gt;&lt;br /&gt;1. Choose one of these methods to open the Project Explorer window.&lt;br /&gt;&lt;br /&gt;Press Ctrl+R.&lt;br /&gt;Choose View-&gt;Project Explorer.&lt;br /&gt;Click on the Project Explorer icon in the toolbar.&lt;br /&gt;&lt;br /&gt;2. Click on a form name in the Project Explorer window that contains the object whose properties you want to examine and then click on the View Object lcon.&lt;br /&gt;&lt;br /&gt;3. Click on the downward-pointing arrow of the Object list box in the Properties window and choose the object whose properties you want to examine.&lt;br /&gt;&lt;br /&gt;4. Double-click on the property name that you want to change.&lt;br /&gt;&lt;br /&gt;If you click on an object displayed on a form, the Properties window automatically displays all the properties for that object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Naming objects&lt;br /&gt;&lt;br /&gt;Every object you draw has a Name property, which Visual Basic uses to identify the object. (That's the same reason your parents gave you a name - so people don't say, "Hey, you!" all the time to get your attention.) If you click on the Alphabetic tab in the Properties window, the Name property appears as (Name) at the top of the list.&lt;br /&gt;&lt;br /&gt;Every Visual Basic object must have a unique name. If you try to give the same name to two different objects, Visual Basic complains and refuses to let you make such a horrid mistake.&lt;br /&gt;&lt;br /&gt;When you create an object, Visual Basic automatically gives your object a boring, generic name. For example, the first time you create a command button, Visual Basic names the button Command1. The second time you create a command button, Visual Basic names this new button Command2, and so on.&lt;br /&gt;&lt;br /&gt;The name of an object never appears on the screen. Names can be up to 40 characters long, but they cannot contain punctuation marks or spaces. You can name your objects anything you want, but Microsoft recommends that Visual Basic programmers all over the world use Visual Basic three-letter prefixes, as shown in Table 5-2. If everyone in the world uses these prefixes, it makes modifying another person's Visual Basic program easier to read.&lt;br /&gt;&lt;br /&gt;To change the name of an object, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object that you want to name.&lt;br /&gt;&lt;br /&gt;Handles appear around the object. (To name a form, click anywhere on the form, but do not click on any objects on the form.)&lt;br /&gt;&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;&lt;br /&gt;To do so, press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar.&lt;br /&gt;&lt;br /&gt;3. Double-click on (Name) and type a new name.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* TABLE 5-2&lt;br /&gt;SUGGESTED PREFIXES WHEN NAMING OBJECTS&lt;br /&gt;&lt;br /&gt;Object - Check box&lt;br /&gt;Suggested Prefix - chk&lt;br /&gt;Example Name - chkYourZipper&lt;br /&gt;&lt;br /&gt;Object - Combo box&lt;br /&gt;Suggested Prefix - cbo&lt;br /&gt;Example Name - cboBLT&lt;br /&gt;&lt;br /&gt;Object - Command button&lt;br /&gt;Suggested Prefix - cmd&lt;br /&gt;Example Name - cmdOpenSesame&lt;br /&gt;&lt;br /&gt;Object - Data&lt;br /&gt;Suggested Prefix - dat&lt;br /&gt;Example Name - datFanOverThere&lt;br /&gt;&lt;br /&gt;Object - Directory list box&lt;br /&gt;Suggested Prefix - dir&lt;br /&gt;Example Name - dirTree&lt;br /&gt;&lt;br /&gt;Object - Drive list box&lt;br /&gt;Suggested Prefix - drv&lt;br /&gt;Example Name - drbLikeMad&lt;br /&gt;&lt;br /&gt;Object - File list box&lt;br /&gt;Suggested Prefix - fil&lt;br /&gt;Example Name - filDocuments&lt;br /&gt;&lt;br /&gt;Object - Form&lt;br /&gt;Suggested Prefix - frm&lt;br /&gt;Example Name - frm1040Tax&lt;br /&gt;&lt;br /&gt;Object - Frame&lt;br /&gt;Suggested Prefix - fra&lt;br /&gt;Example Name - fraGroupedButtons&lt;br /&gt;&lt;br /&gt;Object - Horizontal scroll bar&lt;br /&gt;Suggested Prefix - hsb&lt;br /&gt;Example Name - hsbTemperature&lt;br /&gt;&lt;br /&gt;Object - Image&lt;br /&gt;Suggested Prefix - img&lt;br /&gt;Example Name - imgPeace&lt;br /&gt;&lt;br /&gt;Object - Label&lt;br /&gt;Suggested Prefix - lbl&lt;br /&gt;Example Name - lblFakeName&lt;br /&gt;&lt;br /&gt;Object - Line&lt;br /&gt;Suggested Pefix - lin&lt;br /&gt;Example Name - linBorder&lt;br /&gt;&lt;br /&gt;Object - List box&lt;br /&gt;Suggested Prefix - lst&lt;br /&gt;Example Name - lstCandidates&lt;br /&gt;&lt;br /&gt;Object - Menu&lt;br /&gt;Suggested Prefix - mnu&lt;br /&gt;Example Name - mnuHamandEggs&lt;br /&gt;&lt;br /&gt;Object - Picture box&lt;br /&gt;Suggested Prefix - pic&lt;br /&gt;Example Name - picPrettyPictures&lt;br /&gt;&lt;br /&gt;Object - Radio button&lt;br /&gt;Suggested Prefix - opt&lt;br /&gt;Example Name - optStation101&lt;br /&gt;&lt;br /&gt;Object - Shape&lt;br /&gt;Suggested Prefix - shp&lt;br /&gt;Example Name - shpUpOrShipOut(circle, square, oval, rectangle, rounded rectangle, and rounded square)&lt;br /&gt;&lt;br /&gt;Object - Text box&lt;br /&gt;Suggested Prefix - txt&lt;br /&gt;Example Name - txtReadStuffHere&lt;br /&gt;&lt;br /&gt;Object - Vertical scroll bar&lt;br /&gt;Suggested Prefix - vsb&lt;br /&gt;Example Name - vsbMoneyWasted&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Creating captions for objects&lt;br /&gt;&lt;br /&gt;In addition to a name, most (but not all) objects also have a caption. An object's caption appears as text on the screen.&lt;br /&gt;&lt;br /&gt;By default, an object's caption and name are the same until you change them. So the moment you draw a check box on a form, the check box's caption is something dull like Check1, and the check box's name is also Check1.&lt;br /&gt;&lt;br /&gt;The caption for a form appears in the title bar of that form. The caption for an object (such as a command button, label, or text box) appears directly on that object while a caption for a check box or radio button usually appears to the right of the check box or option button.&lt;br /&gt;&lt;br /&gt;Captions are meant to help the user figure out how to use your program. A caption can be blank or up to 255 characters long, including spaces, punctuation marks, and four-letter words. The following are valid captions:&lt;br /&gt;&lt;br /&gt;Hello&lt;br /&gt;Hello, buddy!&lt;br /&gt;Do I really know what I'm doing?&lt;br /&gt;&lt;br /&gt;* To change the caption of an object, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object whose caption you want to change so that black handles appear around the object. (To select a form, click anywhere on the form, but do not click on any objects on the form.)&lt;br /&gt;&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;&lt;br /&gt;3. Double-click on the Caption property and type a new caption. Notice that Visual Basic displays your caption on the screen as you type.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Adding hot keys to a Caption:&lt;br /&gt;&lt;br /&gt;Besides looking pretty and displaying information to the user, captions can also be used to create hot keys so that the user can choose an object without having to click on the object with the mouse.&lt;br /&gt;&lt;br /&gt;To add a hot key to a caption, you have to put the ampersand character (&amp;amp;) into an object's caption. You may be wondering, "Why the heck do I want to use an ugly symbol like that?" The answer is to give users yet another way to choose an object on your user interface.&lt;br /&gt;&lt;br /&gt;For example, to push a command button, users can either:&lt;br /&gt;&lt;br /&gt;Click on the command button with the mouse.&lt;br /&gt;Press Tab until the command button appears highlighted and then press the spacebar or Enter (real obvious, huh?).&lt;br /&gt;&lt;br /&gt;However, if you use the ampersand in the command button's caption, the user can push that button by pressing Alt plus whatever letter the ampersand is in front of. For example, if a command button has a caption of &amp;amp;Exit, it appears in the command button with the E underlined, as in Exit. To push this button, you can simply press Alt+E. If the command button has a caption of E&amp;amp;xit, however, the caption appears in the command button with the x underlined, as in Exit, and you can use Alt+X to press this command button.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the font of an object's caption:&lt;br /&gt;&lt;br /&gt;When you create a caption, Visual Basic displays your caption on the screen in a plain type style. For you creative types who want to make your captions look spiffier, you can change the font, type style, and size of captions to give them more pizzazz.&lt;br /&gt;&lt;br /&gt;Fonts are different ways to display text. Normally, Visual Basic uses the MS Sans Serif font, but you can use any font stored in the memory of your computer. (MS Sans Serif is similar to the Helvetica font, and the Visual Basic MS Serif font is similar to the Times Roman font.)&lt;br /&gt;&lt;br /&gt;To change the font of a caption, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object whose caption you want to modify.&lt;br /&gt;2. Open the Properties window (by choosing View-&gt;Properties Window).&lt;br /&gt;3. Double-click on the Font property.&lt;br /&gt;&lt;br /&gt;Visual Basic displays a dialog box of all the fonts you can use.&lt;br /&gt;&lt;br /&gt;4. Click on the font you want and click on OK.&lt;br /&gt;&lt;br /&gt;Visual Basic immediately changes the font of the caption.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Fonts give you a chance to be creative, but they can also disorient the user, especially if you choose bizarre fonts that don't look like anything normally found in nature. To avoid confusion, let Visual Basic use the default font of MS Sans Serif, unless you have a really good reason to use a different font.&lt;br /&gt;&lt;br /&gt;if you choose a really bizarre font, that font may not exist on other people's computers. When using fonts, try to use the most common ones found on all computers or else your program's captions may look really weird.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the size of an object's caption:&lt;br /&gt;&lt;br /&gt;You can also change the size of your caption by making it smaller or larger to fit inside your object. Depending on the font you choose, Visual Basic gives you a variety of font sizes to choose from.&lt;br /&gt;&lt;br /&gt;For example, if you choose the MS Sans Serif font, Visual Basic gives you the following choices of font sizes:&lt;br /&gt;&lt;br /&gt;8&lt;br /&gt;10&lt;br /&gt;12&lt;br /&gt;14&lt;br /&gt;18&lt;br /&gt;24&lt;br /&gt;&lt;br /&gt;Obviously, the more font sizes you use, the odder your captions look. The best approach is to use one size to avoid confusing the user any more than you have to.&lt;br /&gt;&lt;br /&gt;To define the font size of your captions, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object whose font size you want to modify.&lt;br /&gt;&lt;br /&gt;2. Open the Properties window (by clicking on the Properties Window icon on the toolbar).&lt;br /&gt;&lt;br /&gt;3. Double-click on the Font property.  Visual Basic displays a dialog box.&lt;br /&gt;&lt;br /&gt;4. Choose the font size you want to use and click on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the type style of an object's caption:&lt;br /&gt;&lt;br /&gt;If changing the font and size of your captions isn't enough excitement for one day, Visual Basic also lets you change the type style of your captions. The number of available type styles depends on the font you're using for your caption.&lt;br /&gt;&lt;br /&gt;For example, if you choose the MS Sans Serif font, Visual Basic gives you the following choices of type styles:&lt;br /&gt;&lt;br /&gt;Regular&lt;br /&gt;Italic&lt;br /&gt;Bold&lt;br /&gt;Bold Italic&lt;br /&gt;Underline&lt;br /&gt;Strikeout&lt;br /&gt;&lt;br /&gt;If you want, you can even combine two or more type styles for extra emphasis.&lt;br /&gt;&lt;br /&gt;To set different font styles, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object whose caption you want to modify.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Double-click on the Font property.  Visual Basic displays a dialog box.&lt;br /&gt;4. Click on the font style you want to use and click on OK.  Visual Basic immediately changes the caption's appearance.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the background and foreground colors of captions:&lt;br /&gt;&lt;br /&gt;Captions normally appear in boring black, white, and shades of gray. To make your captions stand out more colorfully, you can change the background and foreground colors. The BackColor property of an object represents the object's background color, and the ForeColor property represents the foreground color.&lt;br /&gt;&lt;br /&gt;Unlike other types of objects, command buttons have only a BackColor property. The BackColor property simply changes the color that surrounds the caption when the command button is highlighted.&lt;br /&gt;&lt;br /&gt;To change the color surrounding an object's caption, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object whose background color you want to change.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Double-click on the BackColor (or ForeColor) property and click on the Palette tab.  Visual Basic displays a color palett&lt;br /&gt;4. Click on the color you want. Visual Basic instantly obeys.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Moving objects on the screen&lt;br /&gt;&lt;br /&gt;Objects can appear anywhere on a form. Visual Basic provides two ways to define the position of an object on the form:&lt;br /&gt;&lt;br /&gt;Use the mouse.&lt;br /&gt;Change the Left and Top properties in the Properties window.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To change the position of an object using the mouse, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object you want to move so that black handles appear around the object.&lt;br /&gt;&lt;br /&gt;2. Position the mouse over the object (not over one of the object's handles). Then hold down the left mouse button and move the mouse to where you want the object to appear.&lt;br /&gt;&lt;br /&gt;3. Release the mouse button.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In case you haven't figured out by now what is happening, when you create and place an object for the first time, that position is where Visual Basic displays the object. Use the mouse whenever you want to move an object quickly without regard to exact placement on the screen.&lt;br /&gt;&lt;br /&gt;For more precise measurements when moving an object, use the Properties window and type in values for the Left and Top properties.&lt;br /&gt;&lt;br /&gt;For objects, the Left property measures the distance from the left edge of the form to the left edge of the object. The Top property measures the distance from the top of the form to the top of the object.&lt;br /&gt;&lt;br /&gt;For forms, the Left property measures the distance from the left edge of the screen to the left edge of the form. The Top property measures the distance from the top of the screen to the top of the form.&lt;br /&gt;&lt;br /&gt;To change the position of an object using the Properties window, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object you want to move so that black handles appear around the object.&lt;br /&gt;(If you want to change the position of a form, click anywhere on the form so that handles appear around the edges of the form.)&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Double-click on the Left property and type a new value.&lt;br /&gt;4. Double-click on the Top property and type a new value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Deleting objects off the face of the earth&lt;br /&gt;&lt;br /&gt;Sometimes you draw an object and then decide that you don't need it after all.&lt;br /&gt;&lt;br /&gt;To delete an object, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object you want to delete.&lt;br /&gt;2. Press Delete or choose Edit-&gt;Delete.&lt;br /&gt;&lt;br /&gt;If you press Ctrl+Z right after you delete an object, you can undelete the object you previously deleted.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Copying objects because you're too tired to draw new ones&lt;br /&gt;&lt;br /&gt;After you draw an object that is the exact size you need, you may want to make a copy of the object rather than create a new one and go to the trouble of resizing it.&lt;br /&gt;&lt;br /&gt;To copy an object, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object you want to copy.&lt;br /&gt;2. Press Ctrl+C, choose Edit-&gt;Copy, or click on the Copy Icon.&lt;br /&gt;3. Press Ctrl+V, choose Edit-&gt;Paste, or click on the Paste icon.&lt;br /&gt;&lt;br /&gt;Visual Basic displays a dialog box that asks whether you want to create a control array. If you know what a control array is and want to create one, click on Yes; otherwise, click on No. Visual Basic displays a copy of your object in the upper-left corner of the form.&lt;br /&gt;&lt;br /&gt;A control array lets you create two or more objects that share the same name. That way, two or more objects can share the same event procedure. If none of this makes any sense to you, just pretend this paragraph doesn't exist or refer to the latest edition of MORE Visual Basic For Dummies, which explains what control arrays are and why you might want to use them.&lt;br /&gt;&lt;br /&gt;4. Move this copy of the object anywhere on your screen.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Selecting more than one object to move, copy, or delete&lt;br /&gt;&lt;br /&gt;Before you can move, copy, or delete any object, you have to select the object by clicking on the object. However, if you want to move, copy, or delete more than one object at the same time, you have two choices:&lt;br /&gt;&lt;br /&gt;Use the mouse to select multiple objects.&lt;br /&gt;Click on multiple objects while holding down Ctrl or Shift.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To use the mouse to select multiple objects, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Position the mouse at the upper-left corner of the group of objects you want to select. (But don't position the mouse directly over any of the objects you want to select.)&lt;br /&gt;&lt;br /&gt;2. Hold down the left mouse button while you drag the mouse to the lower-right corner of the group of objects you want to select.&lt;br /&gt;&lt;br /&gt;Visual Basic displays a dotted line around all the objects you select.&lt;br /&gt;&lt;br /&gt;3. Release the mouse button.&lt;br /&gt;&lt;br /&gt;Visual Basic displays a gray rectangle around all the objects you select.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To click on multiple objects while holding down Ctrl or Shift, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the first object that you want to select.&lt;br /&gt;Visual Basic displays black handles around the object.&lt;br /&gt;&lt;br /&gt;2. Point to the second object that you want to select.&lt;br /&gt;&lt;br /&gt;3. Press Ctrl or Shift while you click on the second object.&lt;br /&gt;Visual Basic displays gray rectangles around this object and each of your previously selected objects.&lt;br /&gt;&lt;br /&gt;4. Repeat Steps 2 and 3 until you select all the objects you want.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the size of objects&lt;br /&gt;&lt;br /&gt;After creating an object, the next step is to define the object's size, which is a topic most men tend to exaggerate. Visual Basic provides two ways to change the size of an object:&lt;br /&gt;&lt;br /&gt;Use the mouse.&lt;br /&gt;Change the Height and Width properties in the Properties window.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To change the size of an object using the mouse, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object that you want to resize.  Little black handles appear around the edges of the object.&lt;br /&gt;&lt;br /&gt;2. Move the mouse to the edge of the object until the mouse pointer turns into a double-headed arrow.&lt;br /&gt;&lt;br /&gt;3. Hold down the mouse button and drag the mouse. When the object is in the shape you want, release the mouse button.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To change the size of a form using the Properties window, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object you want to resize.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Double-click on the Height property, type a new value, and press Enter.&lt;br /&gt;4. Double-click on the Width property, type a new value, and press Enter.&lt;br /&gt;&lt;br /&gt;Use the mouse method when the exact size of your object isn't crucial. Change the Height and Width properties manually when you want absolute precision or when you feel like being picky about details that nobody else cares about.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Defining the TabIndex property of your objects&lt;br /&gt;&lt;br /&gt;The TabIndex property determines the order in which Visual Basic highlights buttons when the user presses either the Tab, up-arrow, down-arrow, right-arrow, left-arrow, or Shift+Tab keys.&lt;br /&gt;&lt;br /&gt;The Tab, down-arrow, and right-arrow keys highlight the object with the next-highest TabIndex value.&lt;br /&gt;&lt;br /&gt;The Shift+Tab, up-arrow, and left-arrow keys highlight the object with the next-lowest TabIndex value. To highlight option buttons, you can use only the up, down, right, and left arrow keys, but not the Tab or Shift+Tab keys.&lt;br /&gt;&lt;br /&gt;The spacebar or Enter key selects a highlighted object.&lt;br /&gt;&lt;br /&gt;Some objects, such as image boxes and menu objects, don't have a TabIndex property, so you can't highlight them by pressing any keys.&lt;br /&gt;&lt;br /&gt;An object with a TabIndex property set to 0 appears highlighted as soon as your program runs. If the user presses Tab, the object with a TabIndex property of 1 is highlighted next, and so on.&lt;br /&gt;&lt;br /&gt;The first object that you create has a TabIndex property of 0. The second object that you create has a TabIndex property of 1, and so on.&lt;br /&gt;&lt;br /&gt;The only way to highlight an object stored inside a frame (see Chapter 6) is to press Tab or to click on the object with the mouse. After an object inside a frame is highlighted, pressing the up-, down-, left-, and right-arrow keys only highlights other command buttons or objects in that frame.&lt;br /&gt;&lt;br /&gt;Although most users use a mouse to highlight and select objects, some users may not. For those rare instances, the keyboard is the only way these behind-the-times people can select the objects on your user interface.&lt;br /&gt;&lt;br /&gt;To change the TabIndex property of an object, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object that you want to modify.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Double-click on the TabIndex property and type a number (such as 1 or 4).&lt;br /&gt;&lt;br /&gt;Whenever you change the TabIndex property of a button, Visual Basic automatically renumbers the TabIndex of your other buttons. Thus, you can never assign two buttons identical TabIndex values.&lt;br /&gt;&lt;br /&gt;If you have created lots of objects, you can set the TabIndex properties for them quickly and easily by following these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object that you want highlighted last (the object that Is to have the highest TabIndex property value).&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click on the TabIndex property and type 0.&lt;br /&gt;4. Click on the object that you want highlighted second to last.&lt;br /&gt;5. Repeat Steps 2 through 4 until you set the TabIndex properties for all your objects to 0.&lt;br /&gt;&lt;br /&gt;If you follow these steps, the last object you click on has a TabIndex of 0, the second-to-last object you click on has a TabIndex of 1, and so on.&lt;br /&gt;&lt;br /&gt;For some reason if you don't want the user to be able to highlight an object by pressing the tab key, you can set that object's TabStop property to False.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Dimming objects&lt;br /&gt;&lt;br /&gt;If you don't want the user to press a particular object (such as a command button, a check box, or an image box), you can dim the object. A dimmed object tells the user, "Sometimes you can click on this object but not right now. So there."&lt;br /&gt;&lt;br /&gt;To dim an object, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object that you want to dim.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click on the Enabled property and set it to False.&lt;br /&gt;&lt;br /&gt;A dimmed object doesn't do anything, so if you want to undim it during runtime events, you eventually have to use BASIC code.&lt;br /&gt;&lt;br /&gt;To give you a sneak preview of the incredible power of BASIC code, here's how BASIC undims and dims a button. To undim a button, set the button's Enabled property to True. The following example undims a command button named cmdExit:&lt;br /&gt;&lt;br /&gt;cmdExit.Enabled = True&lt;br /&gt;&lt;br /&gt;To dim a button using BASIC code, set the button's Enabled property to False. The following example dims a command button named cmdExit:&lt;br /&gt;&lt;br /&gt;CmdExit.Enabled = False&lt;br /&gt;&lt;br /&gt;You can dim and undim buttons using BASIC code while your program is running. That way, you can dim and undim buttons in response to whatever the user is doing (typing, moving the mouse, pounding helplessly on the keyboard, and so on).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Making objects invisible&lt;br /&gt;&lt;br /&gt;Rather than dimming an object (which essentially taunts the user because the object is there but unavailable), you can make objects disappear completely.&lt;br /&gt;&lt;br /&gt;To make an object disappear, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object you want to disappear.&lt;br /&gt;2. Press F4 or select Properties from the View menu to open the Properties window.&lt;br /&gt;3. Click on the Visible property and set it to False.&lt;br /&gt;&lt;br /&gt;You can also make an object disappear using BASIC code. To do so, set the object's Visible property to False. The following example makes a command button named cmdNew disappear:&lt;br /&gt;&lt;br /&gt;CmdNew.Visible = False&lt;br /&gt;&lt;br /&gt;Like dimmed objects, invisible objects are useless unless you can make them visible once in a while. To make an object appear again, you have to use BASIC code to set the object's Visible property to True. The following example makes a command button named cmdNew appear:&lt;br /&gt;&lt;br /&gt;CmdNew.Visible = True&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Adding Tooltips to an Object&lt;br /&gt;&lt;br /&gt;Despite the standard user interface of Windows 95/98/NT, many people may still have no clue what the different objects of your program actually do. Rather than click on these unmarked objects at random (and risk wrecking their data), most people sit paralyzed with fear and wind up never using many parts of a program at all.&lt;br /&gt;&lt;br /&gt;To overcome this hesitation, all of your objects can display tooltips. A tooltip is nothing more than brief text that explains what a particular object does. The tooltip remains invisible until the user moves the mouse cursor over the object and leaves the mouse hovering there for a few seconds. Then your Visual Basic program can spring to life and display the tooltip text.&lt;br /&gt;&lt;br /&gt;To create tooltip text for your objects, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on any object on your form.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Double-click on the ToolTipText property.&lt;br /&gt;4. Type the brief explanation that you want to appear whenever the user leaves the mouse cursor over the object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Doing Caption Changes for Yourself&lt;br /&gt;&lt;br /&gt;The following sample program lets you change the caption on the form by typing a new caption in a text box and by clicking on the cmdCaption command button. Just create a user interface according to Table 5-3 and see for yourself the amazing power of Visual Basic.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TABLE 5-3&lt;br /&gt;Properties to Change for CAPTION.VBP&lt;br /&gt;&lt;br /&gt;Object - Form:&lt;br /&gt;&lt;br /&gt;Property - Caption&lt;br /&gt;Setting - The Incredible Changing Caption&lt;br /&gt;&lt;br /&gt;Property - Height&lt;br /&gt;Setting - 3885&lt;br /&gt;&lt;br /&gt;Property - Width&lt;br /&gt;Setting - 4680&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Lable1:&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - lblHeadline&lt;br /&gt;&lt;br /&gt;Property - Caption&lt;br /&gt;Setting - This caption can be changed by clicking on the command button below&lt;br /&gt;&lt;br /&gt;Property - Height&lt;br /&gt;Setting - 600&lt;br /&gt;&lt;br /&gt;Property - Left&lt;br /&gt;Setting - 240&lt;br /&gt;&lt;br /&gt;Property - Top&lt;br /&gt;Setting - 360&lt;br /&gt;&lt;br /&gt;Property - Width&lt;br /&gt;Setting - 4000&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Label2:&lt;br /&gt;&lt;br /&gt;Property - Caption&lt;br /&gt;Setting - Type a new caption here:&lt;br /&gt;&lt;br /&gt;Property - Height&lt;br /&gt;Setting - 300&lt;br /&gt;&lt;br /&gt;Property - Left&lt;br /&gt;Setting - 120&lt;br /&gt;&lt;br /&gt;Property - Top&lt;br /&gt;Setting - 1680&lt;br /&gt;&lt;br /&gt;Property - Width&lt;br /&gt;Setting - 1935&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Text1&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - txtCaption&lt;br /&gt;&lt;br /&gt;Property - Height&lt;br /&gt;Setting - 495&lt;br /&gt;&lt;br /&gt;Property - Left&lt;br /&gt;Setting - 2280&lt;br /&gt;&lt;br /&gt;Property - Multiline&lt;br /&gt;Setting - True&lt;br /&gt;&lt;br /&gt;Property - Text&lt;br /&gt;Setting - (Empty)&lt;br /&gt;&lt;br /&gt;Property - Top&lt;br /&gt;Setting - 1560&lt;br /&gt;&lt;br /&gt;Property - Width&lt;br /&gt;Setting - 1935&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Command1&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - cmdCaption&lt;br /&gt;&lt;br /&gt;Property - Caption&lt;br /&gt;Setting - Change Caption&lt;br /&gt;&lt;br /&gt;Property - Height&lt;br /&gt;Setting - 495&lt;br /&gt;&lt;br /&gt;Property - Left&lt;br /&gt;Setting - 1200&lt;br /&gt;&lt;br /&gt;Property - ToolTipText&lt;br /&gt;Setting - Click here to change the caption&lt;br /&gt;&lt;br /&gt;Property - Top&lt;br /&gt;Setting - 2640&lt;br /&gt;&lt;br /&gt;Property - Width&lt;br /&gt;Setting - 2175&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For those of you who don't like typing, you can examine the CAPTION.VBP program on the enclosed CD-ROM.&lt;br /&gt;&lt;br /&gt;Private Sub cmdCaption_Clock( )&lt;br /&gt;  LvlHeadline.Caption = txtCaption.Text&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;When you run this program, just type a new caption in the text box and click on the command button labeled Change Caption. Visual Basic immediately displays your newly typed text in the top label.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 6&lt;br /&gt;&lt;br /&gt;FORMS AND BUTTONS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Creating forms and drawing borders&lt;br /&gt;Choosing the order in which forms are displayed&lt;br /&gt;Creating buttons&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The main part of a user interface is a window, which Visual Basic calls a form. A Visual Basic program needs at least one form, but most programs use two or more forms.&lt;br /&gt;&lt;br /&gt;For example, a typical program uses one form to display a list of command buttons on which to click. If the user clicks on a command button, a second form appears displaying information such as names, addresses, and telephone numbers of people who owe you money.&lt;br /&gt;&lt;br /&gt;The CD-ROM at the back of this book contains a simple Visual Basic program that shows how to change the background of a form. Feel free to experiment with this program and modify it so you can see how you can easily change the appearance of a form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating a Form&lt;br /&gt;&lt;br /&gt;Visual Basic provides two ways to create a form for your program:&lt;br /&gt;&lt;br /&gt;Create a blank form&lt;br /&gt;Use a form template&lt;br /&gt;&lt;br /&gt;Creating a blank form is handy when you want to design the appearance of the form all by yourself. As a quicker way of creating forms, you can use a form template, which provides pre-designed forms for displaying a Tip of the Day, Web Browser, or Splash Screen window in your program.&lt;br /&gt;&lt;br /&gt;If you use a form template, you still have to customize the form for your program, but at least you won't have to waste time drawing objects on the form from scratch.&lt;br /&gt;&lt;br /&gt;Form: Creates a blank form.&lt;br /&gt;&lt;br /&gt;Dialog: Creates a skeleton of a dialog box with an OK and Cancel command button.&lt;br /&gt;&lt;br /&gt;About Dialog: Displays information about your program.&lt;br /&gt;&lt;br /&gt;Log in Dialog: Forces users to type a User ID and password before they can use your program.&lt;br /&gt;&lt;br /&gt;Options Dialog: Displays a dialog box with tabs, allowing your program to offer options for customizing your program.&lt;br /&gt;&lt;br /&gt;Splash Screen: Displays the name of your program along with a logo whenever your program loads.&lt;br /&gt;&lt;br /&gt;Tip of the Day: Provides tips for using your program.&lt;br /&gt;&lt;br /&gt;ODBC Log In: Displays options for connecting your program to a database.&lt;br /&gt;&lt;br /&gt;Web Browser: Adds a Web browser to your program.&lt;br /&gt;&lt;br /&gt;VB Data Form Wizard: Automatically creates a form to display and edit database information.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* To create a form for your program, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose Project-&gt;Add Form (or click on the Add Form Icon on the toolbar and click on form).&lt;br /&gt;   An Add Form dialog box appears.&lt;br /&gt;&lt;br /&gt;2. Click on an icon in the Add Form dialog box, such as the Form (which adds a blank form), Web Browser, or Splash Screen, and click on Open.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Saving Forms&lt;br /&gt;&lt;br /&gt;After you create a form, you may want to save the form (if not for religious purposes, then at least for practical ones) so that you don't have to create the form all over again later. To save a form, Visual Basic gives you two choices:&lt;br /&gt;&lt;br /&gt;Choose File-&gt;Save Form&lt;br /&gt;Press Ctrl+S&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you have two or more forms displayed on the screen and you want to save changes to all your forms at once, choose File-&gt;Save Project or click on the Save Project icon. This command automatically saves every file (listed in the VBP project file) that makes up your entire Visual Basic program.&lt;br /&gt;&lt;br /&gt;Get into the habit of periodically saving your forms. If your computer fails, the power goes out (but doesn't get your hard drive), or terrorists raid your home and riddle your computer with bullets, you lose only the changes that you've made since you last saved the form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Viewing different forms&lt;br /&gt;&lt;br /&gt;Most Visual Basic programs that you create need two or more forms. To keep multiple forms from cluttering up your screen, Visual Basic kindly displays only one form at a time.&lt;br /&gt;&lt;br /&gt;So if you want to switch to a different form to look at, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose one of the following to switch to the Project Explorer window:&lt;br /&gt;&lt;br /&gt;Choose View-&gt;Project Explorer&lt;br /&gt;Press CtrL+R&lt;br /&gt;Click on the Project Explorer icon in the toolbar&lt;br /&gt;&lt;br /&gt;2. Look for the Forms folder. If a plus sign appears to the left of the Forms folder, click on the plus sign.&lt;br /&gt;Visual Basic displays a list of all the forms that make up your program.&lt;br /&gt;&lt;br /&gt;3. Click on the form that you want to view and then click on the View Object icon in the Project Explorer window (or just double-click on the form name).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Positioning a form with Form Layout window&lt;br /&gt;&lt;br /&gt;The Form Layout window lets you decide where your forms initially appear on the computer screen when the program actually runs. In case you can't see the Form Layout window, choose one of the following:&lt;br /&gt;&lt;br /&gt;View-&gt;Form Layout window&lt;br /&gt;Click on the Form Layout window icon on the toolbar&lt;br /&gt;&lt;br /&gt;The Form Layout window displays your forms within a tiny computer screen. To move a form's position, follow these steps:&lt;br /&gt;&lt;br /&gt;1. In the Form Layout window, move the mouse cursor over the form that you want to move. The mouse cursor turns into a four-way pointing arrow.&lt;br /&gt;&lt;br /&gt;2. Hold down the left mouse button and drag the mouse to move the form to its new position.&lt;br /&gt;&lt;br /&gt;3. Release the left mouse button.&lt;br /&gt;&lt;br /&gt;No matter where your form may appear on the screen while you're editing it, the Form Layout window controls the real position of your form when your program runs.&lt;br /&gt;&lt;br /&gt;For a quick way to adjust the position of a form within the Form Layout window, right-click on a form, highlight Startup Position, and then choose an option from the pop-up menu. As another alternative, you can change the StartUpPosition property directly within the Properties window.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Drawing borders around forms&lt;br /&gt;&lt;br /&gt;Borders make forms look pretty, and they also give nations something to argue about. By changing the BorderStyle property, forms can have one of six types of borders.&lt;br /&gt;&lt;br /&gt;In addition to making your forms look pretty, each border style also affects whether the user can move or resize the form.&lt;br /&gt;&lt;br /&gt;The 0 - None style doesn't display a border around your form, but any objects your form contains can still be seen. A user cannot move, resize, or minimize this type of form.&lt;br /&gt;&lt;br /&gt;The 1 - Fixed Single style displays a Control box, title bar, and Close box. Users can move, but not resize, this type of form.&lt;br /&gt;&lt;br /&gt;The 2 - Sizable style is the default style. This style displays a Control box, a title bar, Minimize and Maximize buttons, and the Close box. Users can move, resize, and minimize or maximize this form.&lt;br /&gt;&lt;br /&gt;The 3 - Fixed Diallog style displays a Control box, a title bar, and a Close box. Users can move this form but cannot resize, minimize, or maximize this form style.&lt;br /&gt;&lt;br /&gt;The 4 - Fixed ToolWindow style displays a title bar and Close box. Users can move this form but cannot resize, minimize, or maximize this style of form.&lt;br /&gt;&lt;br /&gt;The 5 - Sizable ToolWindow style displays a title bar and Close box. Users can move and resize this form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To change the borders around your form using the Properties window, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click anywhere on the form where there is not an object.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click on the BorderStyle property.&lt;br /&gt;4. Choose one of the following:&lt;br /&gt;&lt;br /&gt;0 -None&lt;br /&gt;1 - Fixed Single&lt;br /&gt;2 - Sizable&lt;br /&gt;3 - Fixed Dialog&lt;br /&gt;4 - Fixed ToolWindow&lt;br /&gt;5 - Sizable ToolWindow&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Minimizing and maximizing forms&lt;br /&gt;&lt;br /&gt;Forms can cover part of the screen or the entire screen. Any form that hogs the whole screen is considered maximized. At the other extreme, forms can be shrunk and displayed on the screen as !cons. A shrunken form is considered minimized. Any form that just covers part of the screen is considered normal. Anyone who thinks that computer programmers invent too many definitions is also considered normal.&lt;br /&gt;&lt;br /&gt;If you define a BorderStyle of 0 - None, 1 - Fixed Single, 3 - Fixed Dialog, 4 -Fixed ToolWindow, or 5 - Sizable ToolWindow, you cannot minimize or maximize a form.&lt;br /&gt;&lt;br /&gt;To display a form as normal, minimized, or maximized while your program runs, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click anywhere on the form. (Do not click on any objects on the form.)&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click on the WindowState property in the Properties window.&lt;br /&gt;4. Choose one of the following:&lt;br /&gt;&lt;br /&gt;0 - Normal&lt;br /&gt;1 -Minimized&lt;br /&gt;2 - Maximized&lt;br /&gt;&lt;br /&gt;You can also give the user the option of minimizing or maximizing a form. To do so, your form needs to display Minimize and Maximize buttons.&lt;br /&gt;&lt;br /&gt;To display Minimize and Maximize buttons on a form, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click anywhere on the form where there are no objects.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click on the MinButton (or the MaxButton) property in the Properties window and choose True or False. Depending on the border style you choose for your form, the default setting for the MinButton and MaxButton settings may be True or False.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Removing forms&lt;br /&gt;&lt;br /&gt;Occasionally, you may decide you don't want a particular form as part of your Visual Basic program after all. To remove a form from a Visual Basic project, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose one of the following to switch to the Project Explorer window:&lt;br /&gt;&lt;br /&gt;Choose View-&gt;Project Explorer&lt;br /&gt;Press Ctrl+R&lt;br /&gt;Click on the Project Explorer Icon in the toolbar&lt;br /&gt;&lt;br /&gt;2. Click on the form you want to remove.&lt;br /&gt;&lt;br /&gt;3. Choose Project-&gt;Remove or right-click on the form name and choose Remove.&lt;br /&gt;&lt;br /&gt;If you remove a form that you've previously saved, the form still exists on your hard disk; it just isn't part of your Visual Basic project anymore. To physically remove all traces of a form out of existence, use Windows Explorer and delete the form file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** The Control Box&lt;br /&gt;&lt;br /&gt;Users can move or resize a form by using the mouse. To minimize or maximize a form, simply click the Minimize or Maximize button. For those users who haven't caught up with current technology or refuse to use a mouse, each form also provides a control box, as well.&lt;br /&gt;&lt;br /&gt;If you choose a BorderStyle of 0 - None, 4 - Fixed ToolWindow, or 5 - Sizable ToolWindow, you won't see a control box icon on your forms.&lt;br /&gt;&lt;br /&gt;To activate the control box menu while a program is running, click on the control box icon with the mouse pointer or press Alt+spacebar. A menu appears, which lets the user move, resize, minimize, or maximize a form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Removing a control box&lt;br /&gt;&lt;br /&gt;A control box appears on all forms. But if you think that the box looks really ugly and want to remove it, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click anywhere on the form (except where you find objects on the form).&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click the ControlBox property in the Properties window.&lt;br /&gt;4. Choose True or False.&lt;br /&gt;&lt;br /&gt;Depending on the border style you choose for your form, the default value may be True or False.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Displaying icons as the control bar on forms&lt;br /&gt;&lt;br /&gt;Icons are special graphics symbols with the ICO file extension. Normally, Visual Basic displays the control box of a form with a default icon that looks like a sail flapping in the wind. If you don't like this icon, you can customize the icon. To change an icon with the Properties window, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click anywhere on the form, but not on any objects on the form.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Double-click on the Icon property in the Properties window. Visual Basic displays a Load Icon dialog box.&lt;br /&gt;4. Choose the Icon you want to use and click on Qpen.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Choosing Which Form Visual Basic Displays First&lt;br /&gt;&lt;br /&gt;When your program runs, the first form your program displays is generally the first form you've created. To make another form appear first, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose Project-&gt;ProjectName Properties (where ProjectName Is the name of your Visual Basic project). Visual Basic displays a ProSect Properties dialog box.&lt;br /&gt;&lt;br /&gt;2. Click on the General tab.  Visual Basic displays the Project Properties dialog box.&lt;br /&gt;&lt;br /&gt;3. Click on the downward-pointing arrow of the Startup Object list box to display a list of all the forms for your project.&lt;br /&gt;&lt;br /&gt;4. Choose the form you want to display first and click on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Defining Units of Measurement on a Form&lt;br /&gt;&lt;br /&gt;The reason to have a form is so that you can have a place onto which you can put objects. You may notice, therefore, that every form always displays a grid to help you align objects.&lt;br /&gt;&lt;br /&gt;By default, each form uses a unit of measurement called a twip, which sounds like something Elmer Fudd says. ("I'm tying stwing acwoss this path so that wabbit will twip ove wit. Eh, eh, eh, eh, eh.")&lt;br /&gt;&lt;br /&gt;In case you actually care, 1,440 twips equal 1 inch. If you don't like using twips as your preferred unit of measurement, Visual Basic offers seven options:&lt;br /&gt;&lt;br /&gt;Twips (1,440 twips = 1 inch)&lt;br /&gt;Points (72 points = 1 inch)&lt;br /&gt;Pixels (The number of pixels that equals 1 inch depends on your monitor's resolution.)&lt;br /&gt;Characters (A character is 1/6 inch high and 1/12 inch wide.)&lt;br /&gt;Inches (1 inch = 1 inch - amazing, don't you think?)&lt;br /&gt;Millimeters (25.4 mm = 1 inch)&lt;br /&gt;Centimeters (2.54 cm = 1 inch)&lt;br /&gt;&lt;br /&gt;Hard-core programmers may be happy to know that Visual Basic even lets you create your own customized coordinate system. If you're thinking about doing that, you probably need to read a book with a title like Visual Basic For Hard-Core Programming Geniuses instead of this book. For the rest of us, the seven available units of measurement in Visual Basic are more than sufficient.&lt;br /&gt;&lt;br /&gt;* To change your form's grid scale, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click anywhere on the form. (Do not click any objects on the form.)&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click on the ScaleMode property.&lt;br /&gt;4. Click on the downward-pointing arrow to display a list of all the different measurement units you can use.&lt;br /&gt;5. Select the unit of measurement you want your form to use.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Pushing Your Buttons&lt;br /&gt;&lt;br /&gt;Pushing a button is a simple task that anyone can do. Even children can push buttons, which gives them the power to throw a hot dog in a microwave oven and shout with glee when the meat explodes before their eyes.&lt;br /&gt;&lt;br /&gt;Everyone uses buttons. Your disk drive probably has a button that you press to eject a floppy disk. Your monitor has a button to turn the screen's power on and off. Even your mouse has a button (or two or three).&lt;br /&gt;&lt;br /&gt;Because buttons are so familiar and easy to use, programs often display buttons on the screen that you can push with a mouse. Instead of forcing you to wade through various menus to find the right command, buttons conveniently display your options right before your eyes. All you have to do is figure out which button you want to press.&lt;br /&gt;&lt;br /&gt;Buttons are a feature of nearly every program. Therefore, the rest of this chapter is all about making, modifying, and pushing your own buttons.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Types of buttons&lt;br /&gt;&lt;br /&gt;Essentially, a button is nothing more than an area on the screen that the user can click with the mouse. When pushed (clicked on), a command button rushes off and performs a command. (That's why they call them command buttons.) Visual Basic lets you create two types of buttons: command buttons and image buttons.&lt;br /&gt;&lt;br /&gt;A command button displays a caption or an optional icon. This caption can be as unimaginative as OK, Cancel, or Quit. Or the caption can represent a particular command, such as Erase File, Next Screen, or Lose Mr. Johnson's Airline Reservation.&lt;br /&gt;&lt;br /&gt;Command buttons often appear in dialog boxes where the program displays a message, such as, "Do you really want to erase your IRS tax files to avoid criminal prosecution?" The available choices may be Yes and No.&lt;br /&gt;&lt;br /&gt;Unlike a command button that can display both captions and icons, an image button can display only a picture.&lt;br /&gt;&lt;br /&gt;The advantage of image buttons is that they can be smaller than command buttons. The disadvantage is that unless the user knows which command each image button represents, the user has no idea how to use your image buttons.&lt;br /&gt;&lt;br /&gt;Because image buttons aren't as self-explanatory as command buttons, a good idea is to type a brief description of the image button's purpose in the ToolTipText property (see Chapter 5).&lt;br /&gt;&lt;br /&gt;For example, if the only way to exit your program is to click an image button that shows an open door, people may not understand the connection and may wind up turning off their computer to exit your program instead. (And then they probably aren't going to use your program again, either.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Creating buttons&lt;br /&gt;&lt;br /&gt;To create a command button, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Command Button Icon In the Visual Basic Toolbox.&lt;br /&gt;2. Move the mouse to the place on the form where you want to draw the command button.&lt;br /&gt;3. Press and hold the left mouse button and drag the mouse to form a command button box.&lt;br /&gt;4. Release the left mouse button to complete the operation. Visual Basic displays a boring label like Command1 in the command button.&lt;br /&gt;&lt;br /&gt;Although command buttons are the easiest for users to see and click on, you may want to use an image button to give users the option of clicking on a picture to create multimedia programs. To create an image button, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Image Button !con in the Visual Basic Toolbox.&lt;br /&gt;2. Drag the mouse to the place on the torm where you want to draw the image button.&lt;br /&gt;3. Open the Properties window (by pressing F4).&lt;br /&gt;4. Double-click on the Picture property.  Visual Basic cheerfully displays a Load Picture dialog box.&lt;br /&gt;5. Load any graphics file (bitmap, icon, or metafile).  Visual Basic displays this graphic as your image button.&lt;br /&gt;&lt;br /&gt;After you create a command or image button, you still have to write BASIC code to make the button do something when the user clicks on it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Displaying pretty icons on command buttons&lt;br /&gt;&lt;br /&gt;Although most command buttons simply display a caption, such as OK, Cancel, Yes, No, or Blame It On Your Parents, you also can display icons on command buttons. Pictures can help clarify a command button's purpose. For example, rather than just having a command button display a caption that says "OK," you can also display a green traffic light picture on the command button.&lt;br /&gt;&lt;br /&gt;To make a command button display an icon, you can define the following properties:&lt;br /&gt;&lt;br /&gt;Style (Choose 1 - Graphical)&lt;br /&gt;Picture (Defines the icon that appears on the command button)&lt;br /&gt;DownPicture (Defines the icon that appears when the user clicks on the command button)&lt;br /&gt;DisabledPicture (Defines the icon that appears when the command button is dimmed)&lt;br /&gt;&lt;br /&gt;The DownPicture and DisabledPicture properties are optional if you want to display an icon on a command button.&lt;br /&gt;&lt;br /&gt;To display a picture on a command button, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the command button on the form that you want to display a picture.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click on the Style property, click on the downward-pointing arrow, and choose 1 - Graphical.&lt;br /&gt;4. Double-click on the Picture property.  Visual Basic displays a dialog box.&lt;br /&gt;5. Click on the picture you want to use. (You may have to dig through the Graphics folder to find a picture to use.) Click on Open.&lt;br /&gt;6. Double-click on the DownPicture property to define a picture to appear when the user clicks on the command button.&lt;br /&gt;7. Click on the picture you want to use. (You may have to dig through the Graphics folder to find a picture to use.) Click on Open.&lt;br /&gt;8. Double-click on the DisabledPicture property to define a picture to appear If the command button appears dimmed.&lt;br /&gt;9. Click on the picture you want to use. (You may have to dig through the Graphics folder to find a picture to use.) Click on Open.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the size of an image button&lt;br /&gt;&lt;br /&gt;Visual Basic lets you freely draw an image box of any size that you want; however, if your graphics image is too big for your image button, the graphics image appears cut off.&lt;br /&gt;&lt;br /&gt;To make your graphics image change size when you change the image button's size, you need to change the value of the image box Stretch property to True. (The default value of the Stretch property is False.)&lt;br /&gt;&lt;br /&gt;For example, the image box in the upper-left corner has the Stretch property set to False, so no matter how large you make the image box, the graphics image remains the same size. The other three image boxes have their Stretch properties set to True; therefore, the graphics image adjusts in size when you change the size of the image box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Creating a default command button&lt;br /&gt;&lt;br /&gt;The default command button is the one button that users can choose by pressing the Enter key right away as soon as the command buttons appears on the screen. A default button is the most likely choice for the user to choose.&lt;br /&gt;&lt;br /&gt;For example, if the user gives a command to launch nuclear missiles at another nation, a dialog box may pop up asking, "Wouldn't you rather play a nice game of chess?" If the default button was Yes, the user can mindlessly hit Enter and save the world from nuclear destruction.&lt;br /&gt;&lt;br /&gt;Only command buttons can be default command buttons. Image buttons can never be default command buttons because Visual Basic says so.&lt;br /&gt;&lt;br /&gt;You can use two ways to create a default command button:&lt;br /&gt;&lt;br /&gt;Set the command button's TabIndex property to zero. This highlights the command button designated as the default button.&lt;br /&gt;Set the Default property on the default command button to True. This works only if no other object has a TabIndex value of zero.&lt;br /&gt;&lt;br /&gt;To create a default command button using the TabIndex property, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click the command button that you want to be the default button.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar).&lt;br /&gt;3. Click on the TabIndex property and type 0.&lt;br /&gt;&lt;br /&gt;If no other command buttons on your form have a TabIndex property of zero, you can create a default button by setting the Default property of a command button to True.&lt;br /&gt;&lt;br /&gt;To create a default command button using the Default property, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the command button that you want to be the default button.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click the Default property and set the value to True.&lt;br /&gt;4. Make sure that no other objects on the form have a TabIndex of zero.&lt;br /&gt;&lt;br /&gt;What happens if one command button has a TabIndex of zero but another command button has a Default property that is set to True? The default command button is the one with the TabIndex of zero. So there.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Defining the Cancel button&lt;br /&gt;&lt;br /&gt;When users bang on Esc, they usually want to cancel their last command or exit out of the program. Any button that lets the user do this needs to be designated the Cancel button. Only one command button can be defined as the Cancel button. (Another good name for the Cancel button is the Panic button, but that destroys the image of programming as a fine science rather than an incoherent art.)&lt;br /&gt;&lt;br /&gt;To create a Cancel command button, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click the command button that you want to be the Cancel button.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click the Cancel property, set the value to True, and change the button's caption to "cancel" or something similar.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Grouping command buttons&lt;br /&gt;&lt;br /&gt;Occasionally, you may want to group related command buttons on the screen to give the illusion of organization.&lt;br /&gt;&lt;br /&gt;To create a group of command buttons, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Frame Icon in the Visual Basic Toolbox.&lt;br /&gt;2. Move the mouse to where you want to draw the frame.&lt;br /&gt;3. Hold down the mouse button and move the mouse to draw a frame.&lt;br /&gt;4. Click on the Command Button icon in the Visual Basic Toolbox.&lt;br /&gt;5. Move the mouse inside the frame to where you want to draw a command button.&lt;br /&gt;6. Hold down the mouse button and move the mouse to draw your command button Inside the frame.&lt;br /&gt;7. Repeat Steps 4 through 6 until you draw all the command buttons you need or until you decide that the time has come to do something else.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After you draw a command button inside a frame, the button remains forever trapped inside the frame. When you move the frame, all command buttons inside move along with their host frame.&lt;br /&gt;&lt;br /&gt;You cannot create a command button outside a frame and then try to move the button inside a frame, so don't bother trying.&lt;br /&gt;If a command button exists outside of a frame, click on it, choose the Copy or Cut command, click inside the frame so the frame's handles appear, then choose the Paste command. This lets you copy or cut a command button from outside a frame and put it inside the frame.&lt;br /&gt;&lt;br /&gt;As a final modification for grouped command buttons, set the TabStop properties of all grouped buttons to False. Next, set the TabStop property of the first command button to True. That way, if a lame user presses Tab, only the first command button in a group becomes highlighted.&lt;br /&gt;&lt;br /&gt;To turn off the TabStop properties for a group of buttons, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click any command button within the frame, except for the first command button.&lt;br /&gt;2. Open the Properties window (by pressing F4).&lt;br /&gt;3. Click on the TabStop property and set the value to False.&lt;br /&gt;4. Repeat Steps 1 through 3 until the TabStop property for all the command buttons (except the first command button) has been set to False.&lt;br /&gt;5. Go to the kitchen and reward yourself with a Twinkle for your good deed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. Why do command buttons have names and captions?&lt;br /&gt;&lt;br /&gt;a. So you have twice as many chances to call them a four-letter word.&lt;br /&gt;b. The name is a bad word you can call the command button, and the caption is there so that you can write a funny punch line.&lt;br /&gt;c. The name identifies the command button, and the caption is what actually appears on the screen.&lt;br /&gt;d. Because Visual Basic says so, and any product sold by Bill Gates can't be wrong because he's a billionaire,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Why do you want to group buttons together in a frame?&lt;br /&gt;&lt;br /&gt;a. To keep them from escaping into the wild.&lt;br /&gt;b. So related commands are easy to find on the screen.&lt;br /&gt;c. To make understanding what your program is supposed to do harder for anyone.&lt;br /&gt;d. No reason, except to cause more confusion to people trying to learn how to program a computer for the first time.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 7&lt;br /&gt;&lt;br /&gt;BOXES AND BUTTONS FOR MAKING CHOICES&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this chapter:&lt;br /&gt;&lt;br /&gt;Creating check boxes and radio buttons&lt;br /&gt;Creating list boxes and combo boxes&lt;br /&gt;Sorting items in a list box or combo box&lt;br /&gt;Making listed items look pretty&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In school, multiple-choice tests were always easier than essay tests because you could substitute guessing for thinking and still get a decent grade. However, students aren't the only ones who don't want to think if they can avoid doing so. Most users are the same way - they want choices clearly laid out in front of their eyes. That way, they can make wild guesses and be on their merry way.&lt;br /&gt;&lt;br /&gt;Visual Basic provides several ways to offer choices to users: check boxes, radio buttons (also called option buttons), list boxes, and combo boxes. Check boxes let users choose one or more options. Radio buttons let users choose only one option. List boxes and combo boxes offer users multiple choices.&lt;br /&gt;&lt;br /&gt;The CD contains a Visual Basic program that shows how check boxes, radio buttons, list boxes, and combo boxes work. Feel free to modify the source code and see what happens.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating Check Boxes and Radio Buttons&lt;br /&gt;&lt;br /&gt;Check boxes get their name from those silly questionnaires that ask, "Check all that apply," as in:&lt;br /&gt;&lt;br /&gt;Why do you want to work here? (Check all that apply.)&lt;br /&gt;   need the money.&lt;br /&gt;   want to participate in employee theft.&lt;br /&gt;   want a place where I can steal more office supplies.&lt;br /&gt;   need a safe place to hide from the police.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Radio buttons get their name from those old AM car radios that let you push a button to change stations quickly. Just as you can listen to only one radio station at a time, radio buttons let you choose only one option at a time. The following is an example of radio buttons.&lt;br /&gt;&lt;br /&gt;What is your sex? (Choose only one.)&lt;br /&gt;  Male&lt;br /&gt;  Female&lt;br /&gt;  Ex-male (surgically a female)&lt;br /&gt;  Ex-fernale (surgically a male)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Aligning your boxes and buttons&lt;br /&gt;&lt;br /&gt;Check boxes and radio buttons are usually left-aligned, which means they look like the following:&lt;br /&gt;&lt;br /&gt;   This is left-aligned.&lt;br /&gt;&lt;br /&gt;For some odd reason known only to those few programmers who actually use aligning options, you can also right-align check boxes and radio buttons.&lt;br /&gt;&lt;br /&gt;This is right-aligned.&lt;br /&gt;&lt;br /&gt;* To left-align or right-align a check box or radio button, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the check box or radio button that you want to align.&lt;br /&gt;&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;PropertiesWindow, or click on the Properties Window Icon on the toolbar.)&lt;br /&gt;&lt;br /&gt;3. Click on the Alignment property and set the value to 0 - Left Justify or 1 - Right Justify.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Grouping check boxes&lt;br /&gt;&lt;br /&gt;Check boxes rarely appear by themselves. Usually, two or more check boxes huddle together like frightened farm animals. The best way to isolate groups of check boxes is to use a frame. Frames visually separate different groups of check boxes. To create a group of check boxes, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Frame Icon In the Visual Basic Toolbox.&lt;br /&gt;2. Move the mouse to where you want to draw the frame.&lt;br /&gt;3. Hold down the left mouse button and move the mouse to draw a frame.&lt;br /&gt;4. Click on the Check Box icon In the Visual Basic Toolbox.&lt;br /&gt;5. Inside the frame, move the mouse to where you want to draw a check box.&lt;br /&gt;6. Hold down the left mouse button and move the mouse to draw your check box.&lt;br /&gt;7. Repeat Steps 4 through 6 until you've drawn all the check boxes you want inside your frame or until you decide the time for a break has arrived.&lt;br /&gt;&lt;br /&gt;As a final modification to a group of check boxes, set the TabStop properties of all grouped check boxes to False. Next, set the TabStop property of the first check box to True. That way, when someone presses the Tab key, only the first check box in that frame becomes highlighted.&lt;br /&gt;&lt;br /&gt;To turn off the TabStop properties for a group of check boxes, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on any check box or radio button within the frame, except the first check box.&lt;br /&gt;&lt;br /&gt;2. Open the Properties window. (In other words, press F4, choose View-&gt;PropertiesWindow, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;&lt;br /&gt;3. Click on the TabStop property and set the value to False.&lt;br /&gt;&lt;br /&gt;4. Repeat Steps 1 through 3 until the TabStop property has been set to False for all but one of the check boxes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Grouping radio buttons&lt;br /&gt;&lt;br /&gt;If the radio buttons on a form are not grouped inside a frame, Visual Basic assumes that all radio buttons appearing on the same form belong to the same group. Thus, even if two radio buttons have nothing in common with each other but they appear on the same form, only one of the radio buttons can be chosen at any time.&lt;br /&gt;&lt;br /&gt;If you need to display two or more groups of radio buttons, you have to group them within a frame. Otherwise, Visual Basic lumps all the radio buttons in a single group, which means that only one radio button can be chosen at any given time.&lt;br /&gt;&lt;br /&gt;* To create a group of radio buttons in a frame, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Frame icon in the Visual Basic Toolbox.&lt;br /&gt;2. Move the mouse to where you want to draw the frame.&lt;br /&gt;3. Hold down the left mouse button and move the mouse to draw a frame.&lt;br /&gt;4. Click on the Radio Button icon in the Visual Basic Toolbox.&lt;br /&gt;5. Inside the frame, move the mouse to where you want to draw a radio button.&lt;br /&gt;6. Hold down the left mouse button and move the mouse to draw your radio button.&lt;br /&gt;7. Repeat Steps 4 through 6 until you've drawn all the radio buttons you want inside your frame or until you have to go to the bathroom.&lt;br /&gt;&lt;br /&gt;After you draw a radio button inside a frame, the button remains trapped inside that frame forever. When you move the frame, all radio buttons inside move along with their host frame.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Adding icons to check boxes and radio buttons&lt;br /&gt;&lt;br /&gt;Normally, check boxes and radio buttons display only a caption; but if you want to get fancy, you also can display icons on your check boxes and radio buttons, too.&lt;br /&gt;&lt;br /&gt;* To make a check box or radio button display an icon, you must change the following properties as explained below:&lt;br /&gt;&lt;br /&gt;Style: Choose 1 - Graphical&lt;br /&gt;Picture: Defines the icon that appears on the check box or radio button&lt;br /&gt;DownPicture: Defines the icon that appears when the user clicks on the check box or radio button&lt;br /&gt;DisabledPicture: Defines the icon that appears when the check box or radio button is dimmed&lt;br /&gt;&lt;br /&gt;For some odd reason, Visual Basic makes check boxes and radio buttons with pictures appear like command buttons. Make sure that you take this strange appearance into account, or else both you and your users may mistake a check box or radio button for a command button instead.&lt;br /&gt;&lt;br /&gt;* To display a picture on a check box or radio button, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the check box or radio button on the form that you want to display a picture.&lt;br /&gt;&lt;br /&gt;2. Open the Properties window. (Press F4, choose Viewt-&gt;PropertiesWindow, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;&lt;br /&gt;3. Click the Style property, click the downward-pointing arrow, and choose 1 - Graphical.&lt;br /&gt;&lt;br /&gt;4. Double-click on the Picture property.  Visual Basic displays a dialog box.&lt;br /&gt;&lt;br /&gt;5. Click on the picture you want to use. (You may have to dig through the Graphics folder to find a picture to use.) Click on Open.&lt;br /&gt;&lt;br /&gt;6. Double-click on the DownPicture property to define a picture to appear when the user clicks on the command button.&lt;br /&gt;&lt;br /&gt;7. Click on the picture you want to use. (You may have to dig through the Graphics folder to find a picture to use.) Click on Open.&lt;br /&gt;&lt;br /&gt;8. Double-click on the DisabledPicture property to define a picture to appear if the command button appears dimmed.&lt;br /&gt;&lt;br /&gt;9. Click on the Picture you want to use. (You may have to dig through the Graphics folder to find a picture to use.) Click on Open.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Offering More Choices with List Boxes and Combo Boxes&lt;br /&gt;&lt;br /&gt;When you have only a few choices, check boxes and radio buttons work nicely. If you have ten or more choices, however, bombarding the user with a screen full of check boxes or radio buttons can be intimidating and ugly. To present many choices to the user in a clear and helpful manner, Visual Basic provides two alternatives to check boxes and radio buttons: list boxes and combo boxes.&lt;br /&gt;&lt;br /&gt;List boxes display long lists of options from which users can choose. If users want to choose something that isn't on the list, too bad. They can't.&lt;br /&gt;&lt;br /&gt;Combo boxes also display long lists of options for the user to choose. The difference is that combo boxes also let the user type a choice if the selection the user wants cannot be found on the list. Figure 7-4 shows an example of a list box and a combo box. Notice that the combo box displays items only if you click on the down arrow; the list box always displays items.&lt;br /&gt;is a combo box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Creating list boxes and combo boxes&lt;br /&gt;&lt;br /&gt;List boxes are like fast-food menus. You can choose only what's on the menu because the folks working there don't know how to handle special requests. Combo boxes are like fancy restaurants where you have a choice of ordering off the menu or saying, "I know this is a vegetarian restaurant, but I want the cook to grill me a steak anyway."&lt;br /&gt;&lt;br /&gt;* To create a list box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the List Box !con in the Visual Basic Toolbox.&lt;br /&gt;2. Move the mouse to the place on the form where you want to draw the list box.&lt;br /&gt;3. Hold down the left mouse button and move the mouse to draw the list box. Visual Basic displays one list box with a dull caption such as List3.&lt;br /&gt;4. Repeat Steps 1 through 3 until you've drawn all the list boxes you need.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* To create a combo box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Combo Box icon In the Visual Basic Toolbox.&lt;br /&gt;2. Move the mouse to the place on the form where you want to draw the combo box.&lt;br /&gt;3. Hold down the left mouse button and move the mouse to draw the combo box. Visual Basic displays one combo box with a dull caption such as Combo1.&lt;br /&gt;4. Repeat Steps 1 through 3 until you've drawn all the combo boxes you need.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Combo box styles&lt;br /&gt;&lt;br /&gt;A combo box lets you type a choice or select one from the displayed list. For added variety, three styles of combo boxes are available:&lt;br /&gt;&lt;br /&gt;Drop-down combo box (Style 0, the default)&lt;br /&gt;Simple combo box (Style 1)&lt;br /&gt;Drop-down list box (Style 2)&lt;br /&gt;&lt;br /&gt;The drop-down combo box lets users type an item. If users have no idea what to type, they can click the downward-pointing arrow to the right of the combo box, and the combo box politely displays a list of possible choices. Visual Basic always creates this type of combo box unless you change the Visual Basic Style property.&lt;br /&gt;&lt;br /&gt;The simple combo box always displays the list on the screen but also gives users the choice of typing an item.&lt;br /&gt;&lt;br /&gt;Unlike the other two combo box styles, you must draw the full size of a simple combo box style so the user can see the items stored in the combo box.&lt;br /&gt;&lt;br /&gt;The drop-down list box is actually a list box and always displays a range of choices, but you can't type anything of your own.&lt;br /&gt;&lt;br /&gt;If you don't want the user to type anything into a combo box, set the combo box's Style property to 2 - Dropdown List.&lt;br /&gt;&lt;br /&gt;At this point, you may be asking, "Wait a minute. Why do I want to create a combo box and then turn it into a stupid list box?" Unlike ordinary list boxes, a drop-down list box doesn't display the list on the screen until the user clicks on the arrow to the right of the box. This type of list box is useful when you need to conserve screen space.&lt;br /&gt;&lt;br /&gt;* To define the style for a combo box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the combo box that you want to change.  (This assumes that you've already created the box.)&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window Icon on the toolbar.)&lt;br /&gt;3. Click on the Style property.&lt;br /&gt;4. Click on the arrow in the Settings Box to display your list of choices. (Hey, what do you know? The Settings Box is an example of a dropdown list box!)&lt;br /&gt;5. Click on the combo box style you want.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. What is the main difference between a check box and a radio button?&lt;br /&gt;&lt;br /&gt;a.You can choose one or more check boxes but only one radio button.&lt;br /&gt;b. Radio buttons tune in to your favorite radio station, but check boxes are places where you save canceled checks.&lt;br /&gt;c. I don't know. Aren't you supposed to be the teacher with all the answers?&lt;br /&gt;d. Everything is one, man. Like, the answer is all in your point of view.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. What is the major difference between a list box and a combo box?&lt;br /&gt;&lt;br /&gt;a. A combo box gives you a choice of typing an item or choosing one from a displayed list. A list box forces you to choose an item from a displayed list.&lt;br /&gt;b. A list box is spelled L-I-S-T, but a combo box is spelled C-O-M-B-O.&lt;br /&gt;c. Combo boxes are cooler than list boxes because a combo box tends to be more confusing to the average user.&lt;br /&gt;d. No difference. In fact, two out of three French chefs think that they both taste exactly like butter.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Adding Items to List Boxes and Combo Boxes&lt;br /&gt;&lt;br /&gt;After you create your list box or combo box, you have to fill up your box with items. (Otherwise, you have no real point in creating a list box or combo box, now do you?) Visual Basic gives you two ways to add items to a list box or combo box:&lt;br /&gt;&lt;br /&gt;Use the List property in the Properties window.&lt;br /&gt;Use BASIC code.&lt;br /&gt;&lt;br /&gt;** To add items to a list box or a combo box using the List property, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the list box or combo box that you want to add items to.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;PropertiesWindow, or click on the Properties Window Icon on the toolbar.)&lt;br /&gt;3. Double-click on the List property. A drop-down text box appears.&lt;br /&gt;4. Type the first item you want to appear in your list box or combo box. Next, press Ctrl+Enter. Repeat this step for each item you want to add.&lt;br /&gt;5. Press Enter.&lt;br /&gt;&lt;br /&gt;When typing items in the List property, make sure that you press CtrL+Enter in between each item. The moment you press Enter, Visual Basic assumes you're done typing items in the List property.&lt;br /&gt;&lt;br /&gt;If you want to use BASIC code to add items to a list box or combo box, the secret BASIC command to use is AddItem. So if you want to add the item "Pick me" to a list box named 1stCommands, here is the magic BASIC code that you use to do so:&lt;br /&gt;&lt;br /&gt;1stCommands.AddItem "Pick me"&lt;br /&gt;&lt;br /&gt;You can add items to a list box or combo box any time your program is running, but the most common time is when the form containing the list box or combo box first loads.&lt;br /&gt;&lt;br /&gt;To add items to a list when a form loads, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form in the Project Explorer window.&lt;br /&gt;2. Click on the View Code !con.&lt;br /&gt;3. Click in the Object list box and choose the form name.  Visual Basic displays the following procedure:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load()&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;4. For each item you want to display in a list box or combo box, use the AddItem secret command.&lt;br /&gt;&lt;br /&gt;For example, if you had a list box named 1stToDo and a combo box named cboHideln, the Sub Form-Load () procedure may look like the following:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load()&lt;br /&gt;  1stToDo.AddItem "Call stockbroker"&lt;br /&gt;  1stToDo.AddItem "Make airline reservations"&lt;br /&gt;  1stToDo.AddItem "Act normally until noon"&lt;br /&gt;  1stToDo.AddItem "Steal $250,000"&lt;br /&gt;  1stToDo.AddItem "Fake headache"&lt;br /&gt;  1stToDo.AddItem "Leave work early"&lt;br /&gt;  1stToDo.AddItem "Go to airport"&lt;br /&gt;  cboHideln.AddItem "Acapulco"&lt;br /&gt;  cboHideIn.AddItem "Rio de Janeiro"&lt;br /&gt;  cboHideIn.AddItem "Paris"&lt;br /&gt;  cboHideIn.AddItem "Tokyo"&lt;br /&gt;  cboHideIn.AddItem "New York"&lt;br /&gt;  cboHideIn.AddItem "Bangkok"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;This procedure adds these items to the 1stToDo list box and to the cboHideln combo box whenever the first form of your program loads.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Highlighting default items&lt;br /&gt;&lt;br /&gt;The purpose of list boxes and combo boxes is to provide users with choices. To make choosing items even more mindless and thus more efficient from the user's point of view, combo boxes can display default items. (With list boxes, the first item is the default item.) A default item is the item that the computer assumes the user wants unless instructed otherwise. (For a default item to be the least likely choice doesn't really make much sense.)&lt;br /&gt;&lt;br /&gt;** To create a default item for a combo box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the combo box for which you want to assign a default Item.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;PropertiesWindow, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;3. Click on the Text property.&lt;br /&gt;4. Type the item that you want to appear as the default item in this combo box.&lt;br /&gt;&lt;br /&gt;If you set a combo box's Style property to 2 - Dropdown List, you can define a default item by using BASIC code to set the ListIndex property to a value such as 0 (to make the first item the default item):&lt;br /&gt;&lt;br /&gt;CboHideIn.ListIndex = 2&lt;br /&gt;&lt;br /&gt;When a user clicks on the combo box, the default item is highlighted.&lt;br /&gt;&lt;br /&gt;If you don't define a default item, Visual Basic displays the combo box's generic name (Combo1, Combo2, and so on) as the default item. Because this looks very ugly and amateurish, you should always define a default item for your combo boxes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Sorting Items In a list box or combo box&lt;br /&gt;&lt;br /&gt;The order that you add items to a list box or combo box is the order in which the items appear. For a little variety, Visual Basic lets you sort items in two ways:&lt;br /&gt;&lt;br /&gt;Alphabetically&lt;br /&gt;Any way you want&lt;br /&gt;&lt;br /&gt;When Visual Basic sorts a list alphabetically, the list is sorted without regard to whether items are capitalized or not. For example, Visual Basic considers "Your Momma" and "YOUR MOMMA" to be identical.&lt;br /&gt;&lt;br /&gt;To sort items in a list box or combo box alphabetically, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the list box or combo box in which you want to display items alphabetically.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;PropertiesWindow, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;3. Click on the Sorted property and set the property to True.&lt;br /&gt;&lt;br /&gt;Visual Basic always sorts items with the A's on top and the Z's at the bottom. You cannot sort items in descending order, with the Z's on top and the A's at the bottom (unless, of course, you flip your monitor upside down).&lt;br /&gt;&lt;br /&gt;If alphabetic sorting isn't what you want, you have to sort items one-by-one yourself. Visual Basic assigns an index number (which is just an ordinary number such as 1 or 3) to each item in a list.&lt;br /&gt;&lt;br /&gt;The first item in a list is assigned an index number of 0, the second item is assigned an index number of 1, the third item is assigned an index number of 2, and so on. (If you've ever been in a European elevator where the ground floor is labeled 1, the first floor is labeled 2, and the second floor is labeled 3, you are going to recognize the confusing way that Visual Basic assigns index numbers.)&lt;br /&gt;&lt;br /&gt;To put an item at the top of a list, you still have to use the magic Add Item BASIC command in the following way:&lt;br /&gt;&lt;br /&gt;cboHideIn.AddItem "Harare", 0&lt;br /&gt;&lt;br /&gt;If you omit the index number, Visual Basic adds items to a list in one of two ways:&lt;br /&gt;&lt;br /&gt;If the Sorted property of the list box or combo box is False, the item goes to the bottom of the list.&lt;br /&gt;If the Sorted property of the list box or combo box is True, the item goes in the correct alphabetic order.&lt;br /&gt;&lt;br /&gt;If you set the Sorted property of a list box or combo box to True and add items by using index numbers, Visual Basic adds the item according to the index number and does not sort the newly added items alphabetically.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Removing items from a list box or combo box&lt;br /&gt;&lt;br /&gt;Adding items and sorting them may make your lists look nice, but wiping out an item to satisfy that destructive urge that everyone experiences once in a while is more fun.&lt;br /&gt;&lt;br /&gt;Visual Basic gives you two ways to remove an item from a list:&lt;br /&gt;&lt;br /&gt;Use the RemoveItem BASIC command to remove items one at a time.&lt;br /&gt;Use the Clear BASIC command to wipe out an entire list at once.&lt;br /&gt;&lt;br /&gt;To use the Remove Item BASIC command, you have to know the index number of the item you want to remove. For example, to remove the item with an index number of 5 that's located in a list box named 1stToDo, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;1st ToDo.Removeltem 5&lt;br /&gt;&lt;br /&gt;To use the Clear BASIC command to wipe out an entire list in a single blow, you need the name of the list box or combo box that contains the list you want to kill. To wipe out the entire contents of a combo box named cboHideln, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;CboHideIn.Clear&lt;br /&gt;&lt;br /&gt;Before using the Clear BASIC command, make sure that you really want to wipe out an entire list.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Displaying check boxes in your list boxes&lt;br /&gt;&lt;br /&gt;When you display items in a list box, you can also display them as check boxes. By using check boxes, you can check off items in a list box such as to-do lists, grocery lists, or lists of New Year's resolutions that you never plan to complete.&lt;br /&gt;&lt;br /&gt;* To display check boxes in a list box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the list box where you want check boxes to appear.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;3. Click on the Style property and choose 1 - Checkbox.&lt;br /&gt;&lt;br /&gt;To figure out which item a user may have chosen in a checked list box, you have to use BASIC code. Remember that items in a list box are assigned a number. The top item is given an index number of 0, the second from the top a number of 1, the third from the top 2, and so on. Knowing this, you have to write an event procedure that tells you which item was just checked (or unchecked). To do this, you have to use the event procedure attached to your list box such as:&lt;br /&gt;&lt;br /&gt;Private Sub List1-ItemCheck(Item As Integer)&lt;br /&gt;GlobalVariable = Item&lt;br /&gt;&lt;br /&gt;' This will print the item checked (or unchecked)&lt;br /&gt;Print Item&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The moment someone checks (or unchecks) an item in a checked list box, the ItemCheck event procedure runs and the Item variable tells you which item was checked (or unchecked). So if the top item is checked (or unchecked), the ItemCheck event procedure assigns the number 0 to Item.&lt;br /&gt;&lt;br /&gt;Then you have to assign your own variable to Item so you can tell the other parts of your program which list box item got checked (or unchecked). From there, you have to write BASIC code to figure out what to do if someone checks or unchecks an item.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating Multiple Column List Boxes&lt;br /&gt;&lt;br /&gt;For aesthetic purposes - or just because you're bored and want to goof around - you can dispIay multiple columns in a list box. Visual Basic provides three types of multiple columns, depending on the value defined by the Column property:&lt;br /&gt;&lt;br /&gt;Value 0: A single column list with vertical scrolling (the default appearance of list boxes)&lt;br /&gt;&lt;br /&gt;Value 1: A single column list with horizontal scrolling (but no vertical scrolling)&lt;br /&gt;&lt;br /&gt;Any value greater than 1 in number: A multiple column list of two or more columns with horizontal scrolling (but no vertical scrolling)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* To change the way a list box displays items in columns, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the list box that you want to modify.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;3. Click on the Columns property and type 0, 1, or any number larger than 1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Making Listed Items Look Pretty&lt;br /&gt;&lt;br /&gt;To spice up your lists and make them look a little less like boring shopping lists, Visual Basic lets you change the font, type style, and size of your list's items.&lt;br /&gt;&lt;br /&gt;Fonts are different ways to display text. Normally, Visual Basic uses the MS Sans Serif font, but you can use any font stored in the memory of your computer. (MS Sans Serif is similar to the Helvetica font, and the Visual Basic MS Serif font is similar to the Times Roman font.)&lt;br /&gt;&lt;br /&gt;* To change the font of items that appear in a list box or combo box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the list box or combo box whose font you want to modify.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;3. Double-click on the Font property.  Visual Basic displays a Font dialog box.&lt;br /&gt;4. Click on the font you want and click on OK.  Visual Basic immediately changes the font in the list box or combo box.&lt;br /&gt;&lt;br /&gt;Be careful when you use fonts. Novices often get carried away and use so many bizarre fonts that all semblance of normality is lost. Unless you have a really good reason to use different fonts, let Visual Basic use its default font of MS Sans Serif.&lt;br /&gt;&lt;br /&gt;You can also change the size of your items, making them smaller or larger. However, the larger the type size is, the larger your list box or combo box must be to show the entire item at once.&lt;br /&gt;&lt;br /&gt;The larger the font size, the more the items in your list boxes and combo boxes stand out. Usually, the best method is to use one size for all your list boxes or combo boxes to avoid confusing the user any more than you have to.&lt;br /&gt;&lt;br /&gt;* To define the font size, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the list box or combo box whose font size you want to modify.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window Icon on the toolbar.)&lt;br /&gt;3. Double-click on the Font property.  Visual Basic displays a Font dialog box.&lt;br /&gt;4. Click on the font size you want and click on OK.&lt;br /&gt;Visual Basic immediately changes the font size of the list box or combo box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Besides changing the font and size, you can also change the font style and display text in bold, italics, underline, or strikeout.&lt;br /&gt;* To set any one or more font styles, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the list box or combo box whose fonts you want to modify.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar).&lt;br /&gt;3. Double-click on the Font property.  Visual Basic displays a Font dialog box.&lt;br /&gt;4. Click on the font style you want and click on OK.&lt;br /&gt;Visual Basic immediately changes the font style of the list box or combo box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The more attractive you make your list boxes and combo boxes, the more likely the user is going to notice the boxes, at least (if not use them). Just remember that you want to make your program easy to use, not a work of art. If you want to get creative, take up finger painting. If you want to create useful programs and make millions of dollars, make your programs easy, fun, and simple to use.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 8&lt;br /&gt;&lt;br /&gt;TEXT BOXES FOR TYPING AND SHOWING WORDS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Creating text boxes&lt;br /&gt;Filling text boxes and hiding passwords&lt;br /&gt;Using different fonts, sizes, type styles, and colors&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Despite the growing acceptance of icons and graphical user interfaces, not all choices can always be offered through command buttons, radio buttons, or combo boxes. Sometimes your program may need to display a word, sentence, paragraph, or entire novel on the screen. And sometimes the user may want to type in a good word or two as well.&lt;br /&gt;&lt;br /&gt;So what's the solution? Combo boxes work with words or short phrases, but if your program needs to display a chunk of text or if the user needs to type in a substantial amount of information, a text box can make your job a whole lot easier.&lt;br /&gt;&lt;br /&gt;Text boxes have two purposes in life:&lt;br /&gt;&lt;br /&gt;To show text on the screen&lt;br /&gt;To let the user type text into the program&lt;br /&gt;&lt;br /&gt;Text boxes are among the most flexible programming objects because you can display instructions in a text box and the user can type a reply using ordinary words. If you use enough text boxes in your programs, you may help increase literacy among our population today.&lt;br /&gt;&lt;br /&gt;The Visual Basic program enclosed on the CD-ROM provides a simple example of using a text box for accepting a password. Dig into the source code and play around. At the very least, you may mess up the program but still learn something in the process.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating a Text Box&lt;br /&gt;&lt;br /&gt;Text boxes are like miniature word processors but can display only one font, one size, and one type style (such as bold or italics). So if you want to display multiple fonts in a text box, give up that thought right now because you can't.&lt;br /&gt;&lt;br /&gt;When a user types text in a text box, the following keys work:&lt;br /&gt;&lt;br /&gt;Delete: Erases the character to the right of the cursor&lt;br /&gt;Backspace: Erases the character to the left of the cursor&lt;br /&gt;Shift+Arrow: Highlights a block of text&lt;br /&gt;Ctrl+Left arrow: Moves the cursor one word to the left&lt;br /&gt;Ctrl+Right arrow: Moves the cursor one word to the right&lt;br /&gt;Home (or Ctrl+Home): Moves the cursor to the beginning of the line&lt;br /&gt;End (or Ctrl+End): Moves the cursor to the end of the line&lt;br /&gt;Shift+any movement key (such as Home): Highlights text&lt;br /&gt;F11 or F12: Doesn't do a thing and is about as useful on your keyboard as wisdom teeth in your mouth&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To create a text box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Text Box Icon in the Visual Basic Toolbox.&lt;br /&gt;2. On the form, move the mouse where you want to draw the text box.&lt;br /&gt;3. Hold down the left mouse button and draw the text box. Visual Basic displays your text box with default text inside, such as Text1.&lt;br /&gt;4. Repeat Steps 1 through 3 until you've drawn all the text boxes you need or until you find something else to do.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Putting pretty borders around text boxes&lt;br /&gt;&lt;br /&gt;Normally, Visual Basic displays a single line around a text box, defining the boundaries of that text box. If you want to keep your users guessing where a text box is, you can remove this border.&lt;br /&gt;&lt;br /&gt;* To change the borders around a text box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box whose border you want to change.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;3. Click on the BorderStyle property and choose one of the following:&lt;br /&gt;&lt;br /&gt;0 -None&lt;br /&gt;1 - Fixed Single&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Displaying wordes in a text box&lt;br /&gt;&lt;br /&gt;After you create a text box, the next step is to put some text in the box. By default, Visual Basic displays the text box's name in the text box, such as Text1.&lt;br /&gt;&lt;br /&gt;Changing the Text property of a text box does not affect the Name property of the text box. So if you want your text box to display something more exciting than Text1, you have to change the Text property.&lt;br /&gt;&lt;br /&gt;The Text property can contain anything from a blank line (which means your text box appears empty) to ordinary text, to a mass of incomprehensible text that resembles a typical computer manual.&lt;br /&gt;&lt;br /&gt;* To change the Text property of a text box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box whose Text property you want to change.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;3. Double-click on the Text property (or just click once on the Text label) and type whatever text you want to appear in your text box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want to change the contents of your text box while your program is running, you have to use BASIC code such as:&lt;br /&gt;&lt;br /&gt;txtMessage.Text = "This will now appear in the text box."&lt;br /&gt;&lt;br /&gt;Whenever you change the Text property of a text box, the new contents of the text box completely wipe out the previous contents of the text box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Aligning text in a text box:&lt;br /&gt;&lt;br /&gt;To make a text box look nice and organized, Visual Basic can align the text as left-justified, right-justified, or centered.&lt;br /&gt;&lt;br /&gt;* To align text in a text box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box whose text you want to align.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window Icon on the toolbar.)&lt;br /&gt;3. Click on the MultiLine property and set the value to True. If the MultiLine property is set to False, Visual Basic ignores any changes you make to the Alignment property.&lt;br /&gt;4. Click on the Alignment property and choose one of the following:&lt;br /&gt;&lt;br /&gt;0 - Left Justify&lt;br /&gt;1 - Right Justify&lt;br /&gt;2 - Center&lt;br /&gt;&lt;br /&gt;Changing the Alignment property doesn't align the text until you first change the text box's MultiLine property to True.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Word-wrapping text boxes:&lt;br /&gt;&lt;br /&gt;In addition to displaying text that the programmer typed into the Text property, a text box also lets users type in their own text. By default, a text box is pretty stupid at handling text. If you type text into a text box, the text box cheerfully displays the text as one huge line that scrolls endlessly out of sight. To make a text box wrap words within the box's boundaries like in a word-processor program, you have to set the text box's MultiLine property to True.&lt;br /&gt;&lt;br /&gt;* To set the MultiLine property to True for a text box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box where you want to use word-wrapping.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;3. Click on the MultiLine property and set the value to True.&lt;br /&gt;&lt;br /&gt;When a text box has a MultiLine property of True, the text box word-wraps text within the boundaries of the text box. If you change the width of a text box while your program is running, the text box automatically word-wraps the text within the new size of the text box. Now, don't you think that what computers can do nowadays is amazing?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Adding horizontal and vertical scroll bars in text boxes&lt;br /&gt;&lt;br /&gt;Word-wrapping is a fine way to display text within a text box, but if the text box isn't tall enough, the text box can't display all the text you may type in. To solve this problem, you may also have to add horizontal or vertical scroll bars.&lt;br /&gt;&lt;br /&gt;Be careful! If you add a horizontal scroll bar to a text box, that turns off all word-wrapping. When a text box uses horizontal scroll bar, the only way a user can type on the next line is to press Enter.&lt;br /&gt;&lt;br /&gt;Adding a vertical scroll bar lets users type and display more text than the text box can display. With vertical scroll bars, users can press PageUp or PageDown to display text in a text box.&lt;br /&gt;&lt;br /&gt;* To add scroll bars to a text box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box in which you want to add scroll bars.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window Icon on the toolbar.)&lt;br /&gt;3. Click on the ScrollBars property and choose one of the following:&lt;br /&gt;&lt;br /&gt;0 - None&lt;br /&gt;1 -Horizontal&lt;br /&gt;2 - Vertical&lt;br /&gt;3 - Both (horizontal and vertical scroll bars)&lt;br /&gt;&lt;br /&gt;Vertical and horizontal scroll bars work only if you have set the text box's MultiLine property to True. (Otherwise, there's no point in having scroll bars remain if you can't display more than one line of text.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Making a Password Text Box&lt;br /&gt;&lt;br /&gt;In case you work for the CIA, FBI, NSA, DIA, IRS, or any organization that spends lots of money, buries itself in secrecy, and hides behind a three-letter acronym, you may be interested in the ability of Visual Basic to create special password text boxes.&lt;br /&gt;&lt;br /&gt;Rather than display ordinary text, password text boxes mask any text you type into a text box with a single character, such as an asterisk (*).&lt;br /&gt;&lt;br /&gt;To create a password text box, you need to define the character that the text box displays when someone types in text.&lt;br /&gt;&lt;br /&gt;* To create a password text box, you need to follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box that you want to turn Into a password text box.&lt;br /&gt;&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window Icon on the toolbar.)&lt;br /&gt;&lt;br /&gt;3. Click on the MultiLine property and set the value to False.&lt;br /&gt;Always set the MultiLine property of a password text box to False, otherwise the password text box can't mask any typed characters. This is the Visual Basic way of saying that passwords can't be so long that they require two or more lines to write.&lt;br /&gt;&lt;br /&gt;4. Click on the PasswordChar property and type the masking character, such as an asterisk.&lt;br /&gt;The masking character can only be a single character.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Limiting the Length of Text&lt;br /&gt;&lt;br /&gt;To prevent people from getting too wordy, you can set the maximum length of text for a text box. This way, people can't type rambling essays about what they did last summer in your text boxes.&lt;br /&gt;&lt;br /&gt;To define the maximum number of characters that a text box can accept from the user, change the MaxLength property. If the user tries to type any characters beyond the MaxLength limit, Visual Basic beeps and accepts no more.&lt;br /&gt;&lt;br /&gt;(Alas, Visual Basic doesn't have a minimum length property. For ordinary text boxes, this isn't a problem, but if you're creating a password text box, you can bet that at least one bozo is going to choose a one-letter password that some hacker can easily guess.)&lt;br /&gt;&lt;br /&gt;* To define the maximum length of characters that a text box accepts, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box whose maximum character length you want to define.&lt;br /&gt;&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;&lt;br /&gt;3. Double-click on the MaxLength property and type any number greater than zero.&lt;br /&gt;&lt;br /&gt;A value of zero effectively means that no limit to the number of characters a user can type in a text box exists.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Changing Fonts, Sizes, and Type Styles&lt;br /&gt;&lt;br /&gt;Visual Basic normally displays text in a text box using the MS Sans Serif font, but if you want to exercise your creativity, you can choose any font stored in the memory of your computer. (The MS Sans Serif font is similar to the Helvetica font, and the Visual Basic MS Serif font is similar to the Times Roman font.)&lt;br /&gt;&lt;br /&gt;* To change the font used in a text box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box whose font you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the Font property.  Visual Basic displays a font dialog box.&lt;br /&gt;4. Click on the font you want and click on OK.  Visual Basic immediately changes the font in the text box.&lt;br /&gt;&lt;br /&gt;Be careful when using fonts. Beginners often get carried away and choose really bizarre fonts that confuse more than they clarify. Unless you have a really good reason to use a different font, just use the default font, MS Sans Serif, for most of your work.&lt;br /&gt;&lt;br /&gt;You can also change the size of your text, making your text smaller or larger. Of course, the larger the type size of your text, the larger your text box must be to show the entire text. The larger the font size, the less text you can display. To avoid confusing the user any more than necessary, use one font size for all your text boxes.&lt;br /&gt;&lt;br /&gt;* To define the font size for a text box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box whose font size you want to modify.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the Font property.  Visual Basic displays a font dialog box.&lt;br /&gt;4. Click on the font size you want and then click on OK. Visual Basic immediately changes the font size of the text displayed in your chosen text box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Changing the font and type size of text can be fun so Visual Basic also gives you additional ways to change the appearance of your text to display bold, italic, or strikeout.&lt;br /&gt;&lt;br /&gt;* To choose a font style, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box whose font that you want to modify.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the Font property.  Visual Basic displays a font dialog box.&lt;br /&gt;4. Click on the font style you want and click on OK.  Visual Basic immediately changes the font style of your chosen text box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. Give two uses for text boxes.&lt;br /&gt;&lt;br /&gt;a.To store letters from your Scrabble game and to contain words that may win you a million dollars on Wheel of Fortune.&lt;br /&gt;b. To display text on-screen and to let users type text into a program.&lt;br /&gt;c. To store all the computer books that you buy but never read, and to make cardboard forts that your children can hide in.&lt;br /&gt;d.To use as a litter box and to give your cat something to read.&lt;br /&gt;&lt;br /&gt;2. If a text box has the PasswordChar property set to * (asterisk) and the MaxLength property set to 10. what happens?&lt;br /&gt;&lt;br /&gt;a. I have to flip back through the pages of this book to find the answer, so wait while I do that.&lt;br /&gt;b. I'm not sure, but whatever happens must be important because this question is listed here.&lt;br /&gt;c. This defines the secret password that is needed to break into the Pentagon's computers.&lt;br /&gt;d. The text box accepts a maximum of 10 characters and displays an asterisk in place of an actual typed character.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Coloring Text Boxes&lt;br /&gt;&lt;br /&gt;If you loved the idea of writing in different colors with crayons when you were a kid, then you are going to love the idea of coloring your text boxes using Visual Basic.&lt;br /&gt;&lt;br /&gt;Normally, Visual Basic displays text in black against a white background. For more creativity, you can change the foreground and background colors of your text boxes.&lt;br /&gt;&lt;br /&gt;The color inside the text box (background color) is defined by the BackColor property. The color of the text itself (foreground color) is defined by the ForeColor property.&lt;br /&gt;&lt;br /&gt;To change the background or foreground color of a text box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the text box whose background or foreground color you want to modify.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the BackColor or ForeColor property and click on the Palette tab.  Visual Basic displays a color palette.&lt;br /&gt;4. Click on the color you want.  Visual Basic immediately changes the color of your chosen text box.&lt;br /&gt;&lt;br /&gt;By changing the color of your text boxes, you can highlight certain information and make it easier for the user to see (or ignore). Just remember that too many colors can be distracting and that some people may be colorblind, which means they won't experience the full effect of your program if they can't see the text displayed in certain colors. Remember, use colors sparingly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 9&lt;br /&gt;&lt;br /&gt;SCROLL BARS AND LABELS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Creating scroll bars&lt;br /&gt;Moving the scroll box&lt;br /&gt;Making labels&lt;br /&gt;Aligning and word-wrapping text&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Not all choices in life can be divided into neat categories like check boxes, radio buttons, or list boxes. Sometimes users may need to make choices that require a wide range of gradual adjustments.&lt;br /&gt;&lt;br /&gt;Think of adjusting the volume on a stereo. If the only three choices you have are soft, medium, and loud, you can't adjust the volume to your taste. That's why most stereos let you turn a knob or press a button that gradually adjusts the volume higher or lower.&lt;br /&gt;&lt;br /&gt;For minute measurements, or for moving through long lists of information, use scroll bars. Although text boxes, forms, and list boxes have built-in scroll bars, you can create separate scroll bars on your own.&lt;br /&gt;&lt;br /&gt;The CD-ROM contains a Visual Basic program showing how a vertical scroll bar works. Study the source code and modify it to see what happens.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating Scroll Bars&lt;br /&gt;&lt;br /&gt;Visual Basic lets you create two types of scroll bars: horizontal scroll bars and vertical scroll bars. Horizontal scroll bars point left and right, just like the fast-forward and rewind buttons on your VCR or tape player. Vertical scroll bars point up and down, just like the volume control on some stereos.&lt;br /&gt;&lt;br /&gt;To create a scroll bar, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click the Horizontal or Vertical Scroll Bar Icon In the Visual Basic Toolbox.&lt;br /&gt;2. Move the mouse cursor on the form to where you want to draw the scroll bar.&lt;br /&gt;3. Hold down the left mouse button and move the mouse to draw the scroll bar, then release the left mouse button.&lt;br /&gt;4. Repeat Steps 1 through 3 until you draw all the scroll bars you feel like making.&lt;br /&gt;&lt;br /&gt;If you double-click on the Horizontal or Vertical Scroll Bar icon in the Visual Basic Toolbox, Visual Basic creates a scroll bar on a form right away.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Setting scroll bar maximum and minimum values&lt;br /&gt;&lt;br /&gt;Scroll bars are actually graphical representations of numeric values. The value of a scroll bar can range from -32,768 to 32,767. These numerical values can represent anything you want, such as measurements or quantities.&lt;br /&gt;&lt;br /&gt;By default, Visual Basic sets the maximum value to 32,767 and the minimum value to 0. On horizontal scroll bars, the maximum value is represented when the scroll box is at the rightmost position on the scroll bar. The minimum value is represented when the scroll box is at the leftmost position on the scroll bar.&lt;br /&gt;&lt;br /&gt;On vertical scroll bars, the maximum value is represented when the scroll box is at the bottommost position on the scroll bar. The minimum value is represented when the scroll box is at the topmost position on the scroll bar.&lt;br /&gt;&lt;br /&gt;Obviously, the default values of 32,767 and 0 may be too extreme for most programs. To define a smaller range of values, you have to change the scroll bar's Max and Min settings.&lt;br /&gt;&lt;br /&gt;To change the Max and Min settings for a scroll bar, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the scroll bar whose Max and Min values you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click (or click once) on the Max property and type a new value.&lt;br /&gt;4. Double-click (or click once) on the Min property and type a new value.&lt;br /&gt;&lt;br /&gt;If the Min value is larger than the Max value, the scroll bar acts topsy-turvy In this case, the scroll bar represents the maximum value at the leftmost or topmost position and the minimum value at the rightmost or bottommost position.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Where does the scroll box appear in my scroll bars?&lt;br /&gt;&lt;br /&gt;By default, Visual Basic assigns scroll bars the value defined by the Min property (such as 0). This means that if your Max and Min values are positive, the scroll box always appears in the topmost position in a vertical scroll bar and the leftmost position in a horizontal scroll bar.&lt;br /&gt;&lt;br /&gt;By default, the scroll box represents the minimum value of the scroll bar. However, if you want your scroll bars to display a default value of something other than the minimum value, you have to change the scroll bar's Value property.&lt;br /&gt;&lt;br /&gt;To change the scroll bar's value, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the scroll bar whose value you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the Value property and type a new value.  Visual Basic dutifully changes the scroll bar's value while you watch.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Moving the scroll box&lt;br /&gt;&lt;br /&gt;The scroll box represents the current value of the scroll bar. To move the scroll box, users can do any of the following:&lt;br /&gt;&lt;br /&gt;Drag the scroll box within the scroll bar.&lt;br /&gt;Click on the scroll arrows at each end of the scroll bar.&lt;br /&gt;Click in the area between the scroll box and each scroll arrow.&lt;br /&gt;&lt;br /&gt;Each time the user clicks the scroll arrows, the scroll box moves a certain distance. By default, this distance is 1. Therefore, if your Min value is 0 and your Max value is 12, you have to click on the scroll arrow 12 times to move the scroll box from one end of the scroll bar to the other.&lt;br /&gt;&lt;br /&gt;To modify the distance the scroll box moves when the user clicks on a scroll arrow, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the scroll bar that you want to modify.&lt;br /&gt;2. Open the Properties window. (Press F4, choose View-&gt;Properties Window, or click on the Properties Window icon on the toolbar.)&lt;br /&gt;3. Double-click (or click once) on the SmallChange property and type a new value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Likewise, each time the user clicks on the scroll bar shaft (in the area between the scroll box and the scroll area), the scroll box moves a certain distance. By default, this distance is 1, which means that if the Min value is 0 and the Max value is 5, you have to click five times to move the scroll box from one end of the scroll bar to the other.&lt;br /&gt;&lt;br /&gt;To modify the distance the scroll box moves when the user clicks on the scroll shaft, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the scroll bar that you want to modify.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click (or click once) on the LargeChange property and type a new value.&lt;br /&gt;&lt;br /&gt;The values for LargeChange and SmallChange can vary between 1 and 32,767. The smaller the value, the smaller the distance the scroll box moves. The larger the value, the larger the distance the scroll box moves.&lt;br /&gt;&lt;br /&gt;Here's some information you may never use: You can set LargeChange or SmallChange to values greater than the Max value. This just means that when the user clicks your scroll bar, the scroll box immediately jumps to one end of the scroll bar.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Test your new found knowledge&lt;br /&gt;&lt;br /&gt;1. When can you use a scroll bar?&lt;br /&gt;&lt;br /&gt;a.When you want to give the illusion of complexity.&lt;br /&gt;b. When the user needs to choose a range of values.&lt;br /&gt;c.When you need to rewrap toilet paper that your cat unrolled onto the floor.&lt;br /&gt;d.When nothing else seems to work, and you've run out of ideas on how to make your program easier to use,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. What are the three ways to move the scroll box within a scroll bar?&lt;br /&gt;&lt;br /&gt;a. Press the arrow keys, flip the mouse upside down, or unplug the computer.&lt;br /&gt;b. Telekinesis, verbal threats, or pushing the scroll box with your finger.&lt;br /&gt;c. The scroll box never moves. This is a trick question, right?&lt;br /&gt;d. Drag the scroll box with the mouse, click the scroll arrows, or click the scroll bar shaft inside the scroll bar,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating Labels&lt;br /&gt;&lt;br /&gt;For pure decoration, you can sprinkle labels on any of your Visual Basic forms. Labels simply identify the objects on your form. In real life, you see labels all the time, such as the label MEN or WOMEN on a restroom door, FIRE EXTINGUISHER over a fire extinguisher in a public building, or POWER next to your monitor's on-and-off button. Labels simply call your attention to something you may otherwise overlook.&lt;br /&gt;&lt;br /&gt;Both text boxes (see Chapter 8) and labels can display text on-screen. The main difference is that the user can modify the text inside a text box but can't modify text inside a label.&lt;br /&gt;&lt;br /&gt;Psst, although users can't modify text in a label, BASIC code can modify the text inside a label. In this way, your labels can display changing messages to the user, such as "Sorry, that option isn't available at this time," "Now printing page 2 of 9," or "What are you, stupid or something?".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* To create a label, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Label icon in the Visual Basic Toolbox.&lt;br /&gt;2. Move the mouse cursor on the form to where you want to draw the label.&lt;br /&gt;3. Hold down the left mouse button and move the mouse to draw the label. Release the left mouse button.&lt;br /&gt;  Visual Basic draws a label with a boring caption, such as Label2.&lt;br /&gt;4. Repeat Steps 1 through 3 as often as necessary for each label you want to draw.&lt;br /&gt;&lt;br /&gt;If you double-click on the Label icon in the Visual Basic Toolbox, Visual Basic creates a label on a form right away.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Putting pretty borders around labels&lt;br /&gt;&lt;br /&gt;Normally, labels don't display any visible borders. However, you may want to put a boundary around a label to make the label easier to see. Visual Basic gives you two choices for label borders: a fixed single line or nothing at all.&lt;br /&gt;&lt;br /&gt;To create a border around a label, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the label whose border you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the BorderStyle property and choose one of the following:&lt;br /&gt;&lt;br /&gt;0 -None&lt;br /&gt;1 - Fixed Single&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the size of labels&lt;br /&gt;&lt;br /&gt;The size of a label on the screen determines the length of the caption (text) that the label can display. If a label is too small, part of the caption is cut off.&lt;br /&gt;&lt;br /&gt;Note that the label caption (the text) doesn't change in size when you change the size of a label. To change the size of a label's caption, you have to change the Font property.&lt;br /&gt;&lt;br /&gt;You may not know how much room your captions need, but to keep adjusting the width and height of your labels can be a real pain. Because computers are good at doing things that people don't want to do, Visual Basic can take care of this mundane task.&lt;br /&gt;&lt;br /&gt;Visual Basic automatically can adjust the size of a label to fit any caption you stick inside of the label. Such automatic adjusting labels are perfect for displaying messages whose length may vary.&lt;br /&gt;&lt;br /&gt;An automatic adjusting label grows or shrinks horizontally to match the leength of the label's caption. So if you have a really long caption, the label cheerfully expands in size and disappears off the right side of the screen. To make an automatic adjusting label word-wrap text, you have to set the label's WordWrap property to True.&lt;br /&gt;&lt;br /&gt;To create an automatic adjusting label, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the label that you want to automatically adjust to the size of its caption.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the AutoSize property and choose True.&lt;br /&gt;&lt;br /&gt;The advantage of automatic adjusting labels is that you can use BASIC code to give a label captions of various sizes without ever worrying that a particular caption isn't going to fit. The disadvantage is that you don't have control over the label's maximum size. If you're not careful, a label can get too big and cover other parts of your user interface.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Aligning text within a label&lt;br /&gt;&lt;br /&gt;To make your label captions look nice and organized, Visual Basic offers three options for aligning captions.&lt;br /&gt;&lt;br /&gt;Left-justified&lt;br /&gt;Right-justified&lt;br /&gt;Centered&lt;br /&gt;&lt;br /&gt;To align a caption in a label, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the label whose caption you want to align.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the Alignment property and choose one of the following:&lt;br /&gt;&lt;br /&gt;0 - Left Justify&lt;br /&gt;1 - Right Justify&lt;br /&gt;2 - Center&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Word-wrapping labels&lt;br /&gt;&lt;br /&gt;If you set a label's AutoSize property to True, the label expands horizontally as long as you keep stuffing it with text. However, if you want a label to expand vertically instead, you have to set both the label's AutoSize and WordWrap properties to True.&lt;br /&gt;&lt;br /&gt;Setting both the AutoSize property and the WordWrap property to False means that long captions may be cut off at the bottom if your label isn't tall enough.&lt;br /&gt;&lt;br /&gt;Setting AutoSize to False and WordWrap to True has the same effect as setting both AutoSize and WordWrap to False.&lt;br /&gt;&lt;br /&gt;Setting AutoSize to True and WordWrap to False means that the label expands horizontally to fit an entire caption. However, the label shows only one line of the caption.&lt;br /&gt;&lt;br /&gt;Setting both AutoSize and WordWrap to True means that the label grows or shrinks vertically to fit a caption.&lt;br /&gt;&lt;br /&gt;To set the WordWrap property for a label to True, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the label in which you want to use word-wrapping.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the WardWrap property and set the value to True.&lt;br /&gt;&lt;br /&gt;When creating labels that adjust to the size of a caption, be careful that your labels don't accidentally grow over and cover up other parts of your user interface. Otherwise, you may really confuse someone who is trying to use your program.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 10&lt;br /&gt;&lt;br /&gt;PRETTY PICTURES AND OBJECTS FROM GEOMETRY&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Creating picture boxes and image boxes&lt;br /&gt;Making the picture boxes and image boxes fit their contents&lt;br /&gt;Creating geometric shapes&lt;br /&gt;Altering the appearance of lines, circles, and other shapes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can sprinkle labels and pictures on any of your Visual Basic forms. AIthough pictures can make your forms look nice, they also can be an actual part of your program.&lt;br /&gt;&lt;br /&gt;For example, a picture on the front of a road map showing a smiling gas station attendant with the label "Always Trust Your Car to the Man Who Wears the Star" is superfluous and decorative. However, a road map using pictures to show city highways and major side streets can be integral and necessary.&lt;br /&gt;&lt;br /&gt;If you sprinkle plenty of labels and pictures in your user interface, your program is going to be easier to use and understand. After all, that's the purpose of creating a user interface in the first place.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating Pictures&lt;br /&gt;&lt;br /&gt;Visual Basic provides two ways to display pictures on the screen:&lt;br /&gt;&lt;br /&gt;In a picture box&lt;br /&gt;In an image box&lt;br /&gt;&lt;br /&gt;Use a picture box to display graphics or to group buttons together. Use an image box to display graphics or to create image buttons. To create a picture box or image box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Picture Box or Image Box icon in the Visual Basic Toolbox.&lt;br /&gt;2. Using the mouse, hold down the left mouse button on the form and drag to where you want to draw the picture box or Image box, and draw the box by dragging the mouse.&lt;br /&gt;3. Repeat Steps 1 and 2 until you draw all the picture boxes or Image boxes you need.&lt;br /&gt;&lt;br /&gt;If you double-click on the Picture Box or Image Box icon in the Visual Basic Toolbox, Visual Basic draws the picture box or image box on the form for you automatically. After drawing a picture box or image box, its size will likely change depending on the size of the graphic image you want to put in it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Displaying pictures in picture boxes or image boxes&lt;br /&gt;&lt;br /&gt;After you create a picture box or an image box, putting a picture in the box is only natural. (Why else do you create the box?) Picture boxes and image boxes can display three types of graphics images:&lt;br /&gt;&lt;br /&gt;Bitmap files: (BMP or DIB file extensions) Consist of patterns of dots, or pixels, which are the types of files created by paint programs, such as Microsoft Paint. If you enlarge a bitmap image, the image tends to look grainy and ugly.&lt;br /&gt;&lt;br /&gt;Icon files: (ICO file extensions) Special kinds of bitmap files with a maximum size of 32 x 32 pixels.&lt;br /&gt;&lt;br /&gt;Metafiles: (WMF file extensions) Images created by lines and geometric shapes that most people have forgotten about since high-school geometry. These types of files are created by draw programs, such as CorelDRAW.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To load a picture in a picture box or image box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the picture box or image box into which you want to load a graphics file.&lt;br /&gt;(This assumes that you've already drawn the picture box or image box on a form. Otherwise, draw the picture box or image box as explained in the Creating Pictures section.)&lt;br /&gt;&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;&lt;br /&gt;3. Double-click on the Picture property in the Properties window.  Visual Basic displays the Load Picture dialog box.&lt;br /&gt;&lt;br /&gt;4. Click on the picture file you want to load.  Visual Basic instantly loads the picture in the picture box or image box.&lt;br /&gt;&lt;br /&gt;In addition to loading pictures by using the Properties window, you also can load and remove pictures while your program is running (during runtime). To load a picture into a picture box or image box, use the following LoadPicture command:&lt;br /&gt;&lt;br /&gt;ImgGreeting.Picture = LoadPicture("c:\graphics\martian.bmp")&lt;br /&gt;&lt;br /&gt;The LoadPicture command specif ies the exact drive, directory, and file to store in the Picture property of a picture box or an image box.&lt;br /&gt;&lt;br /&gt;To remove a picture from a picture box or image box during run time, use the LoadPicture command as follows:&lt;br /&gt;&lt;br /&gt;ImgGreeting.Picture = LoadPicture("")&lt;br /&gt;&lt;br /&gt;This statement essentially loads a blank image into the Picture property of a picture box or image box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Putting nifty borders around picture boxes and image boxes&lt;br /&gt;&lt;br /&gt;To define the edge of your picture box or image box, Visual Basic can display a border. By default, neither type of box displays a border. To change the border around a picture box or image box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the picture box or image box whose border you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the BorderStyle property and choose one of the following:&lt;br /&gt;&lt;br /&gt;0 - None&lt;br /&gt;1- Fixed Single&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Changing the Size of Picture Boxes or Image Boxes&lt;br /&gt;&lt;br /&gt;Generally, the size of picture boxes or image boxes has no effect on the size of the graphics image that the picture box or image box displays, with two exceptions:&lt;br /&gt;&lt;br /&gt;Metafile graphics always change size to fit within a picture box or an image box.&lt;br /&gt;If an image box's Stretch property is set to True, bitmap and !con graphics change size to fit within the image box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the size of graphics images&lt;br /&gt;&lt;br /&gt;Bitmap and icon graphics appear in their original size no matter what the size of the picture box or image box (unless the Stretch property is set to True). Therefore, if you create a huge picture box but load in a tiny bitmap graphics image, all you see is a tiny bitmap graphics image with lots of empty space around the image.&lt;br /&gt;&lt;br /&gt;Unlike bitmap or icon graphics, metafiles expand or shrink to fill an entire picture box or expand to their original size to fill an entire image box. To change the size of a metafile, just change the size of the picture box or image box holding the metafile.&lt;br /&gt;If you use a picture box, you can never (and I mean never) change the size of bitmap or icon graphics. On the other hand, if you use an image box, you can change the size of bitmap or icon graphics by changing the image box's Stretch property. To change the size of bitmap or icon graphics in an image box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the image box whose Stretch property you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the Stretch property and set the value to True.&lt;br /&gt;&lt;br /&gt;After an image box has the Stretch property set to True, you can adjust the size of bitmap or icon graphics just by changing the size of the image box. (Isn't it amazing what $2,000 computers can do?)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Automatically changing the size of picture boxes&lt;br /&gt;&lt;br /&gt;If you're too busy to bother creating and adjusting the size of your picture boxes, let Visual Basic do such formatting automatically. All you need to do is set the AutoSize property to True. The moment you load the bitmap or icon graphics image into a picture box, the picture box immediately shrinks or expands to fit tightly around the graphics image, just like shrink-wrap around a box of floppy disks. To make a picture box automatically adjust its size around a graphics image, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the picture box whose AutoSize property you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the AutoSize property and set the value to True.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Coloring Picture Boxes&lt;br /&gt;&lt;br /&gt;Visual Basic usually displays a plain gray background in picture boxes. If your graphics images fill up the entire picture box, the background color is irrelevant. But if the graphics image isn't big enough, the background color can be seen.&lt;br /&gt;&lt;br /&gt;The background color is defined by the BackColor property. With a tasteful background color, you can highlight your graphics and make them more colorful.&lt;br /&gt;&lt;br /&gt;To change the background color of a picture box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the picture box whose background color you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the BackColor property in the Properties window and then click on the Palette tab.&lt;br /&gt;4. Click on the color you want.  Visual Basic instantly obeys.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. Which lets you change the size of a bitmap or icon graphic: a picture box or an image box?&lt;br /&gt;&lt;br /&gt;a. Neither. Bitmaps and icon graphics are perfect just the way they are, and to believe that you can change anything for the better is blasphemous.&lt;br /&gt;b. A picture box, because I don't have the slightest idea what the difference is.&lt;br /&gt;c. An image box, but only if you set the Stretch property to True.&lt;br /&gt;d. This question is too hard. I need a nap.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. What are the three types of graphics files you can load in a picture box or image box?&lt;br /&gt;&lt;br /&gt;a. Bitmaps, icons, and metafiles.&lt;br /&gt;b, Bitmaps, graffiti, and forgeries of famous paintings.&lt;br /&gt;c. Bitmaps, centerfolds, and home videos.&lt;br /&gt;d. Bigfoot, UFOs, and grainy pictures of Elvis walking through downtown Manhattan.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Lines. Circles, and Other Nightmares from Geometry&lt;br /&gt;&lt;br /&gt;What performs absolutely no useful function except a decorative one? If you answered, "The vice president of the United States," you're close, but the real answer is the parts of a user interface that make the interface look more attractive.&lt;br /&gt;&lt;br /&gt;The prettier something looks, the friendlier people feel toward the pretty something, which explains why physically attractive people can go through life without having to pay their own bills. So if you make your user interface pretty, the likely consequence is that more people are actually going to try to use your user interface.&lt;br /&gt;&lt;br /&gt;Visual Basic provides seven objects for adding visual makeup to your user interface. These objects are as follows:&lt;br /&gt;&lt;br /&gt;Lines&lt;br /&gt;Squares&lt;br /&gt;Rectangles&lt;br /&gt;Ovals&lt;br /&gt;Circles&lt;br /&gt;Rounded rectangles&lt;br /&gt;Rounded squares&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Creating lines&lt;br /&gt;&lt;br /&gt;Lines are useful for underlining or separating items on the screen. To create a line, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Line Icon in the Visual Basic Toolbox.&lt;br /&gt;2. On the form, move the mouse to where you want the line to start.&lt;br /&gt;3. Hold down the mouse button and move the mouse to where you want the line to end.&lt;br /&gt;4. Release the mouse button.&lt;br /&gt;&lt;br /&gt;If you double-click on the Line icon in the Visual Basic Toolbox, Visual Basic draws a line on the form for you automatically.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Creatinig circles and rectangles&lt;br /&gt;&lt;br /&gt;Circles and rectangles can enclose and separate items on the screen. Or they can be an excuse for doodling on company time when the boss thinks that you're really writing a program. To create a circle or rectangle, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Shape icon in the Visual Basic Toolbox.&lt;br /&gt;2. On the form, move the mouse to where you want the top-left corner of the circle or rectangle to appear.&lt;br /&gt;3. Hold down the left mouse button and move the mouse to where you want the bottom-right corner of the circle or rectangle to end.&lt;br /&gt;4. Release the mouse button. At this point, Visual Basic displays a rectangle on the screen. If that's what you want, stop right here; otherwise, continue to Step 5.&lt;br /&gt;5. Open the Properties window.&lt;br /&gt;6. Click on the Shape property and click on the arrow in the Settings Box. Visual Basic displays a list of shapes to choose from:&lt;br /&gt;&lt;br /&gt;0 - Rectangle&lt;br /&gt;1 - Square&lt;br /&gt;2 - Oval&lt;br /&gt;3 - Circle&lt;br /&gt;4 - Rounded Rectangle&lt;br /&gt;5 - Rounded Square&lt;br /&gt;&lt;br /&gt;7. Click on the shape you want to create.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the color of lines and other shapes&lt;br /&gt;&lt;br /&gt;Visual Basic usually draws lines, circles, and rectangles by using a solid black line. Although boring ol' black is okay for most purposes, sometimes a little color can spice up your user interface. You define the color of a line by using the BorderColor property. To change the line color of a line or shape, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the line or shape whose line color you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the BorderColor property in the Properties window and click on the Palette tab.&lt;br /&gt;4. Click on the color you want.  Visual Basic instantly obeys.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the thickness of titles&lt;br /&gt;&lt;br /&gt;Lines can be from 1 to 8,192 in thickness. (The numbers are relative and not related to an actual unit of measurement.) Any line thicker than 100, however, tends to look like a fat sausage on the screen. To change the thickness of a line, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the line or shape whose line thickness you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the BorderWidth property and type a new value.  Visual Basic immediately changes the thickness of your line.&lt;br /&gt;4. Marvel at the wonder of technology and how one day you are going to be able to tell your children, "When I was going to school, we had to draw lines using an Etch-A-Sketch. You kids have line drawing so easy with computers and everything."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the appearance of lines, circles, and rectangles&lt;br /&gt;&lt;br /&gt;Visual Basic usually draws lines, circles, and rectangles with a solid line. Although a solid line is easier to see, you may want to create special effects that look like perforations on a page or Morse code. Visual Basic provides the following seven line styles.&lt;br /&gt;&lt;br /&gt;Transparent&lt;br /&gt;Solid (the default)&lt;br /&gt;Dash&lt;br /&gt;Dot&lt;br /&gt;Dash-Dot&lt;br /&gt;Dash-Dot-Dot&lt;br /&gt;Inside Solid&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If the thickness of a line is greater than 1, the only BorderStyle settings you can use are 1 (Solid) and 6 (Inside Solid). If you use a different BorderStyle setting, nothing happens and you may think that Visual Basic is broken.&lt;br /&gt;&lt;br /&gt;To confuse matters even more, the appearance of a line is determined by the BorderStyle property. Normally, you think of a border as something surrounding an object. But in the Visual Basic world of twisted logic, the BorderStyle defines the appearance of a line. To change the appearance of lines by themselves or lines that make up your circles or rectangles, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the line, circle, or rectangle whose appearance you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the BorderStyle property and choose one of the following:&lt;br /&gt;&lt;br /&gt;0 - Transparent&lt;br /&gt;1 - Solid&lt;br /&gt;2 - Dash&lt;br /&gt;3 - Dot&lt;br /&gt;4 - Dash-Dot&lt;br /&gt;5 - Dash-Dot-Dot&lt;br /&gt;6 - Inside Solid&lt;br /&gt;&lt;br /&gt;If you choose any style from 2 to 5, set the BorderWidth property to 1. Otherwise, Visual Basic displays the BorderStyle you selected as a solid line.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the size and position of lines&lt;br /&gt;&lt;br /&gt;When you create a line, try to draw the line as the exact size you need. (What's the point of drawing a long line when you know that you really need a short one?) Visual Basic provides two ways to change the size and position of a line:&lt;br /&gt;&lt;br /&gt;You can use the mouse.&lt;br /&gt;You can change the X1, X2, Y1, and Y2 properties in the Properties window.&lt;br /&gt;&lt;br /&gt;The mouse is the quickest and sloppiest way to change the size and position of a line. But if you insist on using the mouse, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the line that you want to change.&lt;br /&gt;&lt;br /&gt;Visual Basic displays a blue rectangle at each end of the line. These rectangles are called handles. (Because clicking on a single line can be an exercise in frustration, you can also move the mouse above the line, hold down the mouse button, move the mouse below the line, and release the mouse button.)&lt;br /&gt;&lt;br /&gt;2. Move the mouse over one of these handles until the mouse pointer turns into a crosshair.&lt;br /&gt;&lt;br /&gt;3. Hold down the mouse button and move the mouse to adjust the line. When the line takes the shape you want, release the mouse button.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you prefer not to soil your hands by touching the mouse, you can use a more refined method favored by people of distinction everywhere: Use the Properties window. To change the size of a line using the Properties window, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the line you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the X1 property and type a new value.&lt;br /&gt;4. Double-click on the Y1 property and type a new value.&lt;br /&gt;5. Double-click on the X2 property and type a new value.&lt;br /&gt;6. Double-click on the Y2 property and type a new value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing the size of circles, rectangles, and other shapes&lt;br /&gt;&lt;br /&gt;Happily, changing the size of circles, rectangles, and other shapes is much easier than changing the size of a line. You can use the mouse or the Properties window to change the size of a shape. To change the size of a shape using the mouse, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the shape you want to change.  Visual Basic displays black handles around the shape.&lt;br /&gt;2. Move the mouse over one of these handles until the mouse pointer turns into a double arrow.&lt;br /&gt;3. Hold down the mouse button and move the mouse. When the object is the shape you want, release the mouse button.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For those who prefer to use a keyboard at the expense of ease and convenience, you can change the size of a shape also by using the Properties window. To change the size of a shape by using the Properties window, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the shape you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the Height property and type a new value.&lt;br /&gt;4. Double-click on the Width property and type a new value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Filling Shapes with Colours and Pretty Patterns&lt;br /&gt;&lt;br /&gt;The inside of a shape is usually empty, blank, and boring. For more excitement than most people's hearts can handle, you can change the color and pattern of the inside of a shape. Visual Basic provides eight patterns that you can use to fill the inside of a shape. The pattern is defined by the FillStyle property. The color of the pattern is defined by the FillColor property.&lt;br /&gt;&lt;br /&gt;To define the fill pattern of a shape, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the shape whose inside pattern you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the FillStyle property and choose one of the following:&lt;br /&gt;&lt;br /&gt;0 - Solid&lt;br /&gt;1 - Transparent&lt;br /&gt;2 - Horizontal Line&lt;br /&gt;3 - Vertical Line&lt;br /&gt;4 - Upward Diagonal&lt;br /&gt;5 - Downward Diagonal&lt;br /&gt;6 - Cross&lt;br /&gt;7 - Diagonal Cross&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To change the color of a shape's fill pattern, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the shape whose pattern color you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Double-click on the FillColor property in the Properties window and click on the Palette tab.&lt;br /&gt;4. Click on the color you want. Visual Basic obeys instantly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Changing the Background Color of Shapes&lt;br /&gt;&lt;br /&gt;In addition to changing the color of the fill pattern inside a shape (fill color) and the line color that makes up a shape (border color), you can also change a shape's background color (back color). Confused?&lt;br /&gt;&lt;br /&gt;Before you can change the background color of a shape, you must set the shape's BackStyle property to Opaque. (The default is Transparent, which means that the shape is invisible. If the shape is invisible, changing the color isn't going to do a thing.)&lt;br /&gt;&lt;br /&gt;To change the background color of a shape, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the shape whose background color you want to change.&lt;br /&gt;2. Open the Properties window.&lt;br /&gt;3. Click on the BackStyle property and set the value to Opaque.&lt;br /&gt;4. Double-click on the BackColor property in the Properties window and click on the Palette tab.&lt;br /&gt;5. Click on the color you want.  Visual Basic instantly obeys.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Try Changing an Object's Size for Yourself&lt;br /&gt;&lt;br /&gt;The following sample program lets you change a circle's thickness by using the horizontal scroll bar. To see for yourself, create three objects with the following property settings.&lt;br /&gt;&lt;br /&gt;If you don't feel like creating the program listed below, just load and run the SHAPE.VBP file off the enclosed CD-ROM.&lt;br /&gt;&lt;br /&gt;Object - Form&lt;br /&gt;Property - Caption&lt;br /&gt;Setting - The Shrinking/Growing Circle&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Shape1:&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - shpCircle&lt;br /&gt;&lt;br /&gt;Property - Height&lt;br /&gt;Setting - 1455&lt;br /&gt;&lt;br /&gt;Property - Left&lt;br /&gt;Setting - 1440&lt;br /&gt;&lt;br /&gt;Property - Shape&lt;br /&gt;Setting - 3 (Circle)&lt;br /&gt;&lt;br /&gt;Property - Top&lt;br /&gt;Setting - 1080&lt;br /&gt;&lt;br /&gt;Property - Width&lt;br /&gt;Setting - 1695&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - HScroll1:&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - hsbCircle&lt;br /&gt;&lt;br /&gt;Property - Height&lt;br /&gt;Setting - 255&lt;br /&gt;&lt;br /&gt;Property - Left&lt;br /&gt;Setting - 720&lt;br /&gt;&lt;br /&gt;Property - Max&lt;br /&gt;Setting - 20&lt;br /&gt;&lt;br /&gt;Property - Min&lt;br /&gt;Setting - 1&lt;br /&gt;&lt;br /&gt;Property - Top&lt;br /&gt;Setting - 360&lt;br /&gt;&lt;br /&gt;Property - Width&lt;br /&gt;Setting - 3255&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Double-click on the horizontal scroll bar and type the following in the Code window:&lt;br /&gt;&lt;br /&gt;Private Sub hsbCircle-Change()&lt;br /&gt;  shpCircle.BorderWidth = hsbCircle.Value&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;To run the program, press F5. Then click on the horizontal scroll bar and watch the circle grow before your eyes. Amazing! Astound your friends! Be the hit of your next cocktail party! Visual Basic reveals it all!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ PART III&lt;br /&gt;&lt;br /&gt;MAKING MENUS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this part ....&lt;br /&gt;&lt;br /&gt;Pull-down menus are a fancy way to organize all the options available in your program. That way, if users want to do something with your program, they just have to choose the right pull-down menu and pick the appropriate command.&lt;br /&gt;&lt;br /&gt;This part of the book shows you how to make pull-down menus in your own programs. Believe it nor not, making your own menus is actually simple. (The hard part is making your program actually work the way you want it to, which is something that even eludes the grasp of the Microsoft programmers).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 11&lt;br /&gt;&lt;br /&gt;CREATING AND EDITING PULL-DOWN MENUS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Creating menus and menu titles&lt;br /&gt;Adding separator bars&lt;br /&gt;Using shortcut keys and check marks&lt;br /&gt;Dimming or making menu commands disappear&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Generally, every menu bar contains the following menu titles: File, Edit, Window, and Help. The File menu appears on the far left, the Edit menu appears next, the Window menu appears next to last, and the Help menu appears last. In between the Edit and Window menus are menu titles unique to a particular program.&lt;br /&gt;&lt;br /&gt;Every menu consists not only of menu titles but also menu commands. The menu titles appear at the top of the screen in a menu bar, and the menu commands appear in pull-down menus.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** The Basic Elements of a Menu Bar&lt;br /&gt;&lt;br /&gt;Before creating menus, decide how many menu titles your program needs and where each command belongs in your menu titles.&lt;br /&gt;&lt;br /&gt;Visual Basic can create menus for you if you use the VB Application Wizard to help you create your program (as I explain in Chapter 3).&lt;br /&gt;&lt;br /&gt;The File menu needs to contain commands directly related to file operations, such as opening, closing, saving, and printing files, as well as quitting the program so that you can go to the kitchen and get something to eat.&lt;br /&gt;&lt;br /&gt;The Edit menu, needs to contain commands related to editing (duh), such as Undo (and Redo), Cut, Copy, Paste, Clear, and Select All.&lt;br /&gt;&lt;br /&gt;The Window menu needs to contain commands related to opening, closing, arranging, and switching among different windows.&lt;br /&gt;&lt;br /&gt;The Help menu needs to contain commands for getting help from the program. Typical help commands include a table of contents to the help system, an alphabetical index, propaganda about product support, and a useless About command that displays information the programmers think looks cute on the screen.&lt;br /&gt;&lt;br /&gt;Any other menus you sandwich between the Edit and the Window menu titles need to clearly organize the type of commands hidden underneath.&lt;br /&gt;&lt;br /&gt;For example, many word-processing programs have a Tools menu title that displays commands for grammar checking, hyphenation, macro creation, and other commands that 99 percent of the working population of America is never going to use.&lt;br /&gt;&lt;br /&gt;If your menu titles are unique to your particular program (in other words, they're not the standard Edit or Window menu titles found on other programs), try to make your menu titles descriptive - that way users will have a better idea where to find a specific command.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Making Menus for Your User Interface&lt;br /&gt;&lt;br /&gt;To create and edit menus, you have to open the Menu Editor window. (If you use the VB Application Wizard, Visual Basic can create standard pull-down menus for you automatically, but you still need to use the Menu Editor window to edit your menus.)&lt;br /&gt;&lt;br /&gt;In the name of freedom and confusion, Visual Basic provides three ways to display the Menu Editor window:&lt;br /&gt;&lt;br /&gt;Press CtrI+E.&lt;br /&gt;Choose Tools-&gt;Menu Editor.&lt;br /&gt;Click on the Menu Editor icon on the toolbar.&lt;br /&gt;&lt;br /&gt;You can create one set of pull-down menus for each form. So if your program contains two forms, you can have a completely different menu for each form. Of course, having multiple menus may confuse users, but if you're a typical programmer who generally doesn't care what users think, this isn't going to bother you one bit.&lt;br /&gt;&lt;br /&gt;The Menu Editor window is where you define everything to create your menus. The first two things you have to define for all your menu titles are their names and their captions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Naming menus&lt;br /&gt;&lt;br /&gt;Every menu titile and menu command has a caption and a name. The caption is what appears on the screen. The name never appears on the screen; you use the name to identify which menu command the user chooses.&lt;br /&gt;&lt;br /&gt;Captions can be up to 40 characters long, including numbers, spaces, punctuation, and the underscore character (_). Of course, the longer your caption is, the more space the caption is going to gobble up on the screen.&lt;br /&gt;&lt;br /&gt;Because captions appear on the screen, you can use an ampersand (&amp;amp;) in your captions, such as &amp;amp;File or T&amp;amp;able. Why do you want to do such a silly thing? An ampersand in front of any letter makes that letter underlined in the caption.&lt;br /&gt;&lt;br /&gt;When a letter is underlined in a menu title, users can pull down that menu by pressing and holding down the Alt key and pressing whatever letter is underlined. If a menu title is named &amp;amp;Window, the caption appears on the screen as Window, and users can pull the menu down by pressing Alt+W. Offering this option can help users choose menu titles by using these keyboard shortcuts rather than using the mouse.&lt;br /&gt;&lt;br /&gt;When the ampersand underlines a letter in a menu command caption, users can choose the caption simply by typing the underlined letter without pressing Alt. So if a menu command caption is named &amp;amp;New, the caption appears on the screen as New. Users can choose that caption by first pulling down the menu and then pressing N.&lt;br /&gt;&lt;br /&gt;Names, like captions, can be up to 40 characters long, including numbers and the underscore character. Because names never appear on the screen, you can make them as long as you want until you reach the magic number of 40.&lt;br /&gt;&lt;br /&gt;Unlike captions, names cannot include spaces, punctuation, or words that the editors at IDG Books Worldwide, Inc., deem offensive and, hence, may harm sales of this book.&lt;br /&gt;&lt;br /&gt;For menu names, Visual Basic recommends that the name begins with mnu, as in the following examples:&lt;br /&gt;&lt;br /&gt;mnuFile&lt;br /&gt;mnuWindow&lt;br /&gt;mnuFileOpen&lt;br /&gt;&lt;br /&gt;Visual Basic doesn't care whether you use uppercase or lowercase consistently. If you really want to, you can use the following names for menus:&lt;br /&gt;&lt;br /&gt;MNufiLEmNuwINDow&lt;br /&gt;MNUfileOPEN&lt;br /&gt;&lt;br /&gt;Such names are not only hard to read, but the scattered casing also makes you look illiterate. So for consistency (and to protect your image), the best method is to adopt Microsoft's style and stick with this style whenever you use Visual Basic.&lt;br /&gt;&lt;br /&gt;To identify menu commands that appear under certain menu titles, include the menu title as part of a menu command's name. For example, if the menu title File is named mnuFile, menu commands (such as the Open, Save, and Exit commands) that appear in the File menu should have names like mnuFileOpen, mnuFileSave, and mnuFileExit.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Making menu tittes&lt;br /&gt;&lt;br /&gt;Creating pull-down menus for your Visual Basic programs is a two-step process:&lt;br /&gt;&lt;br /&gt;First you create the menu titles that appear in the menu bar.&lt;br /&gt;Next you create the menu commands that appear under each menu title.&lt;br /&gt;&lt;br /&gt;To create menu titles that appear in the menu bar at the top of a form, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form to which you want to add menu titles.&lt;br /&gt;&lt;br /&gt;2. Open the Menu Editor window by pressing CtrI+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;&lt;br /&gt;3. In the Caption text box of the Menu Editor window, type the menu title that you want to have appear on the screen, including any ampersands.&lt;br /&gt;&lt;br /&gt;As you type, Visual Basic displays your caption in the Menu control list box.&lt;br /&gt;&lt;br /&gt;4. Press Tab to move the cursor to the Name text box.&lt;br /&gt;&lt;br /&gt;5. Type your menu name, beginning with mnu followed by the menu caption itself, such as mnuFile or mnuFiIePrint.&lt;br /&gt;&lt;br /&gt;You can mix uppercase and lowercase, but for consistency with Visual Basic programmers around the world, stick with the style mnuFileExit where you use uppercase letters to identify separate words such as File and Exit.&lt;br /&gt;&lt;br /&gt;6. Press Enter or click on Next to create the next menu title.&lt;br /&gt;&lt;br /&gt;7. Repeat Steps 3 through 6 until you create all the menu titles that you want to have appear at the top of the screen in the menu bar.&lt;br /&gt;&lt;br /&gt;8. Click on OK.&lt;br /&gt;Visual Basic displays your menus at the top of the form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Adding and deleting menu tittes and commands&lt;br /&gt;&lt;br /&gt;Creating menu titles is fairly straightforward. Unfortunately, nothing in life is permanent, and that can include your menu titles. For that reason, Visual Basic gives you the option of adding or deleting menu titles.&lt;br /&gt;&lt;br /&gt;To add another menu title to a form, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form to which you want to add another menu title.&lt;br /&gt;2. Open the Menu Editor window by pressing CtrI+E, choosing Tools-&gt;Menu. Editor or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;3. Click on the menu title that you want to appear to the right of your new menu title.&lt;br /&gt;4. Click on Insert.&lt;br /&gt;Visual Basic pushes the previously highlighted menu title down and highlights a blank line.&lt;br /&gt;5. Click on the Caption text box and type your new menu title caption, such as &amp;amp;Tools or Forma&amp;amp;t.&lt;br /&gt;6. Press Tab to move the cursor to the Name text box and type your new menu name (such as mnuTools or mnuFormat) and then press Enter.&lt;br /&gt;7. Click on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To delete a menu title, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form from which you want to delete a menu title.&lt;br /&gt;2. Open the Menu Editor window by pressing CtrI+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor Icon on the toolbar.&lt;br /&gt;3. Click on the menu title you want to delete.&lt;br /&gt;4. Click on Delete. Visual Basic deletes the highlighted menu title.&lt;br /&gt;5. Click on OK.&lt;br /&gt;&lt;br /&gt;When you delete a menu title or menu command, any BASIC code you've written for that particular menu command still exists, so you'll have to delete this code as well.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating Menu Commands under Menu Titles&lt;br /&gt;&lt;br /&gt;After you create the menu titles that appear in the menu bar at the top of a form, the next step is to create the commands to appear underneath each menu title.&lt;br /&gt;&lt;br /&gt;In the Menu control list box, all flush left items are menu titles that appear in the menu bar. Indented items are menu commands that appear below a menu title.&lt;br /&gt;&lt;br /&gt;To create menu commands, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form to which you want to add menu commands.&lt;br /&gt;2. Open the Menu Editor window by pressing CtrI+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;Visual Basic obediently opens the Menu Editor window.&lt;br /&gt;3. Click underneath the menu title where you want to display the menu commands. For example, if you want to put menu commands underneath the File menu title, click underneath the File menu title.&lt;br /&gt;4. Click on Insert.&lt;br /&gt;5. Click on the Caption text box and type the menu command's caption, such as &amp;amp;Save or &amp;amp;Print.&lt;br /&gt;6. Press Tab to move the cursor to the Name text box.&lt;br /&gt;7. Type the menu command's name, such as mnuFiIeSave or mnuFilePrint.&lt;br /&gt;8. Click on the right-arrow button to indent the menu command. This indentation shows you that an item is a menu command and not a menu title. (How's that for similar but confusing terms?)&lt;br /&gt;9. Click on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;**  Moving Menu Titles and Commands&lt;br /&gt;&lt;br /&gt;When you create pull-down menus, you can always edit and change them at a later time. Visual Basic gives you four ways to move your menu titles and commands around:&lt;br /&gt;&lt;br /&gt;Up&lt;br /&gt;Down&lt;br /&gt;Indent right&lt;br /&gt;Indent left&lt;br /&gt;&lt;br /&gt;In the Menu Editor window, Visual Basic provides four arrow buttons that enable you to move items up, down, right, or left. Moving an item up or down in the Menu control list box simply rearranges that item's position on the menu bar or in a pull-down menu.&lt;br /&gt;&lt;br /&gt;To move an item up or down in the Menu control list box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form containing the menu titles or commands that you want to rearrange.&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;3. Click on the item in the Menu Editor window that you want to move up or down.&lt;br /&gt;4. Click on the up-arrow button to move the item up, or click on the down-arrow button to move the item down.&lt;br /&gt;5. Click on OK when you're done goofing around&lt;br /&gt;&lt;br /&gt;When within the Menu Editor window, indenting an item to the right turns a menu title into a menu command. Likewise, while within this window, indenting an item to the left turns a menu command into a menu title.&lt;br /&gt;&lt;br /&gt;To indent an item left or right in the Menu control list box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form containing the menu titles or commands that you want to rearrange.&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor Icon on the toolbar. Visual Basic obediently opens the Menu Editor window.&lt;br /&gt;3. Click on the item that you want to indent left or right.&lt;br /&gt;4. Click on the right-arrow button to indent the Item to the right, or click on the left-arrow button to indent the item to the left.&lt;br /&gt;5. Click on OK&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Making Menus Pretty&lt;br /&gt;&lt;br /&gt;Pull-down menus conveniently list commands where users can (hopefully) find them. To make your menus even easier to use, Visual Basic also lets you separate menu commands with separator bars, display check marks next to currently used menu commands, add shortcut keys so users don't have to use your pull-down menus at all, and dim or remove menu items altogether.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Putting separator bars in menus&lt;br /&gt;&lt;br /&gt;Separator bars are lines in a pull-down menu that divide groups of commands. Generally, separator bars group related items so that users can find the command they want.&lt;br /&gt;&lt;br /&gt;To create a separator bar, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form containing the menus to which you want to add separator bars.&lt;br /&gt;&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;&lt;br /&gt;3. Click on the item in the Menu Editor window that you want to appear directly below the separator bar.&lt;br /&gt;&lt;br /&gt;4. Click on Insert so that Visual Basic displays an empty line.&lt;br /&gt;If necessary, you may have to click on the right- or left-arrow buttons to make the separator bar appear on the same level as the items the bar is dividing.&lt;br /&gt;&lt;br /&gt;5. Click on the Caption text box, type a hyphen (-), and press Tab to move the cursor to the Name text box.&lt;br /&gt;&lt;br /&gt;6. Type any name you want to identify the separator bar.&lt;br /&gt;Ideally, the name should include part of the menu title, such as mnuFileBar1 or mnuEditBar3.&lt;br /&gt;&lt;br /&gt;7. Click on OK to close the Menu Editor window.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. Why are pull-down menus so usefull?&lt;br /&gt;&lt;br /&gt;a. They hide commands so that users can't find them.&lt;br /&gt;b.They make programs easier to use by organizing related commands in easy-to-find menus.&lt;br /&gt;c. Pull-down menus are useful for confusing people while giving them the illusion that it's their fault for not knowing how to use your program in the first place.&lt;br /&gt;d. If pull-down menus are so useful, how come people still need to buy 400-page books to teach them how to use these stupid programs?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. How can you create and edit pull-down menus in a Visual Basic program?&lt;br /&gt;&lt;br /&gt;a. Press Ctrl+E, choose Tools-&gt;Menu Editor, or click on the Menu Editor icon on the toolbar to open the Menu Editor.&lt;br /&gt;b. Copy someone else's program and hope that they don't notice.&lt;br /&gt;c. To create pull-down menus, you need to earn a four-year degree studying C++ and Java.&lt;br /&gt;d.Visual Basic can create pull-down menus?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Assigning shortcut keys&lt;br /&gt;&lt;br /&gt;After a while, you are likely to get tired of using pull-down menus every time you want to pick a command. For commonly used commands, a good idea is to assign these commands to shortcut keys, such as Ctrl+S to choose the Save command or Ctrl+X to choose the Cut command. Such a shortcut key lets the user give a command without wading through multiple pull-down menus.&lt;br /&gt;&lt;br /&gt;Shortcut keys appear on menus next to the commands they represent. In this way, users can quickly discover the shortcut keys for all your menu commands.&lt;br /&gt;&lt;br /&gt;To assign a shortcut key to a menu command, you have to use the Menu Editor window again. Although you may want to make up your own shortcut keys, Visual Basic lets you choose from only a limited list of possible keys.&lt;br /&gt;&lt;br /&gt;Visual Basic doesn't let you assign the same shortcut keys to different commands. If you try to, Visual Basic scolds you with an Error dialog box.&lt;br /&gt;&lt;br /&gt;To assign shortcut keys to menu commands, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form containing the menus to which you want to add shortcut keys.&lt;br /&gt;&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor Icon on the toolbar. Visual Basic displays the Menu Editor window.&lt;br /&gt;&lt;br /&gt;3. Click on the menu command for which you want to assign a shortcut key.&lt;br /&gt;&lt;br /&gt;4. Click on the down-arrow button in the Shortcut list box.&lt;br /&gt;Visual Basic displays a list of possible keystroke combinations you can use.&lt;br /&gt;&lt;br /&gt;5. Scroll through this list until you find the right keystroke combination.&lt;br /&gt;Ideally, you want to choose keystroke combinations that are easy to remember, such as Ctrl+S for the Save command or Ctrl+X for the Cut command. Visual Basic displays your choice in the Menu control list box.&lt;br /&gt;&lt;br /&gt;6. Click on OK.&lt;br /&gt;&lt;br /&gt;Now when you click on your pull-down menus, shortcut keys appear next to some of the commands. Because you haven't written any BASIC code to tell these commands what to do, nothing happens if you press any of the shortcut keys.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Putting check marks next to menu commands&lt;br /&gt;&lt;br /&gt;Check marks, which appear next to items on a menu, visually show that the items already have been selected. These check marks are often useful in identifying which font, type style, or size is currentIy in use.&lt;br /&gt;&lt;br /&gt;If you want to make any default choices in your pull-down menus, you can have check marks appear when your program runs.&lt;br /&gt;&lt;br /&gt;Check marks can appear next to menu commands only and riot menu titles. If you try to put a check mark next to a menu title, Visual Basic screams and displays the error message - Can't put check mark here.&lt;br /&gt;&lt;br /&gt;To add check marks to menu commands, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form containing the menus to which you want to add check marks.&lt;br /&gt;&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;&lt;br /&gt;3. Click on the menu command from the Menu Editor window that you want a check mark to appear next to.&lt;br /&gt;&lt;br /&gt;4. Click on the Checked check box.&lt;br /&gt;&lt;br /&gt;5. Click on OK.&lt;br /&gt;&lt;br /&gt;If you put check marks next to your menu commands, you're going to want to remove the check marks eventually. To do this, you have to use (gasp!) BASIC code.&lt;br /&gt;&lt;br /&gt;To remove a check mark that's next to a menu command, just set the command's Checked property to False. The following example removes a check mark from a menu command named mnuFont12:&lt;br /&gt;&lt;br /&gt;mnuFont12.Checked = False&lt;br /&gt;&lt;br /&gt;To add a check mark using BASIC code, just set the menu command's Checked property to True. The following example adds a check mark next to a menu command named mnuFontHelvetica:&lt;br /&gt;&lt;br /&gt;MnuFontHelvetica.Checked = True&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Dimming menu commands&lt;br /&gt;&lt;br /&gt;Sometimes using certain commands doesn't make sense. For example, until you select a block of text, having the Cut or Copy commands as options is pointless. To prevent users from choosing menu commands that aren't available, you can dim the commands. That way, the commands still appear in the menus, but the user can't choose them.&lt;br /&gt;&lt;br /&gt;To dim a menu item, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form containing the menu commands that you want to dim.&lt;br /&gt;&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor lcon on the toolbar. Visual Basic cheerfully displays the Menu Editor window.&lt;br /&gt;&lt;br /&gt;3. Highlight the menu item that you want to dim.&lt;br /&gt;&lt;br /&gt;4. Click on the Enabled check box to remove the check mark.&lt;br /&gt;&lt;br /&gt;5. Click on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you dim a menu command, eventually, you're going to want to undim the command. To do so, you have to use BASIC code. To undim a menu command, set the command's Enabled property to True. The following example undims a menu command named mnuEditCut:&lt;br /&gt;&lt;br /&gt;MnuEditCut.Enabled = True&lt;br /&gt;&lt;br /&gt;To dim a menu command while your program is running, use BASIC code. Just set the menu command's property to False. The following example dims a menu command named mnuEditCopy:&lt;br /&gt;&lt;br /&gt;MnuEditCopy.Enabled = False&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Making menu commands disappear&lt;br /&gt;&lt;br /&gt;Rather than dim a menu command, you can make the command disappear. For example, some programs remove all menu titles except File and Help from the menu bar until the user opens or creates a file. (After all, displaying an Edit menu when you have nothing to edit is pointless.)&lt;br /&gt;&lt;br /&gt;To remove a menu item, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form containing the menu commands you want to make invisible.&lt;br /&gt;&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;&lt;br /&gt;3. From the Menu Editor window, highlight the menu item that you want to make invisible.&lt;br /&gt;&lt;br /&gt;4. Click on the Visible check box to remove the cheek mark.&lt;br /&gt;&lt;br /&gt;5. Click on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After you make a menu command invisible, eventually you're going to have to make the command visible. To do so, you have to use BASIC code. To make a menu command visible, set the command's Visible property to True. The following example makes a menu title named mnuEdit visible:&lt;br /&gt;&lt;br /&gt;mnuEdit.Visible = True&lt;br /&gt;&lt;br /&gt;To make a menu command invisible while your program is running, use BASIC code and set the menu item's property to False. The following example makes a menu title named mnuTools disappear:&lt;br /&gt;&lt;br /&gt;mnuTools.Visible = False&lt;br /&gt;&lt;br /&gt;Just remember that all these fine points of beautifying your menus make your program easier to use and give your program that professional look. As any professional programmer can tell you, if a program looks good, users assume that any error they come across must be their fault. And that's the real reason programmers spend so much time creating a user interface - so that users aren't going to blame the programmers when the program fails catastrophically.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 12&lt;br /&gt;&lt;br /&gt;SUBMENUS, GROWING MENUS, AND POP-UP MENUS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Creating submenus&lt;br /&gt;Dynamically growing menus&lt;br /&gt;Creating pop-up menus&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A typical menu bar displays a list of menu titles at the top of the screen. Selecting one of the menu titles displays a pull-down menu.&lt;br /&gt;&lt;br /&gt;Unfortunately, a menu bar can hold only a limited number of menu titles, and a pull-down menu can hold only as many commands as can appear on the screen simultaneously. So what happens if you write a killer application that requires more commands than can possibly appear on the menu bar or in multiple pull-down menus? The solution is to use submenus (or to redesign your program).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating Submenus&lt;br /&gt;&lt;br /&gt;Submenus are often used to bury a command several layers deep within a series of pull-down menus. If organized properly, submenus clearly show the relationship between various topics. If organized improperly, your program is going to look just as confusing as the most popular commercial programs that millions of people are forced to use every day.&lt;br /&gt;&lt;br /&gt;For example, many programs have a Format menu title. Under this Format menu may be commands such as TypeStyle, Font, and Size. Choosing Font often displays a submenu listing all the possible fonts available.&lt;br /&gt;&lt;br /&gt;Visual Basic lets you create up to four levels of submenus. Although this number of submenus can be handy, most programs use only one level of submenus to avoid burying commands so deeply that no one can find them again. Rumor has it that the Watergate tapes, Jimmy Hoffa's body, and the location of the Holy Grail reside somewhere in a well-known program's submenus.&lt;br /&gt;&lt;br /&gt;Whenever a menu item displays an arrowhead symbol, the symbol indicates that a submenu exists for that item. When you create submenus, Visual Basic displays this arrowhead symbol automatically.&lt;br /&gt;&lt;br /&gt;The Menu Editor window is the only place where you can define submenus. Any item that appears flush left appears as a menu title in the menu bar. Items indented once appear on the pull-down menus, items indented twice appear on the first submenu level, items indented three times appear on the second submenu level, items indented four times appear on the third submenu level, and items indented five times appear on the fourth and last submenu level.&lt;br /&gt;&lt;br /&gt;To create submenus, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form on which you want to create submenus.&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;3. In the Menu Control list box, highlight the menu item that you want to make into a submenu.&lt;br /&gt;4. Click on the right-arrow button to indent the item.&lt;br /&gt;5. Click on OK.&lt;br /&gt;&lt;br /&gt;Each level of indentation (submenu level) is represented by four dots in the Menu Control list box.&lt;br /&gt;&lt;br /&gt;If you want to move submenus up a level (such as from submenu level 3 to submenu level 2), you can. Just follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form containing the submenus that you want to modify.&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;3. In the Menu Control list, highlight the menu item box that you want to move up a level.&lt;br /&gt;4. Click on the left-arrow button to indent the item to the left.&lt;br /&gt;5. Click on OK when you finish playing around.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Rather than using multiple levels of submenus, most of the really cool programs use dialog boxes. (See Chapter 13 to find out all about dialog boxes.) A dialog box lets users make multiple choices all at once instead of making choices one at a time through many submenu levels. While submenus are fine for choosing a few options, dialog boxes are better for choosing lots of options.&lt;br /&gt;&lt;br /&gt;Then again, what's the point of offering submenus if even Microsoft recommends against doing so? This is just one of the many ways that Microsoft gives you the freedom to write hard-to-use user interfaces so that your programs can never pose a real threat to Microsoft's own programs.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Changing Menu Captions While Your Program Is Running&lt;br /&gt;&lt;br /&gt;In certain cases, changing the caption of a menu command while the program is running is necessary. The most common menu command that changes is the Undo command in the Edit menu. After choosing the Undo command, some programs may toggle Undo to display the Redo command.&lt;br /&gt;&lt;br /&gt;To change a menu caption, you have to use BASIC code. Just find the name of the menu item that you want to change and set the item's Caption property to a new caption. The following example changes the mnuEditUndo caption to Redo:&lt;br /&gt;&lt;br /&gt;mnuEditUndo.Caption = "Redo"&lt;br /&gt;&lt;br /&gt;The following example changes the mnuEditUndo caption back to Undo:&lt;br /&gt;&lt;br /&gt;mnuEditUndo.Caption = "Undo"&lt;br /&gt;&lt;br /&gt;When changing menu captions, you can use the ampersand (&amp;amp;) symbol to display a menu command hot key. (You can read more about hot keys in Chapter 11.) For example, the following code changes the mnuEditUndo caption to Undo where the capital letter U appears underlined:&lt;br /&gt;&lt;br /&gt;mnuEditUndo.Caption = "&amp;amp;Undo"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Designing Dynamically Growing Menus&lt;br /&gt;&lt;br /&gt;If you use many Windows-based programs (such as Microsoft Word), you may notice an odd feature: Each time you load a program, the File menu displays a list of the last four or five files you worked on. If you ever open two or more windows in the same program, you may notice that the Window menu also lists the names of the files currently open.&lt;br /&gt;&lt;br /&gt;To create a dynamically growing menu, you have to create empty spaces in your menu. To do this, use the Menu Editor window and create BASIC code to add items to make the items visible.&lt;br /&gt;&lt;br /&gt;To create a dynamically growing menu, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form where you want to create a dynamically growing menu.&lt;br /&gt;&lt;br /&gt;2. Open the Menu Editor window by pressing Ctrl+E, choosing Tools-&gt;Menu Editor, or clicking on the Menu Editor icon on the toolbar.&lt;br /&gt;&lt;br /&gt;3. Click below the last menu command under the menu title to which you want to add new items.&lt;br /&gt;For example, if you want to add new items under the File menu, click below the last menu command under the File menu title.&lt;br /&gt;&lt;br /&gt;4. Click on Insert to add the item.&lt;br /&gt;&lt;br /&gt;5. Click on the right-arrow button to indent the empty lines so that they appear as menu commands below the menu title.&lt;br /&gt;&lt;br /&gt;6. Leave the Caption text box empty and press Tab.&lt;br /&gt;&lt;br /&gt;7. In the Name text box, type the same name for each of these empty lines, such as mnuFileMRU.&lt;br /&gt;&lt;br /&gt;8. Type 0 in the Index text box for the first empty line.&lt;br /&gt;Each time you add another empty line, increase the number in the Index text box by 1. You want the first empty line Index text box to contain 0, the second to contain 1, the third to contain 2, and so on.&lt;br /&gt;&lt;br /&gt;9. Click in the Visible check box to clear the check box.&lt;br /&gt;&lt;br /&gt;10. Press Enter.&lt;br /&gt;&lt;br /&gt;11. Repeat Steps 3 through 10 until you create four or five empty lines below the last menu title in the Menu Editor Control list box. Make sure that each empty line has a different number in its Index text box.&lt;br /&gt;&lt;br /&gt;12. Click on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The preceding steps create a dynamically growing menu, but to actually add items to this menu, you have to use BASIC code. The following example shows how to add an item to give the illusion of a dynamically growing menu:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load()&lt;br /&gt;  mnuFileMRU(O).Caption = "&amp;amp;1 C:\VB\HELLO.VBP"&lt;br /&gt;  mnuFileMRU(O).Visible = True&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The second line of the preceding Form_Load event procedure sets the caption of the first empty line to 1 C:\VB\HELLO.VBP. The third line makes this item visible on the pull-down menu.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating Pop-Up Menus&lt;br /&gt;&lt;br /&gt;Pop-up menus (also called context menus) are often used to quickly display a list of commands on the screen. Any menu or submenu can appear as a popup menu. Pop-up menus are usually programmed to appear when the user presses the right mouse button.&lt;br /&gt;&lt;br /&gt;To create a pop-up menu, you have to use the BASIC command PopupMenu. The following example displays the mnuEdit menu as a pop-up menu when the user clicks the right mouse button:&lt;br /&gt;&lt;br /&gt;Private Sub Form_MouseDown(Button As Integer, Shift As _ Integer, X As Single, Y As Single)&lt;br /&gt;  If Button = 2 Then     '  Right mouse button pressed  _&lt;br /&gt;      PopupMenu mnuEdit     '  Pops up the mnuEdit menu&lt;br /&gt;  End If&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Instead of using the number 1 to represent the left mouse button and the number 2 to represent the right mouse button, you can use the variables vbPopupMenuLeftButton and vbPopupMenuRightButton, respectively.&lt;br /&gt;&lt;br /&gt;To create a pop-up menu, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the form containing the menu that you want to turn into a pop-up menu.&lt;br /&gt;2. Press F7, choose View-&gt;Code, or click on the View Code Icon In the Project Explorer window.&lt;br /&gt;The Code Editor window appears.&lt;br /&gt;3. Click in the Object list box and choose Form.&lt;br /&gt;4. Click in the Procedure list box and choose MouseUp.  Visual Basic displays an empty Private Form_MouseUp procedure.&lt;br /&gt;5. Type the following code below the Private Sub Form_MouseDown statement and above the End Sub statement:&lt;br /&gt;&lt;br /&gt;If Button = vbPopupMenuRightButton   Then&lt;br /&gt;  PopUpMenu (type the menu name here such as mnuEdit)&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;If for some odd reason you want to make a menu pop up by pressing the left mouse button, substitute the vbPopupMenuRightButton variable with the vbPopupMenuLeftButton variable instead.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Defining the location of pop-up menus&lt;br /&gt;&lt;br /&gt;Normally, the pop-up menu appears wherever the mouse pointer happens to be. However, if you want pop-up menus to appear in a specific location on the screen, you can specify the exact coordinates.&lt;br /&gt;&lt;br /&gt;For example, the following PopupMenu BASIC command displays a pop-up menu named mnuTools at X-coordinate 500 and Y-coordinate 650:&lt;br /&gt;&lt;br /&gt;PopupMenu mnuTools, 500, 650&lt;br /&gt;&lt;br /&gt;For those people who are finicky about where the pop-up menu appears relative to the mouse pointer, you can specify whether the menu appears to the left, to the right, or dead center of the mouse. Use one of the following commands:&lt;br /&gt;&lt;br /&gt;PopupMenu mnuEdit, 0   '  Left aligned&lt;br /&gt;PopupMenu mnuEdit, 4   '  Center aligned&lt;br /&gt;PopupMenu mnuEdit, 8   '  Right aligned&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Using numbers to specify right or left alignment can be easy to type but ultimately confusing to understand what the code actually does. To simplify matters, Visual Basic lets you use honest-to-goodness English phrases that represent the above numbers, such as the following:&lt;br /&gt;&lt;br /&gt;PopupMenu mnuEdit,  vbPopupMenuLeftAlign   '  Left aligned&lt;br /&gt;PopupMenu mnuEdit,  vbPopupMenuCenterAlign   '  Center aligned&lt;br /&gt;PopupMenu mnuEdit,  vbPopupMenuRightAlign   '  Right aligned&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Essentially, these statements tell Visual Basic, "Hey stupid, whenever you see the words vbPopupMenuRightAlign, substitute the number 8 instead."&lt;br /&gt;&lt;br /&gt;Using the old method in a Visual Basic procedure looks like the following:&lt;br /&gt;&lt;br /&gt;Private Sub Form_MouseDown(Button As Integer, Shift As  _  Integer, X As Single, Y As Single)&lt;br /&gt;  If Button = 2 Then               '  Right mouse button pressed&lt;br /&gt;     PopupMenu mnuEdit, 4    '  Old, confusing way&lt;br /&gt;  End If&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now here's what the modern, easy-to-read method using English looks like:&lt;br /&gt;&lt;br /&gt;Private Sub Form_MouseDown(Button As Integer, Shift As _  Integer, X As Single, Y As Single)&lt;br /&gt;  If Button = vbPopupMenuRightButton Then&lt;br /&gt;     PopupMenu mnuEdit, vbPopupMenuCenterAlign&lt;br /&gt;  End If&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;In case your mind is racing ahead already to new possibilities, you can left-, center-, or right-align a menu around a specific X-coordinate. For example, if you want to center-align the pop-up menu around a specific X-coordinate, do the following:&lt;br /&gt;&lt;br /&gt;PopupMenu mnuTools, 4, 500, 650&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;PopupMenu mnuTools, vbPopupMenuCenterAlign,  500,  650&lt;br /&gt;&lt;br /&gt;This example displays the pop-up menu at the X- and Y-coordinates of 500 twips and 650 twips, respectively.&lt;br /&gt;&lt;br /&gt;If you change the units of measurement on a form from twips to inches or centimeters, you may have to change the X- and Y-coordinate values as well to correspond to your new scale. (See Chapter 6 in case you want to define different units of measurement for your form.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Defining the right mouse button to work with pop-up menus&lt;br /&gt;&lt;br /&gt;Normally, pop-up menus work like ordinary pull-down menus. To choose a command, you just click on the command with the left mouse button. However, because the right mouse button is used about as often as you use your wisdom teeth, you may want to give users the capability to use either the left or right mouse button.&lt;br /&gt;&lt;br /&gt;The following code example activates the right mouse button:&lt;br /&gt;&lt;br /&gt;PopupMenu mnuEdit, 2&lt;br /&gt;&lt;br /&gt;To replace numbers with English, you can substitute the following:&lt;br /&gt;&lt;br /&gt;PopupMenu mnuEdit, vbPopupManuRightButton&lt;br /&gt;&lt;br /&gt;By default, Visual Basic assumes that you always want to use the left mouse button with any pop-up menu.&lt;br /&gt;&lt;br /&gt;Trick question: How do you define both center-alignment and right-button activation? The answer is to use the Or operator, as shown in the following:&lt;br /&gt;&lt;br /&gt;PopupMenu mnuEdit, 2 Or 4&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To use English instead of numbers, you can use the following:&lt;br /&gt;&lt;br /&gt;PopupMenu mnuEdit, vbPopupMenuRightButton Or vbPopupMenuCenterAlign&lt;br /&gt;&lt;br /&gt;Most popular programs (such as WordPerfect, Excel, and Paradox) use submenus, dynamically growing menus, and pop-up menus. But for less complicated programs, such as games, you probably aren't going to need all these different menu features.&lt;br /&gt;&lt;br /&gt;Fortunately, most users are already familiar with all these menu features, so when a pop-up menu or submenu appears on the screen, the user is not going to be shocked. The secret is to use these features only if you have to. Remember, the more fancy features you add to your program, the more programming concerns you have to worry about. (Now aren't you glad you decided to find out how to program your computer?)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. Explain why you may want your menu captions to change while your program is running.&lt;br /&gt;&lt;br /&gt;a. To confuse your users so that they think they're doing something wrong.&lt;br /&gt;b. To move important commands every five minutes to keep users on their toes.&lt;br /&gt;c. To toggle menu captions like Undo and Redo.&lt;br /&gt;d. Because you aren't considered a real programmer unless you use every possible feature of a programming language to make your programs more complicated to use.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Explain what the following BASIC code does:&lt;br /&gt;&lt;br /&gt;Private Sub&lt;br /&gt;  Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)&lt;br /&gt;  If Button = vbPopupMenuRightButton Then PopupMenu mnuFont&lt;br /&gt;  End If&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;a. When the user presses and releases the right mouse button, the program displays the mnuFont menu as a popup menu.&lt;br /&gt;b. When the user presses the right mouse button, World War Ill is declared.&lt;br /&gt;c. When the user presses any button, the mouse self-destructs with a loud popI&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 13&lt;br /&gt;&lt;br /&gt;DIALOG BOXES&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Creating dialog boxes&lt;br /&gt;Adding icons and buttons to dialog boxes&lt;br /&gt;Using common dialog boxes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Pull-down menus certainly make life easier for users (provided, of course, that the users know how to use the menus). In addition to pulldown menus, nearly every program also uses dialog boxes.&lt;br /&gt;&lt;br /&gt;Dialog boxes are those tiny windows that pop up on the screen. Most of the time, the computer uses dialog boxes to let the user know what the computer is doing, such as "Now printing page 4 of 67"' or "Windows 98 just crashed again and here's an application error number that you won't understand anyway."&lt;br /&gt;&lt;br /&gt;However, dialog boxes also let the computer ask questions of users, such as "Cancel printing?" or "Do you really want to exit out of Windows?" A fancy dialog box may be crammed full of options so that the user can make multiple choices all at one time. Just as most Windows-based programs use similar pull-down menus (File, Edit, Help), these programs also use similar dialog boxes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating a Simple Dialog Box&lt;br /&gt;&lt;br /&gt;A dialog box displays a brief message on the screen along with one or more command buttons. Dialog boxes typically contain the following four parts.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A title bar&lt;br /&gt;A message&lt;br /&gt;An eye-catching icon&lt;br /&gt;One or more command buttons&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The title bar identifies the purpose of the dialog box, such as About This Program. The message contains text that appears in the dialog box, such as "Are you sure that you want to start World War Ill?" The icon provides visual information about the dialog boxs importance. The number and type of command buttons can vary from one to three.&lt;br /&gt;&lt;br /&gt;The simplest dialog box is one that displays a message on the screen and provides an OK command button so that the user can make the dialog box go away.&lt;br /&gt;&lt;br /&gt;The following BASIC code creates the simple dialog box.&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load ( )&lt;br /&gt;  MsgBox "Get a Macintosh",   ,"Another Windows Crash"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;This simple dialog box does nothing more than appear on the screen and then disappear when the user clicks on OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Adding icons to a dialog box&lt;br /&gt;&lt;br /&gt;Icons can help grab a user's attention to your dialog box. Visual Basic uses four icons.&lt;br /&gt;&lt;br /&gt;Critical Message: Alerts the user to an extremely important question, such as "If you continue, you are going to erase all the files on your hard disk. Are you sure that you want to do this?"&lt;br /&gt;&lt;br /&gt;Warning Query. (A question mark.) Highlights less-threatening questions, such as "Do you really want to exit from Microsoft Word?"&lt;br /&gt;&lt;br /&gt;Warning Message: (An exclamation mark.) Emphasizes warnings that the user needs to know about, such as "You are about to replace all 79 pages of your document with a period!"&lt;br /&gt;&lt;br /&gt;Information Message: Makes otherwise drab and boring messages look interesting, such as "Printing all 3,049 pages of your document may take a long time. Click on OK if you want to go through with this."&lt;br /&gt;&lt;br /&gt;To add an icon to a dialog box, just add the numeric value of the icon between the dialog box message and the title bar text, as follows:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load( )&lt;br /&gt;  MsgBox "It crashed again!", 16, "Windows Error Message'&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Normally, Visual Basic lets you display only one of four possible icons in a dialog box from scratch. To do this, create a separate form, set the form's BorderStyle property to Fixed Dialog, and draw command buttons and an image box directly on this form. You can then draw an image box on the form and load any type of icon you want.&lt;br /&gt;&lt;br /&gt;Just remember that creating a dialog box by using a separate form requires you to draw the command buttons, label, and image box, and to write BASIC code to make the whole dialog box work. If you just want to create a dialog box quickly and easily, use the MsgBox command instead.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Defining the number and type fo command buttons in a dialog box&lt;br /&gt;&lt;br /&gt;Dialog boxes can contain from one to three command buttons. A numerical value represents each command button. Table 13-1 lists the six command button combinations.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;||&lt;br /&gt;TABLE 13-1&lt;br /&gt;Command Button Combinations Available in Visual Basic&lt;br /&gt;&lt;br /&gt;Displays - OK button&lt;br /&gt;Value - 0&lt;br /&gt;Visual Basic Constant - vbOKOnly&lt;br /&gt;&lt;br /&gt;Displays - OK and Cancel buttons&lt;br /&gt;Value - 1&lt;br /&gt;Visual Basic Constant - vbOKCancel&lt;br /&gt;&lt;br /&gt;Displays - Abort, Retry, and Ignore Buttons&lt;br /&gt;Value - 2&lt;br /&gt;Visual Basic Constant - vbAbortRetryIgnore&lt;br /&gt;&lt;br /&gt;Displays - Yes, No, and Cancel buttons&lt;br /&gt;Value - 3&lt;br /&gt;Visual Basic Constant - vbYesNoCancel&lt;br /&gt;&lt;br /&gt;Displays - Yes and No button&lt;br /&gt;Value - 4&lt;br /&gt;Visual Basic Constant - vbYesNo&lt;br /&gt;&lt;br /&gt;Display - Retry and Cancel buttons&lt;br /&gt;Value - 5&lt;br /&gt;Visual Basic Constant - vbRetryCancel&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To define a command button combination, choose the combination you want and type the numerical value of the combination or the Visual Basic constant between the dialog box's message text and title bar text, such as&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load( )&lt;br /&gt;  MsgBox "File not found", 2, "Error Message"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load( )&lt;br /&gt; MsgBox "File not found",  vbAbortRetryIgnore,  "Error Message"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Which command button did the user select in a dialog box?&lt;br /&gt;&lt;br /&gt;If a dialog box just displays an OK command button, clicking on that OK command button usually makes that dialog box go away. However, dialog boxes with two or more command buttons give users a choice. When dealing with multiple command buttons on a dialog box, you have to write BASIC code to figure out:&lt;br /&gt;&lt;br /&gt;Which button the user chose&lt;br /&gt;What your program should do depending on which button the user chose&lt;br /&gt;&lt;br /&gt;The seven possible buttons a user can choose are represented by the numerical balues in TABLE 13-2.&lt;br /&gt;&lt;br /&gt;To make your program determien which command button a user chose, you have to set a variable equal to the MsgBox BASIC code, as shown in the following line:&lt;br /&gt;&lt;br /&gt;Reply = MsgBox("File not foune",  2,  "Error Message")&lt;br /&gt;&lt;br /&gt;This code displays a dialog box with the Abort, Retry, Ignore command buttons. If the user clicks on Abort, the value of Reply is 3. If the user clicks on Retry, the value of Reply is 4. If the user clicks on Ignore, the value of Reply is 5.&lt;br /&gt;&lt;br /&gt;Note.. Whenever you assign a variable to represent the value chosen from a dialog box, you must use parentheses to enclose the dialog box parameters.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;||&lt;br /&gt;TABLE 13-2&lt;br /&gt;Command Buttons a User Can Choose&lt;br /&gt;&lt;br /&gt;Button Selected - OK&lt;br /&gt;Numerical Value - 1&lt;br /&gt;Visual Basic Constant - vbOK&lt;br /&gt;&lt;br /&gt;Button Selected - Cancel&lt;br /&gt;Numerical Value - 2&lt;br /&gt;Visual Basic Constant - vbCancel&lt;br /&gt;&lt;br /&gt;Button Selected - Abort&lt;br /&gt;Numerical Value - 3&lt;br /&gt;Visual Basic Constant - vbAbort&lt;br /&gt;&lt;br /&gt;Button Selected - Retry&lt;br /&gt;Numerical Value - 4&lt;br /&gt;Visual Basic Constant - vbRetry&lt;br /&gt;&lt;br /&gt;Button Selected - Ignore&lt;br /&gt;Numerical Value - 5&lt;br /&gt;Visual Basic Constant - vbIgnore&lt;br /&gt;&lt;br /&gt;Button Selected - Yes&lt;br /&gt;Numerical Value - 6&lt;br /&gt;Visual Basic Constant - vbYes&lt;br /&gt;&lt;br /&gt;Button Selected - No&lt;br /&gt;Numerical Value - 7&lt;br /&gt;Visual Basic Constant - vbNo&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Commonly Used Dialog Boxes&lt;br /&gt;&lt;br /&gt;While a simple dialog box may be sufficient occasionally, you may want to use a more complicated, yet more common, dialog box such as:&lt;br /&gt;&lt;br /&gt;Open&lt;br /&gt;Save As&lt;br /&gt;Color&lt;br /&gt;Font&lt;br /&gt;Print&lt;br /&gt;&lt;br /&gt;Before you can use one of these common dialog boxes, you may have to load the Common Dialog Box icon into the Visual Basic Toolbox. To do this, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose Project-&gt;Components or press Ctrl+T.  A Components dialog box appears.&lt;br /&gt;2. Click on the Controls tab.&lt;br /&gt;3. Make sure that a check mark appears in the Microsoft Common Dialog Control 6.0 check box. If a check mark does not appear, click on the check box.&lt;br /&gt;4. Click on OK.  The Visual Basic Toolbox displays the Common Dialog Box icon.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To display one of the five commonly used dialog boxes in your program, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the Common Dialog Box Icon in the Visual Basic Toolbox.&lt;br /&gt;&lt;br /&gt;2. Move the mouse anywhere on the form. Hold down the mouse button and move the mouse down and to the right. Let go of the mouse button.&lt;br /&gt;&lt;br /&gt;This draws the Common Dialog Box icon on the form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you double-click on the Common Dialog Box icon in the Visual Basic Toolbox, Visual Basic draws the Common Dialog Box icon on the form for you automatically.&lt;br /&gt;&lt;br /&gt;Where you place the Common Dialog Box icon on a form is irrelevant because the icon is always invisible when your program runs. Putting the Common Dialog Box icon on a form essentially tells Visual Basic, "Okay, this icon gives you the magical power to display the Open, Save As, Print, Color, or Font dialog box whenever I tell you to."&lt;br /&gt;&lt;br /&gt;Because you need only one Common Dialog Box icon per form to display the different types of common dialog boxes, you don't have to change the icon's name. Just use the default name that Visual Basic gives the icon, which is CommonDialog1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Test Your Newfound Knowledge&lt;br /&gt;&lt;br /&gt;1. Why do you want do display an icon in a dialog box?&lt;br /&gt;&lt;br /&gt;a. In case an illiterate computer user wants to use your program.&lt;br /&gt;b. To catch the eye of the user and provide a visual cue. For example, a Critical Message icon can warn users that something terrible is about to happen if they don't do something immediatley.&lt;br /&gt;c. To see if the user is smart enough to realize that the dialog box has nothing important to say.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. To use the predefined Open, Save As, Color, Font, or Print dialog box, what must you do first?&lt;br /&gt;&lt;br /&gt;a. Buy the Visual Basic manuals that used to come with the program for free&lt;br /&gt;b. Create a new form, draw three command buttons, two check boxes, one list box, and a partridge in a pear tree.&lt;br /&gt;c. Save your file and exit Visual Basic&lt;br /&gt;d. Make sure that you have drawn the Common Dialog Box icon on your form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Displaying the Open dialog box&lt;br /&gt;&lt;br /&gt;The Open dialog box lets users choose a drive, directory, and file to open. The user also has the choice of displaying only specific file types, such as those matching the *.TXT or *.EXE criteria.&lt;br /&gt;&lt;br /&gt;To display the Open dialog box, you need only one magic BASIC command that looks like this:&lt;br /&gt;&lt;br /&gt;CommonDialog1.ShowOpen&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want to define the list of files that the Open dialog box displays, you have to use something technical called a filter. A filter tells Visual Basic what types of files to display, such as all those with the TXT or BAT file extension.&lt;br /&gt;&lt;br /&gt;A filter consists of two parts: the label that appears in the list box and the filter itself. Table 13-3 lists some examples of labels and filters. For added clarity, labels usually include the filter they use.&lt;br /&gt;&lt;br /&gt;Text files, for example, usually have the file extension TXT, but sometimes they have the file extension ASC. So the label "Text Files (*.TXT)" lets you know that the dialog box shows only text files with the TXT file extension (and not text flies with the ASC file extension).&lt;br /&gt;&lt;br /&gt;To define your labels and filters, use BASIC code, as in the following example:&lt;br /&gt;&lt;br /&gt;CommonDialog1.Filter = "All Files (*.*) |*.*|Text Files - (*.TXT) |*.TXT|Batch Files (*.BAT) - |*.BAT| Executable Files&lt;br /&gt;(*.EXE) |*.EXE"&lt;br /&gt;&lt;br /&gt;This code also establishes the filter order, which you can utilize with the corresponding filter index number. In the above example, the All Files filter is first, and so has a filter index number of 1. After you define the filter, you have to tell Visual Basic which filter to display by default. Again, you use BASIC code:&lt;br /&gt;&lt;br /&gt;CommonDialog1.FilterIndex = 1&lt;br /&gt;&lt;br /&gt;This code line displays "All Files (*.*)" in the List Files of Type list box. Or you can choose the following:&lt;br /&gt;&lt;br /&gt;CommonDialog1.FilterIndex = 4&lt;br /&gt;&lt;br /&gt;This line displays "Executable Files (*.EXE)" in the List Files of Type list box.&lt;br /&gt;&lt;br /&gt;The order in which you define your filter (using the Common Dialog1.Filter command) determines the FilterIndex number. For example, if you change the filter to&lt;br /&gt;&lt;br /&gt;CommonDialog1.Filter = "Text Files (*.TXT) - |*.TXT|All Files(*.*)|*.*"&lt;br /&gt;&lt;br /&gt;the following code displays "Text Files (*.TXT)" in the List Files of Type list box:&lt;br /&gt;&lt;br /&gt;CommonDialog1.FilterIndex = 1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;||&lt;br /&gt;TABLE 13-3&lt;br /&gt;Labels and Filters&lt;br /&gt;&lt;br /&gt;Label - All Files (*.*)&lt;br /&gt;Filter - *.*&lt;br /&gt;&lt;br /&gt;Label - Text Files (*.TXT)&lt;br /&gt;Filter - *.TXT&lt;br /&gt;&lt;br /&gt;Label - Batch Files (*.BAT)&lt;br /&gt;Filter - *.BAT&lt;br /&gt;&lt;br /&gt;Label - Executable Files (*.EXE)&lt;br /&gt;Filter - *.EXE&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* How to create an Open dialog box&lt;br /&gt;&lt;br /&gt;Obviously, if your program is going to store data in a file, the program is going to have to open a file at some point. Because nearly every program needs to open files, make your life easy and use the Open dialog box.&lt;br /&gt;&lt;br /&gt;To actually display an Open dialog box, you need to write BASIC code, such as:&lt;br /&gt;&lt;br /&gt;Private Sub mnuFileOpen_Click( )&lt;br /&gt;  CommonDialog1.Filter "Text Files (*.TXT) |*.TXT |AII Files (*.*)l*.*"&lt;br /&gt;  CommonDialog1.Filterlndex = 1&lt;br /&gt;  CommonDialog1.ShowOpen&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This event procedure tells Visual Basic:&lt;br /&gt;&lt;br /&gt;1. When the user clicks on the Open command underneath the File pulldown menu, follow the instructions sandwiched in between the first and last lines of the Private Sub mnuFileOpen_Click( ) event procedure.&lt;br /&gt;&lt;br /&gt;2. The second line tells Visual Basic what types of files to display in the Open dialog box.&lt;br /&gt;&lt;br /&gt;3. The third line tells Visual Basic to display files matching the first list of files def ined by the Filter property. In this case, the third line tells the Open dialog box to display *. TXT text files.&lt;br /&gt;&lt;br /&gt;4. The fourth line tells Visual Basic to display the Open dialog box on the screen, displaying only files with the TXT file extension.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;At this point, the Open dialog box looks nice and seems to work, but because you haven't written any BASIC code to tell the dialog box what to do, the box doesn't do a thing but look pretty.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Which file did the user choose from an Open dialog box?&lt;br /&gt;&lt;br /&gt;After you display an Open dialog box, the next big question is to find out which file the user chose. When the user clicks on a file displayed by the Open dialog box, Visual Basic stores the filename in the Filename property of the Common dialog box. So if you want to retrieve the filename that the user clicked on, you need to set a variable to store the filename property, such as:&lt;br /&gt;&lt;br /&gt;WhatFile = CommonDialog1.filename&lt;br /&gt;&lt;br /&gt;So the complete event procedure may look like this:&lt;br /&gt;&lt;br /&gt;Private Sub mnuFileOpen_Click( )&lt;br /&gt;Dim WhatFile As String&lt;br /&gt;  CommonDialog1.Filter = "Text Files (*.TXT) |*.TXT|All_Files (*.*)|*.*"&lt;br /&gt;  CommonDialog1.FilterIndex = 1&lt;br /&gt;  CommonDialog1.ShowOpen&lt;br /&gt;  WhatFile = commonDialog1.filename&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The CommonDialog1.file name property contains both the filename and the directory that the file is stored in, such as C:\MyDocuments\Secrets\Resume.txt. If the user clicks the Cancel command button in the Open dialog box, the filename property is set to " " (no text).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Displaying a Save As dialog box&lt;br /&gt;&lt;br /&gt;A Save As dialog box is nearly identical to the Open dialog box. However, the text of the title bar is not the same. (The Open dialog box's title bar says "Open" and the Save As dialog box's title bar says "Save As".)&lt;br /&gt;&lt;br /&gt;The only BASIC command you need to use to display a Save As dialog box is:&lt;br /&gt;&lt;br /&gt;CommonDialog1.ShowSave&lt;br /&gt;&lt;br /&gt;However, you may also want to use filters to display certain types of files, such as:&lt;br /&gt;&lt;br /&gt;Private Sub mnuFileSaveAs_Click( )&lt;br /&gt;  CommonDialog1.Filter = "Text Files (*.TXT) | .TXT | All_Files (*.*) |*.*"&lt;br /&gt;  CommonDialog1.FilterIndex = 1&lt;br /&gt;  CommonDialog1.ShowSave&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Which file did the user choose from a Save As dialog box?&lt;br /&gt;&lt;br /&gt;Like the Open dialog box, the Save As dialog box stores the filename in the Filename property of the Common dialog box. So if you want to retrieve the filename on which the user clicked, you need to set a variable to store the filename property, such as:&lt;br /&gt;&lt;br /&gt;WhatFile = CommonDialog1.filename&lt;br /&gt;&lt;br /&gt;So the complete event procedure may look like this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Private Sub mnuFileSaveAs_Click( )&lt;br /&gt;Dim WhatFile As String&lt;br /&gt;  CommonDialog1.Filter - "Text Files (*.TXT) |*.TXT |All_Files (*.*) |*.*"&lt;br /&gt;  CommonDialog1.FilterIndex = 1&lt;br /&gt;  CommonDialog1.ShowSave&lt;br /&gt;  WhatFile = CommonDialog1.fiIename&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Save As dialog box doesn't actually save files on its own. To save a file under a different name, you have to write additional BASIC code that tells your computer to save a file onto a disk.&lt;br /&gt;&lt;br /&gt;Rather than use Visual Basic's Open and Save As dialog boxes, try experimenting with a free File dialog box control that offers more flexibility and features while being smaller to use. You can download this FileDialog control from the CCRP Web site at www.mvps.org/ccrp. (Note that an independent group of programmers created this FileDialog box control, so if it doesn't work, don't blame Microsoft.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Displaying a Color dialog box&lt;br /&gt;&lt;br /&gt;The Color dialog box lets users choose colors or mix their own.&lt;br /&gt;&lt;br /&gt;To display a Color dialog box, you have to use two magic BASIC commands:&lt;br /&gt;&lt;br /&gt;CommonDialog1.Flags = cdlCCRGBInit&lt;br /&gt;CommonDialog1.ShowColor&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first line tells Visual Basic that the Common dialog box, defined by CommonDialog1, can be used to retrieve a color from the Color dialog box.&lt;br /&gt;&lt;br /&gt;The second line tells Visual Basic to display the Color dialog box.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  CommonDialog1.Flags = cdlCCRGBInit&lt;br /&gt;  CommonDialog1.ShowColor&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Which color did the user choose from the Color dialog box?&lt;br /&gt;&lt;br /&gt;The Color dialog box stores the color the user chose in the Color property of the Common dialog box. So if you want to retrieve the color (which Visual Basic stores as a number) that the user clicked on, you need to set a variable to store the Color property, such as:&lt;br /&gt;&lt;br /&gt;WhatColor = CommonDialog1.Color&lt;br /&gt;&lt;br /&gt;So the complete event procedure may look like this:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;Dim WhatColor as Long&lt;br /&gt;  CommonDialog1.Flags = cdICCRGBInit&lt;br /&gt;  CommonDialog1.ShowColor&lt;br /&gt;  WhatColor = CommonDialog1.Color&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Displaying a Font dialog box&lt;br /&gt;&lt;br /&gt;The Font dialog box lets users choose different fonts, font styles, and point sizes. Each time the user chooses an option, this dialog box displays a sample so that the user can see whether the font, font style, or point size looks okay.&lt;br /&gt;&lt;br /&gt;To display a Font dialog box, you have to use two magic BASIC commands:&lt;br /&gt;&lt;br /&gt;CommonDialog1.Flags = cdlCFEffects Or cdlCFBoth&lt;br /&gt;CommonDialog1.ShowFont&lt;br /&gt;&lt;br /&gt;The first line tells Visual Basic that the Common dialog box, defined by CommonDialog1, can be used to retrieve a font value from the Font dialog box.&lt;br /&gt;&lt;br /&gt;The second line tells Visual Basic to display the Font dialog box.  For example:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click ( )&lt;br /&gt;  CommonDialog1.Flags = cdlCFEffects Or cdlCFBoth&lt;br /&gt;  CommonDialog1.ShowFont&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Which captions did the user choose from the Font dialog box?&lt;br /&gt;&lt;br /&gt;The Font dialog box lets the user choose a variety of options, as Table 13-4 shows:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TABLE 13-4&lt;br /&gt;Properties That Store Values from the Font Dialog Box&lt;br /&gt;&lt;br /&gt;Property - Color&lt;br /&gt;What Information It Contains - The selected color.  To use this property, you must first set the Flags property to cdlCFEffects.&lt;br /&gt;&lt;br /&gt;Property - FontBold&lt;br /&gt;What Information It Contains - Whether bold was selected.&lt;br /&gt;&lt;br /&gt;Property - Property&lt;br /&gt;What Information It Contains - What information it contains.&lt;br /&gt;&lt;br /&gt;Property - FontItalic&lt;br /&gt;What Information It Contains - Whether italic was selected.&lt;br /&gt;&lt;br /&gt;Property - FontStrikethru&lt;br /&gt;What Information It Contains - Whether strikethru was selected. To use this property, you must first set the Flags property to cdlEFEffects.&lt;br /&gt;&lt;br /&gt;Property - FontUnderline&lt;br /&gt;What Information It Contains - Whether underline was selected. To use this property, you must first set the Flags property to cdlCFEffects.&lt;br /&gt;&lt;br /&gt;Property - FontName&lt;br /&gt;What Information It Contains - The selected font name&lt;br /&gt;&lt;br /&gt;Property - FontSize&lt;br /&gt;What Information It Contains - The selected font size.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So the complete event procedure may look like this:&lt;br /&gt;&lt;br /&gt;Private Sub mnuFormatFont_Click( )&lt;br /&gt;Dim TextColor As Long&lt;br /&gt;Dim Bold As Boolean&lt;br /&gt;Dim Italic As Boolean&lt;br /&gt;Dim Underline As Boolean&lt;br /&gt;Dim Strikethru As Boolean&lt;br /&gt;Dim Font As String&lt;br /&gt;Dim Size As Integer&lt;br /&gt;  CommonDialog1.Flags = cdlCFEffects Or cdlCFBoth&lt;br /&gt;  CommonDialog1.ShowFont&lt;br /&gt;  TextColor = CommonDialog1.Color&lt;br /&gt;  Bold = CommonDialog1.FontBold&lt;br /&gt;  Italic = CommonDialog1.FontItalic&lt;br /&gt;  Underline = CommonDialog1.FontUnderline&lt;br /&gt;  Strikethru = CommonDialog1.FontStrikethru&lt;br /&gt;  Font = CommonDialog1.FontName&lt;br /&gt;  Size = CommonDialog1.FontSize&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Displaying a Print dialog box&lt;br /&gt;&lt;br /&gt;A Print dialog box lets users choose the printer, the print range, and the print quantity.&lt;br /&gt;&lt;br /&gt;To display a Print dialog box, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;CommonDialog1.ShowPrinter&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub mnuFilePrint_Click( )&lt;br /&gt;  CommonDialog1.ShowPrinter&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;To set the default value for the number of copies to print, you have to use the following BASIC commands:&lt;br /&gt;&lt;br /&gt;CommonDialog1.Copies = 1&lt;br /&gt;CommonDialog1.ShowPrinter&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  CommonDialog1.Copies = 1&lt;br /&gt;  CommonDialog1.ShowPrinter&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Like the Open, Save As, Color, and Font dialog boxes, the Print dialog box looks like it works but really doesn't do anything until you write BASIC code to tell the box how to work after the user clicks on OK.&lt;br /&gt;&lt;br /&gt;Using the common dialog boxes that I discuss in this chapter can give your programs that all-important professional look and feel that people have come to expect from software. As any professional programmer can tell you, the more your program looks to be in working order, the more likely that people are going to believe that the program does work.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ PART IV&lt;br /&gt;&lt;br /&gt;THE BASICS OF WRITING CODE&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this part.....&lt;br /&gt;&lt;br /&gt;Hurray! Here's the first chapter where you actually find out how to write your own BASIC code to make your computer do something worthwhile. Until now, you may have only drawn the parts that make up a user interface (with an occasional BASIC command thrown in). But everyone knows that looks aren't everything (unless you're a centerfold, looking to marry a multimillionaire who will die within the year). What matters is not only that your user interface looks good, but that your user interface also responds to the user.&lt;br /&gt;&lt;br /&gt;Although the thought of writing BASIC code may seem intimidating, it's not. BASIC code is nothing more than a set of step-by-step instructions that tell the computer exactly what to do. So get ready to start coding (a programmers' term for writing computer commands). You'll find that programming can really be fun, easy, and almost as addictive as drawing your user interface or playing a computer game.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 14&lt;br /&gt;&lt;br /&gt;EVENT PROCEDURES&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Creating event procedures&lt;br /&gt;Viewing different event procedures&lt;br /&gt;Editing in the code window&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Whenever the user takes any action, such as clicking the mouse, pressing a key, passing out on the keyboard, or putting a bullet through the monitor, the action is called an event. The moment an event occurs, Visual Basic looks for BASIC code to tell the program what to do. The BASIC code that responds to a specific event is called an event procedure.&lt;br /&gt;&lt;br /&gt;A single Visual Basic program can consist of several thousand event procedures. If you have that many, however, you either have a tremendously complicated program or you're an incredibly incompetent programmer.&lt;br /&gt;&lt;br /&gt;With so many possible events and so many possible event procedures in a single program, how does Visual Basic know which event procedure to use?&lt;br /&gt;&lt;br /&gt;The answer is easy. When an event occurs, this event is usually directed at some part of your program's user interface. For example, most users click the mouse button only when the mouse is pointing at an object, such as a command button, check box, or menu command on the screen.&lt;br /&gt;&lt;br /&gt;Every object can have one or more event procedures, and each event procedure responds to one specific event, such as clicking the mouse or pressing a key.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Types of Events&lt;br /&gt;&lt;br /&gt;Events can be classified into three categories:&lt;br /&gt;&lt;br /&gt;Keyboard events occur when the user presses a certain key, such as Tab, or a certain keystroke combination, such as Ctrl+P.&lt;br /&gt;&lt;br /&gt;Mouse events occur when the user moves the mouse, clicks or doubleclicks the mouse button, or drags the mouse across the screen.&lt;br /&gt;&lt;br /&gt;Program events occur when a Visual Basic program does something on its own, such as loading, opening, or closing a form. Whereas keyboard and mouse events occur when the user does something, program events occur when BASIC code does something.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Although Visual Basic can respond to a multitude of events, you generally want your user interface to respond only to a few events, such as clicking the mouse or pressing a certain key. As soon as Visual Basic detects an event, your program immediately looks to see what part of the user interface needs to respond.&lt;br /&gt;&lt;br /&gt;When the user clicks the mouse, for example, Visual Basic first identifies the event. ("Okay, that was a mouse click.") Next, Visual Basic looks to see where the user clicked the mouse. ("The user clicked the mouse on the OK command button.")&lt;br /&gt;Visual Basic then finds that particular command button's event procedure, which contains BASIC code that tells your program what to do when the user clicks the mouse button.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Creating event procedures&lt;br /&gt;&lt;br /&gt;One object can respond to one or more events. For example, a command button can respond to the user's clicking the mouse button or pressing Enter.&lt;br /&gt;&lt;br /&gt;Two or more objects can respond to the same event. For example, both a command button and a check box can respond to a mouse click, but they may have different instructions that tell Visual Basic what to do next.&lt;br /&gt;&lt;br /&gt;To write an event procedure, you have to perform the following tasks:&lt;br /&gt;&lt;br /&gt;Identify the part of your user interface that is going to respond&lt;br /&gt;&lt;br /&gt;Open the Code window.&lt;br /&gt;&lt;br /&gt;Identify the event to which Visual Basic is to respond.&lt;br /&gt;&lt;br /&gt;Write BASIC code to process the event.&lt;br /&gt;&lt;br /&gt;Make sure that all the objects of your user interface have names before creating any event procedures. If you create an event procedure for an object and later change that object's name, you will have to rewrite your event procedures.&lt;br /&gt;&lt;br /&gt;The following three parts of a user interface can have events associated with them:&lt;br /&gt;&lt;br /&gt;Forms&lt;br /&gt;Objects (command buttons, check boxes, and so on)&lt;br /&gt;Pull-down menus&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* To create an event procedure for a form, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click anywhere on the form, but not on any objects on the form.&lt;br /&gt;&lt;br /&gt;2. Open the Code window by pressing F7, choosing View-&gt;Code, or double-clicking anywhere on the form (but not on any objects on the form).&lt;br /&gt;&lt;br /&gt;Visual Basic displays the Code window on the screen along with an empty event procedure.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* To create an event procedure for an object, such as a command button or check box, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the object so that little black rectangles (handles) appear around it.&lt;br /&gt;&lt;br /&gt;2. Open the Code window by pressing F7, choosing View-&gt;Code, or by double-clicking on the object.&lt;br /&gt;&lt;br /&gt;Visual Basic displays the Code window on the screen along with an empty event procedure. You may still have to click on the Procedure list box to choose a specific event to respond to, such as Click or KeyPress.&lt;br /&gt;&lt;br /&gt;If you double-click on an object (such as a command button), Visual Basic displays the Code window right away.&lt;br /&gt;&lt;br /&gt;* To create an event procedure for a pull-down menu, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Click on the pull-down menu title containing the menu command you want.&lt;br /&gt;&lt;br /&gt;2. Click on the menu command you want to write BASIC code for.&lt;br /&gt;&lt;br /&gt;Visual Basic displays the Code window on the screen along with an empty event procedure.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Getting to know the parts of event procedures&lt;br /&gt;&lt;br /&gt;When you create an event procedure for the first time, Visual Basic displays an empty event procedure in the Code window. All empty event procedures consist of two lines, such as:&lt;br /&gt;&lt;br /&gt;Private Sub cmdExit_Click( )&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The first line of any event procedure contains five parts:&lt;br /&gt;&lt;br /&gt;Private Sub: Identifies the procedure as a subroutine.&lt;br /&gt;&lt;br /&gt;The object's name: In this example, the object is a command button named cmdExit.&lt;br /&gt;&lt;br /&gt;An underscore&lt;br /&gt;&lt;br /&gt;The event name: In this example, the event is a mouse click.&lt;br /&gt;&lt;br /&gt;A pair of parentheses, containing any data that the subroutine may need to work: In this example, the parentheses are empty, indicating that no additional data is necessary.&lt;br /&gt;&lt;br /&gt;The preceding event procedure says to the computer, "Here are the instructions to follow whenever the user clicks the mouse on the command button named cmdExit. Now leave me alone."&lt;br /&gt;&lt;br /&gt;Because this example contains no instructions to follow, this event procedure does absolutely nothing, much like many co-workers you may know.&lt;br /&gt;&lt;br /&gt;Any time you change the name of an object, make sure that you change the name of all event procedures connected to the newly named object as well. Otherwise, Visual Basic doesn't know which event procedures belong to which objects on your user interface.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Splitting the Code window in half&lt;br /&gt;&lt;br /&gt;After you start to write lots of event procedures, the Code window may not be able to display all your event procedures at the same time. If you want to view two or more event procedures on the screen at the same time, you can split the Code window in half horizontally. You can divide the Code window only in half (not in thirds, quarters, and so on).&lt;br /&gt;&lt;br /&gt;* To split the Code window in half, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Move the mouse pointer to the Split bar.&lt;br /&gt;&lt;br /&gt;The Split bar appears at the top of the vertical scroll bar. As soon as the mouse pointer appears over the Split bar, the mouse pointer turns into two horizontal parallel lines with arrows pointing up and down.&lt;br /&gt;&lt;br /&gt;2. Hold down the left mouse button and drag the mouse down.&lt;br /&gt;&lt;br /&gt;When the Split bar divides the Code window the way you want, let go of the mouse button.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* To display the Code window as a single window again, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Move the mouse pointer over the Split bar that divides the Code window in half.&lt;br /&gt;&lt;br /&gt;The mouse pointer turns into two horizontal parallel lines with arrows pointing up and down.&lt;br /&gt;&lt;br /&gt;2. Hold down the left mouse button and drag the mouse all the way up to the top (or bottom) of the Code window, then let go of the mouse button.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Editing in the Code Window&lt;br /&gt;&lt;br /&gt;The Code window works like a simple word processor. Table 14-1 lists the different keystroke commands you can use to edit your event procedures.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TABLE 14-1&lt;br /&gt;Common Editing Keys&lt;br /&gt;&lt;br /&gt;Keystroke - Delete&lt;br /&gt;What Happens - Deletes the character to the right of the cursor&lt;br /&gt;&lt;br /&gt;Keystroke - Backspace&lt;br /&gt;What Happens - Deletes the character to the left of the cursor&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+Y&lt;br /&gt;What Happens - Deletes the line that the cursor is on&lt;br /&gt;&lt;br /&gt;Keystroke - Home&lt;br /&gt;What Happens - Moves the cursor to the front of the line that the cursor is on&lt;br /&gt;&lt;br /&gt;Keystroke - End&lt;br /&gt;What Happens - Moves the cursor to the end of the line that the cursor is on&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+Home&lt;br /&gt;What Happens - Moves the cursor to the first event procedure&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+End&lt;br /&gt;What Happens - Moves the cursor to the last event procedure&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+Down arrow&lt;br /&gt;What Happens - Displays the next procedure&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+Up Arrow&lt;br /&gt;What Happens - Displays the previous procedure&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+Page Down&lt;br /&gt;What Happens - Goes to the first line of the next procedure&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+Page Up&lt;br /&gt;What Happens - Goes to the first line of the current or previous procedure&lt;br /&gt;&lt;br /&gt;Keystroke - Shift+F2&lt;br /&gt;What Happens - If the cursor appears in a procedure name, this command displays the BASIC code of that procedure&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+Right arrow&lt;br /&gt;What Happens - Goes one word to the right&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+Left arrow&lt;br /&gt;What Happens - Goes one word to the left&lt;br /&gt;&lt;br /&gt;Keystroke - Page Down&lt;br /&gt;What Happens - Displays the next page down in the Code window&lt;br /&gt;&lt;br /&gt;Keystroke - Page Up&lt;br /&gt;What Happens - Displays the next page up in the Code window&lt;br /&gt;&lt;br /&gt;Keystroke - Insert&lt;br /&gt;What Happens - Toggles the Insert mode on or off&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+X&lt;br /&gt;What Happens - Cuts a selected block of text&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+C&lt;br /&gt;What Happens - Copies a selected block of text&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+V&lt;br /&gt;What Happens - Pastes a previously Cut or Copied block of text&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+Z&lt;br /&gt;What Happens - Undoes the last thing you did (typed a letter, erased a sentence, and so on)&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+F&lt;br /&gt;What Happens - Finds a word that you specify&lt;br /&gt;&lt;br /&gt;Keystroke - F1&lt;br /&gt;What Happens - Displays the Visual Basic help system&lt;br /&gt;&lt;br /&gt;Keystroke - F3&lt;br /&gt;What Happens - Finds the next word that you specified previously using the Ctrl+F command&lt;br /&gt;&lt;br /&gt;Keystroke - Shift+F3&lt;br /&gt;What Happens - Finds the last occurrence of the word that you specified previously using the Ctrl+F command&lt;br /&gt;&lt;br /&gt;Keystroke - F6&lt;br /&gt;What Happens - Switches between Code window panes (if the Code window is split)&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+H&lt;br /&gt;What Happens - Searches for a word and replaces it with something else&lt;br /&gt;&lt;br /&gt;Keystroke - Ctrl+P&lt;br /&gt;What Happens - Displays the Print Dialog box&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To help you write BASIC code, the Code window also automatically high-lights BASIC reserved keywords in color. This way you can see which commands are BASIC reserved keywords and which are commands you've created on your own.&lt;br /&gt;&lt;br /&gt;To delete an entire event procedure, highlight the procedure by using the mouse or the cursor keys and press Delete.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Viewing Different Event Procedures&lt;br /&gt;&lt;br /&gt;A typical Visual Basic program consists of event procedures stored in FRM form files. To help you find a particular event procedure to examine or edit, you have two choices:&lt;br /&gt;&lt;br /&gt;Choose an object name from the Object list box and then choose an event from the Procedure list box in the Code window.&lt;br /&gt;&lt;br /&gt;Use the Object Browser window.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Choosing an event procedure with the Object and Procedure list boxes&lt;br /&gt;&lt;br /&gt;To use the Object and Procedure list boxes to find an event procedure, you must know the FRM form file where Visual Basic has stored the event procedure. The Object list box contains all the objects stored on a form. If you click on the Object list box, you can find the object containing the event procedure that you want to see.&lt;br /&gt;&lt;br /&gt;The Procedure list box contains all the events that an object can respond to. Each time you select a different event, Visual Basic displays a different event procedure in the Code window.&lt;br /&gt;&lt;br /&gt;* To display an event procedure by using the Object and Procedure list boxes, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose one of the following to switch to the Project Explorer window:&lt;br /&gt;&lt;br /&gt;* Click on the Project Explorer window with the mouse&lt;br /&gt;* Press CtrL+R&lt;br /&gt;* Choose View-&gt;Project Explorer&lt;br /&gt;&lt;br /&gt;2. Click on the form file that contains the event procedure that you want.&lt;br /&gt;3. Click on the View Code icon in the Project Explorer window (or choose View-&gt;Code).&lt;br /&gt;4. Click on the downward-pointing arrow of the Object list box and click on an object name.&lt;br /&gt;5. Click on the downward-pointing arrow of the Procedure list box and click on an event name.&lt;br /&gt;Visual Basic displays your chosen event procedure.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If an event procedure contains BASIC code, the Procedure list box displays the event name in bold-face type. If an event name appears in normal type, then that event procedure is empty.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Choosing an event procedure with the Object Browser window&lt;br /&gt;&lt;br /&gt;The Object Browser is most useful when you want to view event procedures stored in different files.&lt;br /&gt;&lt;br /&gt;* To display an event procedure with the Object Browser, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose View-&gt;Object Browser, or press F2 to display the Object Browser Window.&lt;br /&gt;2. Click on the downward-pointing arrow in the Project/Library list box and click on the Project that contains the event procedure you want to see.&lt;br /&gt;3. Click on a Form file name that appears in the Classes left pane.&lt;br /&gt;&lt;br /&gt;All event procedures stored in that Form file appear in bold-face in the right pane.&lt;br /&gt;&lt;br /&gt;4. Double-click on the event procedure that appears in the right pane.&lt;br /&gt;&lt;br /&gt;Table 14-2 lists the most common events to which objects can respond.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** TABLE 14-2&lt;br /&gt;Common Events&lt;br /&gt;&lt;br /&gt;Event - Activate&lt;br /&gt;Occurs When - A form becomes the active window&lt;br /&gt;&lt;br /&gt;Event - Change&lt;br /&gt;Occurs When - The contents of a combo box, directory list box, drive list box, scroll bar, label, picture box, or text box change.&lt;br /&gt;&lt;br /&gt;Event - Click&lt;br /&gt;Occurs When - The user clicks the mouse button once on the object&lt;br /&gt;&lt;br /&gt;Event - DblClick&lt;br /&gt;Occurs When - The user clicks the mouse button twice in rapid succession on an object&lt;br /&gt;&lt;br /&gt;Event - Deactivate&lt;br /&gt;Occurs When - A form changes from being an active window to an inactive window&lt;br /&gt;&lt;br /&gt;Event - DragDrop&lt;br /&gt;Occurs When - The user holds down the mouse button on an object, moves the mouse, and releases the mouse button&lt;br /&gt;&lt;br /&gt;Event - DragOver&lt;br /&gt;Occurs When - The user holds down the mouse button on an object and moves the mouse.&lt;br /&gt;&lt;br /&gt;Event - DropDown&lt;br /&gt;Occurs When - The list portion of a combo box drops down to display a list of choices&lt;br /&gt;&lt;br /&gt;Event - GotFocus&lt;br /&gt;Occurs When - An object becomes highlighted when the user presses Tab or clicks on an object, or if a form loads.&lt;br /&gt;&lt;br /&gt;Event - KeyDown&lt;br /&gt;Occurs When - The user presses a key&lt;br /&gt;&lt;br /&gt;Event - KeyPress&lt;br /&gt;Occurs When - The user presses and releases an ANSI key, such as a keyboard character, Ctrl key combination, Enter, or backspace key. (Basically, an ANSI key can be any letter, number, or oddball keystroke combination that you press).&lt;br /&gt;&lt;br /&gt;Event - KeyUp&lt;br /&gt;Occurs When - The user releases a key&lt;br /&gt;&lt;br /&gt;Event - LostFocus&lt;br /&gt;Occurs When - An object is no longer highlighted because the user pressed Tab or clicked on another object, or if a form has unloaded.&lt;br /&gt;&lt;br /&gt;Event - MouseDown&lt;br /&gt;Occurs When - The user presses a mouse button&lt;br /&gt;&lt;br /&gt;Event - MouseMove&lt;br /&gt;Occurs When - The user moves the mouse&lt;br /&gt;&lt;br /&gt;Event - MouseUp&lt;br /&gt;Occurs When - The user releases a mouse button&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The combination of the object name and the event name defines the name for an event procedure. Because object names must always be unique, no two event procedures on the same form can have the same name.&lt;br /&gt;&lt;br /&gt;Although no two event procedures on the same form can share the same name, event procedures on different forms can have the same name. For example, you might have a command button named cmdExit that appears on two different forms. If this happens, you can have the following event procedure stored on both forms:&lt;br /&gt;&lt;br /&gt;Private Sub cmdExit_Click( )&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Two or more objects can share the same name if you make them into a control array. No need to memorize this term right now. Just make a note of this term and move on. If you really want to know about control arrays, pick up a copy of the latest edition of More Visual Basic For Dummies.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** The Event Procedure That Every Program Needs&lt;br /&gt;&lt;br /&gt;The simplest and most important event procedure that every program needs is one that stops your program. The following event procedure tells Visual Basic to stop running your program the moment the user clicks on a command button named cmdExit:&lt;br /&gt;&lt;br /&gt;Private Sub cmdExit_Click( )&lt;br /&gt;  Unload Me&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;If you don't include an event procedure to stop your program, the only way a user can stop your program is by rebooting the computer or turning the whole system off. Because this isn't the best way to exit a program, always make sure that your program contains at least one (or more) ways for the user to exit your program at any given moment.&lt;br /&gt;&lt;br /&gt;The old way to stop a Visual Basic program was to use the End keyword, such as:&lt;br /&gt;&lt;br /&gt;Private Sub cmdExit_Click( )&lt;br /&gt;  End&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;However, Microsoft recommends that instead of using the End keyword, you should use the Unload Me command instead. However, the Unload Me command stops a Visual Basic program only if all forms of your program have been unloaded using the Unload command. If even one form of your program is not unloaded, the Unload Me command will not stop a Visual Basic program from running.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. What is an event, and what are the three types of events?&lt;br /&gt;&lt;br /&gt;a. An event is something that you must get tickets for, such as a concert, a sports event, or the circus.&lt;br /&gt;&lt;br /&gt;b. Events are things that happen to your computer, such as having a drink spilled on the keyboard, having all your files&lt;br /&gt;erased by mistake, and having the dog eat a floppy disk.&lt;br /&gt;&lt;br /&gt;c. Events occur when the user presses a key or mouse button or when the program changes appearance. The three types are keyboard, mouse, and program events.&lt;br /&gt;&lt;br /&gt;d. An event is a holiday or celebration that lets you take the day off from work. The three types of events are legal holidays,&lt;br /&gt;reunions, and funerals for non-existent relatives.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. What do the Object list box and Procedure list box do in the Code window?&lt;br /&gt;&lt;br /&gt;a. They list all the possible reasons why you need to write your program in C++ or Java rather than in Visual Basic.&lt;br /&gt;&lt;br /&gt;b. The Object list box lets you choose an object for which you can write an event procedure. The Procedure list box lets you choose all the possible events to which an object can respond.&lt;br /&gt;&lt;br /&gt;c. The Object list box contains a list of all the blunt objects you can use to hit your computer. The Procedure list box lists all the events that you can attend instead of staring at your computer screen.&lt;br /&gt;&lt;br /&gt;d. Neither list box does anything worth remembering, so don't bother to ask me this question again.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 15&lt;br /&gt;&lt;br /&gt;USING VARIABLES&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter....&lt;br /&gt;&lt;br /&gt;Using Variables&lt;br /&gt;Assigning numbers and strings to variables&lt;br /&gt;Declaring data types&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After you know what you want your program to do, you can start writing BASIC code. The first code you need to write is inside your event procedures.&lt;br /&gt;&lt;br /&gt;At the simplest level, an event procedure tells the computer what to do. An event procedure for exiting a program, for example, gives the computer a single Unload Me instruction:&lt;br /&gt;&lt;br /&gt;Private Sub cmdExit_Click( )&lt;br /&gt;  Unload Me&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;This event procedure requires absolutely no information from the user beyond the simple event of the user's clicking on the cmdExit command button.&lt;br /&gt;&lt;br /&gt;What happens, however, when a user types a name, an address, or a telephone number into a program? Obviously, the program must read this information from the user interface and then do something with the information.&lt;br /&gt;&lt;br /&gt;The CD-ROM contains a simple program to show you how to declare, use, and display a string variable in a text box on two different forms.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Reading Data&lt;br /&gt;&lt;br /&gt;Any information that a program gets from outside the computer is data. Nearly all but the simplest programs receive data, do something to the data, and spit the data out again.&lt;br /&gt;&lt;br /&gt;A word processor receives data as words, which the word processor formats to look pretty and then prints neatly on paper. A database receives data as names, addresses, and phone numbers. The database stores this information someplace and then displays the data in a way that you think is useful. A nuclear-missile guidance system receives data as target coordinates. The missile system uses this data to guide a warhead to a target and wipe entire cities off the planet in the name of peace.&lt;br /&gt;&lt;br /&gt;Every useful program in the world follows these three basic steps:&lt;br /&gt;&lt;br /&gt;1. Get data.&lt;br /&gt;2. Do something to the data.&lt;br /&gt;3. Spit the data back out again.&lt;br /&gt;&lt;br /&gt;Every useless program in the world has these four characteristics:&lt;br /&gt;&lt;br /&gt;Is too hard to understand and use&lt;br /&gt;Costs a great deal of money&lt;br /&gt;Claims to be user-friendly&lt;br /&gt;Doesn't work&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The whole purpose of a program is to turn computers into electronic sausage grinders. Stick information in one end and out comes the information on the other end. No matter what kind of program you examine - word processor, spreadsheet, database, or game - all programs manipulate the following:&lt;br /&gt;&lt;br /&gt;Numbers&lt;br /&gt;Strings&lt;br /&gt;&lt;br /&gt;Numbers can be positive or negative, whole numbers or fractions, or just about any other type of number you can think of (including telephone numbers to hot dates, numbers that form a combination to a safe containing wads of money, and imaginary numbers that no one except mathematicians truly understand).&lt;br /&gt;&lt;br /&gt;Strings are characters strung together. A character is anything you can type from the keyboard, including letters, punctuation marks, and (don't get confused now) numbers.&lt;br /&gt;&lt;br /&gt;Depending on how the program decides to treat them, numbers can be considered as numbers or as a string. For example, most programs treat your telephone number or street address as a string but treat your age or weight as a number.&lt;br /&gt;&lt;br /&gt;A single letter is considered a string. An entire sentence is also a string. You can even consider the first chapter of War and Peace a string. Strings can be any collection of letters, spaces, and numbers grouped together.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Values and Variables&lt;br /&gt;&lt;br /&gt;When you type a number or a string into a program, how does the computer keep track of that number or string? After all, you may know that 555-1234 represents a phone number, but to the computer, the phone number is just another number or string.&lt;br /&gt;&lt;br /&gt;To store data, programs use variables, a time-tested concept from algebra. When you write a program, you have to tell the program, "Okay, when someone types 555-1234, give this number a name, such as PhoneNumber, and store the number someplace where you can find it again."&lt;br /&gt;&lt;br /&gt;When your program needs to retrieve or manipulate this data, the program says, "Okay, where did I put this information? Oh, that's right, I stored the information in a place (variable) called PhoneNumber." The computer obediently rushes to the PhoneNumber variable and yanks out whatever number or word the computer stored there.&lt;br /&gt;&lt;br /&gt;Variables can hold a wide variety of data (which is why they're called variables, a more scientific-sounding name than flaky, wishy-washy, or schizophrenic). The information stored in a variable is called a value because a value represents either a string or a number.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Using variabtes&lt;br /&gt;&lt;br /&gt;Two types of variables exist:&lt;br /&gt;&lt;br /&gt;Those you make up&lt;br /&gt;Those already defined as the properties of every object on a form&lt;br /&gt;&lt;br /&gt;Every time you draw an object to make your user interface, Visual Basic automatically creates a whole bunch of variables (called properties) set with default values. To look at the values of an object's properties, you have to use the Properties window. (Press F4 or choose View-&gt;Properties Window.)&lt;br /&gt;&lt;br /&gt;Property values can represent numbers (such as defining the width and height of an object), True or False (such as defining whether an object is visible), or strings (such as captions on a command button). Properties simply define the appearance of an object on the screen.&lt;br /&gt;&lt;br /&gt;Variables are names that can represent any type of value. Properties are special names for variables that affect the appearance of an object.&lt;br /&gt;&lt;br /&gt;To create a variable on your own, just give the variable a name. After you type a name for a variable, the variable magically springs into existence. You have two ways to create a variable:&lt;br /&gt;&lt;br /&gt;Use the Dim statement to declare the variable.&lt;br /&gt;Just name the variable and assign a value to it.&lt;br /&gt;&lt;br /&gt;The only place where you can type (and create) a variable name is in the Code window. The only place in the Code window where you can type a variable name is sandwiched between the first and last lines of a procedure.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Declaring variables:&lt;br /&gt;&lt;br /&gt;Creating a variable is as simple as typing a name and assigning a value to the variable, as shown in the following example:&lt;br /&gt;&lt;br /&gt;Private Sub Form1-Load( )&lt;br /&gt;  PetName "Bo the cat"&lt;br /&gt;  Age = 6&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The preceding event procedure says the following:&lt;br /&gt;&lt;br /&gt;1. When a form named Form  loads, follow these instructions.&lt;br /&gt;2. First, create a variable called PetName and set the value to the string "Bo the cat".&lt;br /&gt;3. Second, create a variable called Age and set the value to the number 6.&lt;br /&gt;&lt;br /&gt;Although creating a variable out of thin air in the middle of a procedure is perfectly acceptable, this is not considered good programming practice. Unless you examine an event procedure line by line, you have no idea how many variables the procedure may be using.&lt;br /&gt;&lt;br /&gt;A better programming practice is to declare your variables at the beginning of each event procedure. To declare a variable, use the Dim command, as shown in the following example:&lt;br /&gt;&lt;br /&gt;Dim VariableName1,  VariableName2&lt;br /&gt;&lt;br /&gt;Type as many variable names as you want in the preceding command.&lt;br /&gt;&lt;br /&gt;Rewriting the preceding event procedure causes the procedure to look like the following:&lt;br /&gt;&lt;br /&gt;Private Sub Form1_Load( )&lt;br /&gt;Dim PetName, Age&lt;br /&gt;  PetName = "Bo the cat"&lt;br /&gt;  Age = 6&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;You can also declare variables explicitly, as in the following:&lt;br /&gt;&lt;br /&gt;Dim PetName as String, Age as Integer&lt;br /&gt;&lt;br /&gt;I give you the details on this technique in this chapter's section called "Data types."&lt;br /&gt;&lt;br /&gt;Although declaring a variable can add an extra line or two to an event procedure, do you see how easy you can find the names of all the variables used? Instead of examining an event procedure line by line, you can just glance at the first few lines and see a list of all the variable names used.&lt;br /&gt;&lt;br /&gt;Using the Dim statement simply helps you, the programmer, understand what the procedure does. As far as the computer is concerned, the computer doesn't care whether you use the Dim statement or not.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Naming variables:&lt;br /&gt;&lt;br /&gt;You can name your variables anything you want, and you can store anything you want in them.&lt;br /&gt;&lt;br /&gt;However, naming a variable PhoneNumber and then stuffing somebody's address in the variable is pretty foolish.&lt;br /&gt;&lt;br /&gt;To make your life easier, give your variables names that represent the data you're going to store in them. For example, naming a variable PhoneNumber makes sense if you're going to store phone numbers in the variable. Likewise, you want a variable named BusinessName to hold only the words that make up business names.&lt;br /&gt;&lt;br /&gt;When naming your variables, you must adhere to some unbreakable rules, which follow; otherwise, Visual Basic throws a tantrum. All variables must:&lt;br /&gt;&lt;br /&gt;Begin with a letter&lt;br /&gt;Be a maximum of 255 characters in length (with an obvious minimum of one character in length).&lt;br /&gt;Contain only letters, numbers, and the underscore character (_); spaces and punctuation marks are not allowed.&lt;br /&gt;Be any word except a Visual Basic reserved word, such as End or Sub.&lt;br /&gt;&lt;br /&gt;If your variable names meet these criteria, all is going to be well. (Of course, that doesn't mean your program is going to work, but at least Visual Basic is going to be happy.) The following are examples of Visual Basic-approved variable names:&lt;br /&gt;&lt;br /&gt;     Phone&lt;br /&gt;     Here_is_Your_Name&lt;br /&gt;     Route66&lt;br /&gt;&lt;br /&gt;The following are some no-nos for variable names, which Visual Basic refuses to use:&lt;br /&gt;&lt;br /&gt;     123Surprise  (This name begins with a number)&lt;br /&gt;     Just Work (This name contains a space)&lt;br /&gt;     Sub (This name is a Visual Basic reserved keyword).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Assigning numbers to variables&lt;br /&gt;&lt;br /&gt;Now that you know how to create variables by naming them, how do you assign a value to a variable and get the value back out again? Easy - you use something mysterious called an equal sign (=).&lt;br /&gt;&lt;br /&gt;To assign a value to a variable, you have to write a BASIC command, as in the following example:&lt;br /&gt;&lt;br /&gt;VariableName = Value&lt;br /&gt;&lt;br /&gt;Rather than telling the computer, "Hey, stupid. Assign the number 36 to a variable named Age," you can just write:&lt;br /&gt;&lt;br /&gt;Age = 36&lt;br /&gt;&lt;br /&gt;Variables can hold only one value at a time. If a variable already holds a value and you assign another one to the variable, the variable cheerfully tosses out the old value and accepts the new one. You can give two commands, as in the following example:&lt;br /&gt;&lt;br /&gt;Age = 36&lt;br /&gt;Age = 49&lt;br /&gt;&lt;br /&gt;Visual Basic first says, "Okay, let my variable named Age hold the number 36." Then Visual Basic looks at the second line and says, "Okay, let my variable named Age hold the number 49, and forget that the number 36 ever existed."&lt;br /&gt;&lt;br /&gt;Because the properties of an object are variables, you can assign values to an object's property in the same way. For example, suppose that you wanted to change the Height property of a text box named txtPassword to 1200. Here's how you do this:&lt;br /&gt;&lt;br /&gt;txtPassword.Height = 1200&lt;br /&gt;&lt;br /&gt;This tells Visual Basic, "Find the object named txtPassword and change the Height property to 1200"&lt;br /&gt;&lt;br /&gt;If you want to be more specific, you can even do this:&lt;br /&gt;&lt;br /&gt;frmSecret!txtPassword.Height = 1200&lt;br /&gt;&lt;br /&gt;This tells Visual Basic, "On the form named frmSecret, find the object named txt Password and change the Height property to 1200"&lt;br /&gt;&lt;br /&gt;If you don't include the form's name, Visual Basic assumes that the object you want is located on the form containing your BASIC code. To retrieve the value from an object's property (such as finding out the height of a text box), assign a variable to that object's property such as:&lt;br /&gt;&lt;br /&gt;DimButtonHeight As Integer&lt;br /&gt;  ButtonHeight = txtEatThis.Height&lt;br /&gt;&lt;br /&gt;1. Create a variable called ButtonHeight as an integer variable.&lt;br /&gt;2. Assign the variable called ButtonHeight to the value stored in the Height property of a text box named txtEatThis.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Assigning strings to variables&lt;br /&gt;&lt;br /&gt;Assigning strings to variables is similar to assigning numbers to variables. The only difference is that you have to surround a string with quotation marks so that Visual Basic knows where the string begins and ends.&lt;br /&gt;&lt;br /&gt;For example, you can assign a variable with a single-word string:&lt;br /&gt;&lt;br /&gt;Name = "John"&lt;br /&gt;&lt;br /&gt;Or you can assign a variable with a string consisting of two or more words:&lt;br /&gt;&lt;br /&gt;Name = "John Doe".&lt;br /&gt;&lt;br /&gt;Or&lt;br /&gt;&lt;br /&gt;Name = "John Smith Doe the Third and proud of it"&lt;br /&gt;&lt;br /&gt;Not all strings consist of letters. Sometimes you may want to assign a variable with a phone number or social security number, as follows:&lt;br /&gt;&lt;br /&gt;PhoneNumber = "555-1234"&lt;br /&gt;SocialSecurity = "123-45-6789"&lt;br /&gt;&lt;br /&gt;What happens if you don't include the quotation marks and just type the following?&lt;br /&gt;&lt;br /&gt;PhoneNumber = 155-1234&lt;br /&gt;SocialSecurity = 123-45-6789&lt;br /&gt;&lt;br /&gt;Without the quotation marks, Visual Basic thinks the hyphen is a subtraction symbol and that you want the program to calculate a new result. Instead of storing 555-1234 in the PhoneNumber variable, Visual Basic stores the number -679. Instead of storing 123-45-6789 in the Social Security variable, Visual Basic stores -6711.&lt;br /&gt;&lt;br /&gt;The golden rule of assigning variables is this: When you assign a variable with letters or numbers that you want treated as a string, put quotation marks around the letters or numbers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Modifying properties&lt;br /&gt;&lt;br /&gt;Assigning a variable with numbers or strings isn't some dry, academic exercise that has little relation to anything in real life. For example, if you want to display a message on the screen, you need to modify the properties of a label or text box. If you want to create animation, you need to constantly change the Left and Top properties that define an object's position on the screen. Because the properties of an object are variables, you can modify an object by assigning new values to the object's properties.&lt;br /&gt;&lt;br /&gt;Suppose that the two command buttons and the text boxes, shown in Figures 15-2 and 15-3, have the following properties:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Text Box&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - txtMessage&lt;br /&gt;&lt;br /&gt;Property - Text&lt;br /&gt;Setting - (Empty)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Top Command button&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - cmdHello&lt;br /&gt;&lt;br /&gt;Property - Caption&lt;br /&gt;Setting - &amp;amp;Hello&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Bottom command button&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - cmdBye&lt;br /&gt;&lt;br /&gt;Property - Caption&lt;br /&gt;Setting - &amp;amp;Good-bye&lt;br /&gt;&lt;br /&gt;Now, suppose that the first command button has the following event procedure:&lt;br /&gt;&lt;br /&gt;Private Sub cmdHello_Click( )&lt;br /&gt;  txtMessage.Text = "Hello, world!"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;And the second command button has the following event procedure:&lt;br /&gt;&lt;br /&gt;Private Sub cmdBye_Click( )&lt;br /&gt;  txtMessage.Text - "Good-bye, cruel world!"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;When you click on the Hello command button, this is what happens:&lt;br /&gt;&lt;br /&gt;1. Visual Basic detects the Click event and notices that the mouse is pointing to a command button named cmdHello.&lt;br /&gt;2. Visual Basic quickly finds the event procedure named cmdHello-Click( ) and looks for further instructions.&lt;br /&gt;3. The cmdHello-Click( ) event procedure tells Visual Basic, "Find a text box named txt Message and replace the Text property with the string "Hello, world!' "&lt;br /&gt;4. The string "Hello, world!" pops up inside the text box named txtMessage.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When you click on the Good-bye command button, the following process happens:&lt;br /&gt;&lt;br /&gt;1. Visual Basic detects the Click event and notices that the mouse is pointing to a command button named cmdBye.&lt;br /&gt;2. Visual Basic quickly finds the event procedure named cmdBye-Click and looks for further instructions.&lt;br /&gt;3. The cmdBye_Click( ) event procedure tells Visual Basic, "Find a text box named txtMessage and replace the Text property with the string "Good-bye, cruel world!" "&lt;br /&gt;4. The string "Good - bye, cruel world! " pops up inside the text box named txtMessage .&lt;br /&gt;&lt;br /&gt;You can use BASIC code to modify the properties of any object that appears on a form. By modifying the properties of other objects, you can display messages and information to the user.&lt;br /&gt;&lt;br /&gt;The only property that BASIC code cannot change is the Name property of any object. The only way to change the Name property of an object is through the Properties window.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Assigning variables to other variables&lt;br /&gt;&lt;br /&gt;Besides assigning numbers or strings to a variable, you can also assign the value of one variable to another variable. To do this, you have to write a BASIC command like the following:&lt;br /&gt;&lt;br /&gt;FirstVariableName = SecondVariableName&lt;br /&gt;&lt;br /&gt;For example, consider adding a second text box with the following properties.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Second text box&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - txtCopyCat&lt;br /&gt;&lt;br /&gt;Property - Text&lt;br /&gt;Setting - (Empty)&lt;br /&gt;&lt;br /&gt;Consider the following modifications to the cmdHello_Click event procedure:&lt;br /&gt;&lt;br /&gt;Private Sub cmdHello_Click( )&lt;br /&gt;  txtMessage.Text = "Hello, world!"&lt;br /&gt;  txtCopyCat.Text = txtMessage.Text&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;And to the cmdBye-Click event procedure:&lt;br /&gt;&lt;br /&gt;Private Sub cmdBye_Click( )&lt;br /&gt;  txtMessage.Text = "Good-bye, cruel world!"&lt;br /&gt;  txtCopyCat.Text = txtMessage.Text&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Now when you click on the Hello command button, this is what happens:&lt;br /&gt;&lt;br /&gt;1 . Visual Basic detects the Click event and notices that the mouse is pointing to a command button named cmdHello.&lt;br /&gt;&lt;br /&gt;2. Visual Basic quickly finds the event procedure named cmdHello_Click( ) and looks for further instructions.&lt;br /&gt;&lt;br /&gt;3. The cmdHello_Click( ) event procedure tells Visual Basic, "Find a text box named txtMessage and replace the Text property with the string "Hello, world!" "&lt;br /&gt;&lt;br /&gt;4. Visual Basic sees the second instruction that says, 'find a text box named txtCopyCat and replace its Text property with whatever is stored in the txtMessage. Text property."&lt;br /&gt;&lt;br /&gt;5. The string "Hello, world! " pops up inside the text box named txtMessage and the text box named txtCopyCat.&lt;br /&gt;&lt;br /&gt;And when you click on the Good-bye command button, the following happens:&lt;br /&gt;&lt;br /&gt;1. Visual Basic detects the Click event and notices that the mouse is pointing to a command button named cmdBye.&lt;br /&gt;&lt;br /&gt;2. Visual Basic quickly finds the event procedure named cmdBye_Click( ) and looks for further instructions.&lt;br /&gt;&lt;br /&gt;3. The cmdBye_Click( ) event procedure tells Visual Basic, "Find a text box named txtMessage and replace its Text property with the string "Good-bye. cruel world!" "&lt;br /&gt;&lt;br /&gt;4. Visual Basic sees the second instruction that says, "Find a text box named txtCopyCat and replace its Text property with whatever is stored in the txtMessage. Text property."&lt;br /&gt;&lt;br /&gt;5. The string "Good-bye, cruel world!" pops up inside the text box named txtMessage and the text box named txtCopyCat.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Assigning Values to Objects Stored in Other Forms&lt;br /&gt;&lt;br /&gt;To assign a value into an object's property, use this simple command:&lt;br /&gt;&lt;br /&gt;ObjectName.PropertyName = Value&lt;br /&gt;&lt;br /&gt;ObjectName is the name of the object. PropertyName is the property you want to change. Value is the number or string you want to assign to the property that is to affect the object named ObjectName.&lt;br /&gt;&lt;br /&gt;If you want to change the properties on a form that hasn't been loaded yet, you have to specify the form name such as:&lt;br /&gt;&lt;br /&gt;FormName!Ob,jectN,ame.PropertyName = Value&lt;br /&gt;&lt;br /&gt;For example, to change the Text property of the txtMessage text box, you have to type the following:&lt;br /&gt;&lt;br /&gt;txtMessage.Text = "Hello, world!"&lt;br /&gt;&lt;br /&gt;So how can you change the property of an object stored on another form? The solution is easy. You just have to specify the name of the form on which the object is stored.&lt;br /&gt;&lt;br /&gt;Figure 15-5, for example, shows two forms. Form 1 contains two text boxes, named txtMessage and txtCopyCat, and two command buttons, named cmdHello and cmdBye. Form 2 contains one text box with the following properties:&lt;br /&gt;&lt;br /&gt;Object - Form&lt;br /&gt;Property - Name&lt;br /&gt;Setting - A Second Form&lt;br /&gt;&lt;br /&gt;Object - Text Box&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Setting - txtNewBox&lt;br /&gt;&lt;br /&gt;Property - Text&lt;br /&gt;Setting - (Empty)&lt;br /&gt;&lt;br /&gt;So how can the event procedure stored in Form 1 modify the Text property of an object stored on another form? You can simply use the following command:&lt;br /&gt;&lt;br /&gt;FormName!ObjectName.PropertyName = Value&lt;br /&gt;&lt;br /&gt;FormName specifies the name of the form that contains the object you want to modify. ObjectName is the name of the object. PropertyName is the property you want to change. Value is the number or string you want to assign to the property.&lt;br /&gt;&lt;br /&gt;If you want the text box named txtNewBox to display the same message that the text boxes txtMessage and txtCopyCat display, you add the following command to the cmdHello_Click and the cmd Bye_Click event procedures:&lt;br /&gt;&lt;br /&gt;Form2!txtNewBox.Text = txtMessage.Text&lt;br /&gt;&lt;br /&gt;The cmdHello-Click event procedure now looks like this:&lt;br /&gt;&lt;br /&gt;Private Sub cmdHello_Click( )&lt;br /&gt;  txtMessage.Text = "Hello, world!"&lt;br /&gt;  txtCopyCat.Text = txtMessage.Text&lt;br /&gt;  Form2.Show&lt;br /&gt;  Form2!txtNewBox.Text = txtMessage.Text&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;And the cmdBye-Click event procedure now looks like this:&lt;br /&gt;&lt;br /&gt;Private Sub cmdBye_Click( )&lt;br /&gt;  txtMessage.Text = "Good-bye, cruel world!"&lt;br /&gt;  txtCopyCat.Text = txtMessage.Text&lt;br /&gt;  Form2.Show&lt;br /&gt;  Form2!txtNewBox.Text = txtMessage.Text&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The following explains what happens when you click on the Hello command button:&lt;br /&gt;&lt;br /&gt;1. Visual Basic detects the Click event and notices that the mouse is pointing to a command button named cmdHello.&lt;br /&gt;&lt;br /&gt;2. Visual Basic quickly finds the event procedure named cmdHello_Click and looks for further instructions.&lt;br /&gt;&lt;br /&gt;3. The cmdHello_Click( ) event procedure tells Visual Basic, "Find a text box named txtMessage and replace the Text property with the string "Hello, world!""&lt;br /&gt;&lt;br /&gt;4. Visual Basic sees the second instruction that says, "Find a text box named txtCopyCat and replace its Text property with whatever is stored in the txtMessage.Text property."&lt;br /&gt;&lt;br /&gt;5. The Form2.Show command tells Visual Basic, "Find a form named Form2 and display the form on the screen."&lt;br /&gt;&lt;br /&gt;6. The Form2!txtNewBox.Text = txtMessage.Text command tells Visual Basic, "On the form named Form2, look for a text box named txtNewBox and stuff its Text property with the value stored in the text box named txtMessage."&lt;br /&gt;&lt;br /&gt;7. The string "Hello, world! " pops up inside all three text boxes, named txtMessage, txtCopyCat, and txtNewBox.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When you click the mouse on the Good-bye command button, the following happens:&lt;br /&gt;&lt;br /&gt;1. Visual Basic detects the Click event and notices that the mouse is pointing to a command button named cmdBye.&lt;br /&gt;&lt;br /&gt;2. Visual Basic quickly finds the event procedure named cmdBye_Click and looks for further instructions.&lt;br /&gt;&lt;br /&gt;3. The cmdBye_Click event procedure tells Visual Basic, "Find a text box named txtMessage and replace its Text property with the string "Good-bye, cruel world!""&lt;br /&gt;&lt;br /&gt;4. Visual Basic sees the second instruction that says, "Find a text box named txtCopyCat and replace its Text property with whatever is stored in the txtMessage.Text property."&lt;br /&gt;&lt;br /&gt;5. The Form2.Show command tells Visual Basic, "Find a form named Form2 and display this form on the screen."&lt;br /&gt;&lt;br /&gt;6. The Form2! txt NewBox.Text = txtMessage.Text command tells Visual Basic, "On the form named Form2, look for a text box named txtNewBox and stuff the Text property with the value stored in the text boxnamed txtMessage."&lt;br /&gt;&lt;br /&gt;7. The string "Good-bye, cruel world! " pops up inside all three text boxes, named txtMessage, txtCopyCat, and txtNewBox.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Data Types&lt;br /&gt;&lt;br /&gt;Variables can hold numbers and strings. However, you may want a variable called FirstName to contain nothing but strings. If a variable called FirstName winds up holding the number 56, that variable can cause an error if the computer expects a string but gets a number instead. To restrict the type of information a variable can hold, you can declare a variable to hold a specific data type. Data types tell Visual Basic, "See this variable? This variable can hold only strings or certain types of numbers, so there!"&lt;br /&gt;&lt;br /&gt;Here are three primary reasons to use data types:&lt;br /&gt;&lt;br /&gt;So that you can easily see the type of data each variable can hold.&lt;br /&gt;To prevent variables from accidentally storing the wrong type of data and causing an error.&lt;br /&gt;To use memory more efficiently because some data types (such as double) require more memory to use than other data types (such as byte).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you write a BASIC command that attempts to assign a string into a data type that accepts only numbers, Visual Basic squawks and displays an error message. This squawking helps you catch possible errors in your program long before you finish - and distribute - your program to others.&lt;br /&gt;&lt;br /&gt;Visual Basic provides the ten data types shown in Table 15-1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** TABLE 15-1&lt;br /&gt;The Visual Basic Data Types&lt;br /&gt;&lt;br /&gt;Data Type - Byte&lt;br /&gt;Accepts Numbers That Range From - 0 to 255&lt;br /&gt;&lt;br /&gt;Data Type - Boolean&lt;br /&gt;Accepts Numbers That Range From - True or False&lt;br /&gt;&lt;br /&gt;Data Type - Currency&lt;br /&gt;Accepts Numbers That Range From - -922337203685477.5808 to 922337203685477.5807&lt;br /&gt;&lt;br /&gt;Data Type - Date&lt;br /&gt;Accepts Numbers That Range From - Dates between January 1,100 and December 31, 9999&lt;br /&gt;&lt;br /&gt;Data Type - Double&lt;br /&gt;Accepts Numbers That Range From - -1.79769313486232E308 to -4.94065645841247E-324 and 4.94065645841247E-324 to 1.79769313486232E308&lt;br /&gt;&lt;br /&gt;Data Type - Integar&lt;br /&gt;Accepts Numbers That Range From - -32,768 to 32,767&lt;br /&gt;&lt;br /&gt;Data Type - Long&lt;br /&gt;Accepts Numbers That Range From - -2,147,483,648 to 2,147,483,647&lt;br /&gt;&lt;br /&gt;Data Type - Numbers&lt;br /&gt;Accepts Numbers That Range From - Same range as Double&lt;br /&gt;&lt;br /&gt;Data Type - Single&lt;br /&gt;Accepts Numbers That Range From - -3.402823E38 to -1.401298E-45 and 1.401298E-45 to 3.402823E38&lt;br /&gt;&lt;br /&gt;Data Type - String&lt;br /&gt;Accepts Numbers That Range From - 0 to 65,5000 characters&lt;br /&gt;&lt;br /&gt;Data Type - Variant&lt;br /&gt;Accepts Numbers That Range From - (When storing numbers, same range as Double.  When storing strings, same range as String).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Visual Basic actually gives you two ways to declare a variable:&lt;br /&gt;&lt;br /&gt;Dim MyString As String&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;DimMyString$&lt;br /&gt;&lt;br /&gt;The first method can be verbose but clear. The second method uses something called type declaration characters. This makes declaring variables easier but makes your commands harder to read and understand at first glance.&lt;br /&gt;&lt;br /&gt;If you want to be clear and don't mind typing a lot of extra words like "As String" or "As Integer," use the first method. If you want to save time and don't care to make your code readable, use the second method. Here's a short table listing all the type declaration characters you can use to declare variables as different data types:&lt;br /&gt;&lt;br /&gt;Data Type - Currency&lt;br /&gt;Character - @&lt;br /&gt;Example - Dim Loot@&lt;br /&gt;Equivalent To - Dim Loot As Currency&lt;br /&gt;&lt;br /&gt;Data Type - Double&lt;br /&gt;Character - #&lt;br /&gt;Example - Dim Average#&lt;br /&gt;Equivalent To - Dim Average As Double&lt;br /&gt;&lt;br /&gt;Data Type - Integar&lt;br /&gt;Character - %&lt;br /&gt;Example - Dim Age%&lt;br /&gt;Equivalent To - Dim Age As Integer&lt;br /&gt;&lt;br /&gt;Data Type - Long&lt;br /&gt;Character - &amp;amp;&lt;br /&gt;Example - Dim Huge&amp;amp;&lt;br /&gt;Equivalent To - Dim Huge As Long&lt;br /&gt;&lt;br /&gt;Data Type - Single&lt;br /&gt;Character - !&lt;br /&gt;Example - Dim Tiny!&lt;br /&gt;Equivalent To - Dim Tiny As Single&lt;br /&gt;&lt;br /&gt;Data Type - String&lt;br /&gt;Character - $&lt;br /&gt;Example - Dim Name$&lt;br /&gt;Equivalent To - Dim Name As String&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Declaring objects as data types:&lt;br /&gt;&lt;br /&gt;To store whole numbers, use the Integer data type. If you need to store really small or really large numbers, use the Long data type. If you just need to store numbers no smaller than 0 or larger than 255, use the Byte data type.&lt;br /&gt;&lt;br /&gt;To store numbers with decimal points, use the Single data type. If you need to store really small or really large numbers with decimal points, use the Double or Numbers data type.&lt;br /&gt;&lt;br /&gt;To store numbers representing currency (that's money, in non-technical terms), use the Currency data type.&lt;br /&gt;&lt;br /&gt;To store words and letters, use the String data type.&lt;br /&gt;&lt;br /&gt;To store dates, use the Date data type.&lt;br /&gt;&lt;br /&gt;To store True or False values, use the Boolean data type.&lt;br /&gt;&lt;br /&gt;You can also use the Variant data type to store numbers or strings.&lt;br /&gt;&lt;br /&gt;By default, Visual Basic assigns all variables as a Variant data type unless you specifically tell Visual Basic otherwise. The only reason to specifically declare a variable as a Variant data type is for clarity in reading your code. As far as Visual Basic is concerned, declaring a variable as a Variant data type is redundant, such as telling people that you drive a Ford Mustang automobile.&lt;br /&gt;&lt;br /&gt;To declare a variable as a particular data type, use the following command:&lt;br /&gt;&lt;br /&gt;Dim VariableName As DataType&lt;br /&gt;&lt;br /&gt;For example, to declare a variable named MyName as a string data type, you want to use the following command:&lt;br /&gt;&lt;br /&gt;Dim MyName As String&lt;br /&gt;&lt;br /&gt;When Visual Basic sees this statement, Visual Basic thinks, "Okay, this is a variable named MyName, and the programmer defined the variable as a String data type so that this variable can hold only strings."&lt;br /&gt;&lt;br /&gt;When Visual Basic sees the statement:&lt;br /&gt;&lt;br /&gt;Dim MyName As Variant&lt;br /&gt;&lt;br /&gt;Visual Basic thinks, "Okay, this is a variable named MyName, and the programmer defined this variable as a Variant data type so that it can hold numbers or strings."&lt;br /&gt;&lt;br /&gt;And when Visual Basic sees the statement:&lt;br /&gt;&lt;br /&gt;Dim MyName&lt;br /&gt;&lt;br /&gt;Visual Basic thinks, "Okay, this is a variable named MyName; because the programmer is too lame to define the data type, I can automatically assume that this variable is a Variant data type."&lt;br /&gt;&lt;br /&gt;If you want to declare multiple variables on a single line, you must explicitly declare each variable, such as:&lt;br /&gt;&lt;br /&gt;Dim MyName As String, PetName As String&lt;br /&gt;&lt;br /&gt;Suppose you declare your variables like this:&lt;br /&gt;&lt;br /&gt;Dim MyName, PetName As String&lt;br /&gt;&lt;br /&gt;Visual Basic assumes that the MyName variable is a Variant data type and PetName is a String data type.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;An everyday event procedure:&lt;br /&gt;&lt;br /&gt;To study an actual, honest-to-goodness event procedure that declares variables as specific data types, consider the following:&lt;br /&gt;&lt;br /&gt;Private Sub Form1_Load( )&lt;br /&gt;Dim PetName As String,  Age As Integer&lt;br /&gt;  PetName = "Bo the cat"&lt;br /&gt;  Age = 6&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The variable declaration statement Dim PetName As String, Age As Integer tells Visual Basic, "Okay, create a variable named PetName and make sure that you use this variable to hold any strings."&lt;br /&gt;&lt;br /&gt;Visual Basic continues, "Then create a variable named Age and make sure that the variable holds only numbers greater than or equal to -32,768 but less than or equal to 32,767."&lt;br /&gt;&lt;br /&gt;The next command tells Visual Basic, "Assign the string "Bo the cat" to the variable PetName." Faster than a speeding bullet, Visual Basic checks to make sure that the PetName variable really can hold string values. Thankfully, the statement Dim PetName As String defined PetName to hold only string values, so everything is a-okay.&lt;br /&gt;&lt;br /&gt;Finally, Visual Basic says, "Assign the number 6 to the variable Age." Quickly, Visual Basic checks that the variable Age really can hold a number as massive as 6. Because 6 falls within the declared range of an integer (between -32,768 and 32,767), Visual Basic cheerfully allows this statement to pass as valid.&lt;br /&gt;&lt;br /&gt;Always use the smallest data type possible. For example, if you know the variable Age is never going to hold a number larger than 32,767, declare Age as a Byte data type. If you need larger or smaller numbers, choose the Long data type. By choosing the appropriate data type, you can optimize the use of your computer's memory.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* String data types&lt;br /&gt;&lt;br /&gt;In case you want to restrict the length of the strings a variable can hold, you can define the maximum length by using the following command:&lt;br /&gt;&lt;br /&gt;Dim VariableName As String * Size&lt;br /&gt;&lt;br /&gt;The value of Size can vary from 1 to 65,500. So if you want to keep a variable from storing more than ten characters, use the following command to specify Size as 10:&lt;br /&gt;&lt;br /&gt;Dim VariableName As String * 10&lt;br /&gt;&lt;br /&gt;For example, suppose that you declare the following:&lt;br /&gt;&lt;br /&gt;Dim FirstName As String * 5&lt;br /&gt;&lt;br /&gt;The following are valid strings that you can assign to the FirstName variable:&lt;br /&gt;&lt;br /&gt;" 12345 "&lt;br /&gt;&lt;br /&gt;"Bo"&lt;br /&gt;&lt;br /&gt;"Jacob"&lt;br /&gt;&lt;br /&gt;"Will"&lt;br /&gt;&lt;br /&gt;If you try to assign to the FirstName variable a string that is longer than five characters, however, this is how Visual Basic actually stores a string:&lt;br /&gt;&lt;br /&gt;String Assignment            What Really Happens&lt;br /&gt;&lt;br /&gt;FirstName = Marilyn         FirstName = Maril&lt;br /&gt;FirstName = Bobcat         FirstName = Bobca&lt;br /&gt;FirstName = King Edwards     FirstName = King&lt;br /&gt;&lt;br /&gt;If a string is too long for the declared string length of a variable, Visual Basic ruthlessly chops off the string. If you don't define a maximum string length, or if you define the variable as a Variant data type, the variable can hold up to 65,500 characters.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Scope of variables&lt;br /&gt;&lt;br /&gt;The scope of a variable determines the accessibility of a variable within a Visual Basic program. Visual Basic lets you declare the scope of variables in three ways:&lt;br /&gt;&lt;br /&gt;Local&lt;br /&gt;Module&lt;br /&gt;Public&lt;br /&gt;&lt;br /&gt;A local variable exists only within the procedure in which the variable is created, and a local variable can be used only within the procedure in which the variable is declared. The purpose of a local variable is to isolate a specific variable in the single procedure in which the variable is being used. That way, if a variable is screwing up and storing the wrong value, you can easily isolate the problem and fix it.&lt;br /&gt;&lt;br /&gt;To declare a local variable, declare the variable within an event procedure, as follows:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  Dim FulIName As String&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Remember, a local variable can be used only in the one event procedure in which the variable is declared. But what if you want to create a variable that two or more event procedures can share? In that case, you have to create a module variable.&lt;br /&gt;&lt;br /&gt;Module variables are variables that can be used only by other procedures stored in the same file.&lt;br /&gt;To declare a module variable, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Open the Code window by pressing F7, choosing View-&gt;Code, or double-clicking anywhere on the form (but not on any objects on the form).&lt;br /&gt;&lt;br /&gt;2. Click on the Object list box in the Code window and choose (General).&lt;br /&gt;Visual Basic displays (Declarations) in the Procedure list box.&lt;br /&gt;&lt;br /&gt;3. Type your variable declaration using the Dim command.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Module variables are useful for sharing a variable amoung procedures stored in the same file, such as the same Form (FRM) file. If you want to use a variable that can be used by any event procedure, no matter what file the variable may be stored in, you need to create a public variable.&lt;br /&gt;&lt;br /&gt;Public variables are variables that can be the most convenient to use, because every event procedure in your Visual Basic program can access them. But be careful! Most programmers avoid using public variables because if your program stores the wrong value in a public variable, you have to search your entire program to find the part that is messing up.&lt;br /&gt;&lt;br /&gt;By comparison, if your program messes up a module variable, you can isolate the problem in the file in which you declared the module variable. Likewise, if your program messes up a local variable, the only possible place the problem can occur is in the procedure in which you declared the local variable.&lt;br /&gt;&lt;br /&gt;To declare a public variable, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose Project-&gt;Add Module to create a BAS module file.  An Add Module dialog box appears.&lt;br /&gt;&lt;br /&gt;2. Click on Module and click on Open. Visual Basic displays the Code window with (General) displayed in the Object list box and (Declarations) in the Procedure list box.&lt;br /&gt;&lt;br /&gt;3. Declare your public variable by using the Public command. For example:&lt;br /&gt;&lt;br /&gt;Public FullName As String&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To make sure that programs are easy to understand and modify later, create local, module, or public variables. If you want to throw caution aside, you can create variables as you need them in the middle of your programs, but doing so will make your programs harder to read and understand later.&lt;br /&gt;&lt;br /&gt;If you plan to write large programs, always declare your variables. Like eating your vegetables, this is something that may seem distasteful at first but, later on, can actually be useful.&lt;br /&gt;&lt;br /&gt;To force yourself to declare your variables, just add the following command in the General area (like a module variable) in every file (Form or Module file) of your program:&lt;br /&gt;&lt;br /&gt;Option Explicit&lt;br /&gt;&lt;br /&gt;When you use the Option Explicit command, Visual Basic screams every time you try to use a variable without declaring it first.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 16&lt;br /&gt;&lt;br /&gt;RESPONDING TO THE USER&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter .....&lt;br /&gt;&lt;br /&gt;Getting data from text boxes&lt;br /&gt;Determining which radio button and check box the user chose&lt;br /&gt;Retrieving data from list boxes and scroll bars&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A user interface makes your program look nice and pretty. Unfortunately, a nice and pretty user interface can be as useless as an attractive person without any brains (think of some of your co-workers). If you want your program to have more substance than an empty-headed fashion model, you have to make sure that your program can respond intelligently to the user.&lt;br /&gt;&lt;br /&gt;To make your user interface responsive, your program must:&lt;br /&gt;&lt;br /&gt;Get information from the user interface&lt;br /&gt;Calculate a result&lt;br /&gt;Display that result back on the user interface&lt;br /&gt;&lt;br /&gt;For example, when the user chooses an item from a list box, the program has no idea which item the user chose. If you look at the screen, you may be tempted to say, "Hey, stupid computer. If I can see which item the user has chosen, why can't you?"&lt;br /&gt;&lt;br /&gt;But what you see on the user interface isn't what the computer sees. From the computer's point of view, the computer still has no idea which item the user selected from the list box.&lt;br /&gt;&lt;br /&gt;To tell the computer what action a user took, you have to write BASIC code. This BASIC code grabs information off the user interface so that your program can then do something with the information.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Getting Data from the User Interface&lt;br /&gt;&lt;br /&gt;A user interface is a simple way for users to give information to your program. For example, a user interface can offer a list box that displays several filenames. That way the user can just click on the filename they want to use.&lt;br /&gt;&lt;br /&gt;When a user gives information to a program (by pressing a particular key or clicking on a command button, files list box, and so on), Visual Basic stores this information in the object's properties. From this point on, the program can use the information.&lt;br /&gt;&lt;br /&gt;The nine basic types of objects that can get data from the user interface are as follows:&lt;br /&gt;&lt;br /&gt;Check boxes&lt;br /&gt;Radio buttons&lt;br /&gt;Combo boxes&lt;br /&gt;List boxes&lt;br /&gt;Text boxes&lt;br /&gt;Horizontal and vertical scroll bars&lt;br /&gt;Drive list boxes&lt;br /&gt;Directory list boxes&lt;br /&gt;File list boxes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Finding Information In an Object&lt;br /&gt;&lt;br /&gt;To find the information stored in an object, you need to know:&lt;br /&gt;&lt;br /&gt;The name of the object (such as txtWriteHere)&lt;br /&gt;The object's property that contains the information (such as the Text property)&lt;br /&gt;The name of the form on which the object is located (such as frmMain)&lt;br /&gt;&lt;br /&gt;When the user puts information in an object (such as typing text in a text box), Visual Basic stores the data in one of the object's properties. Different objects store information from the user in different properties. For example, a text box stores information in the Text property, but a check box stores information in the Value property.&lt;br /&gt;&lt;br /&gt;Knowing which property you want isn't enough. You also need the name of the object that holds the property you want. And because objects on different forms can have the same names, you may also need to know the name of the form where the object appears.&lt;br /&gt;&lt;br /&gt;The combination of form name, object name, and property defines the specific location of the information from the user. Think of objects as mail boxes. To retrieve a letter, you have to know the state (form name), the city (object name), and the address (property).&lt;br /&gt;&lt;br /&gt;So if you want to retrieve information from an object, you have to use the following combination:&lt;br /&gt;&lt;br /&gt;FormName!ObjectName.Property&lt;br /&gt;&lt;br /&gt;For example, you may want to retrieve information from a form named frmAttack, containing a text box named txtWarning, which stores data in the Text property, such as&lt;br /&gt;&lt;br /&gt;FrmAttack!txtWarning.Text&lt;br /&gt;.&lt;br /&gt;Whenever Visual Basic sees this code, Visual Basic automatically says to itself, "Okay, let me find the form named frmAttack, look for the object named txtWarning, and find the value stored in the Text setting. Ah, here is the value I want."&lt;br /&gt;&lt;br /&gt;If you omit the form's name, Visual Basic looks only for objects that appear on the current form. If that's where you want to look, you can shorten this combination to the following:&lt;br /&gt;&lt;br /&gt;ObjectName.Property&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Getting Data from Text Boxes&lt;br /&gt;&lt;br /&gt;When a user types something in a text box, Visual Basic stores the information in the Text property. Typing in a text box is equivalent to assigning a value in the text box's Text property.&lt;br /&gt;&lt;br /&gt;If the user types "Greetings from Mars!" in a text box named txtSecret, this is the equivalent to the following BASIC code:&lt;br /&gt;&lt;br /&gt;TxtSecret.Text - "Greetings from Mars!"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Determining which radio button the user chose&lt;br /&gt;&lt;br /&gt;A radio button can have one of two possible values stored in its Value property:&lt;br /&gt;&lt;br /&gt;True (selected)&lt;br /&gt;False (unselected)&lt;br /&gt;&lt;br /&gt;An unselected radio button has the Value property set to False. Clicking on an unselected radio button changes the Value property to True.&lt;br /&gt;&lt;br /&gt;A selected radio button has the Value property set to True. Clicking on a selected radio button changes the Value property to False.&lt;br /&gt;&lt;br /&gt;To determine which radio button the user chose, you have to check the Value properties of all your radio buttons. For example, if the user chooses an unselected radio button named optStation, choosing the button is equivalent to the following BASIC code:&lt;br /&gt;&lt;br /&gt;optStation.Value = True&lt;br /&gt;&lt;br /&gt;If the user selects a different radio button (other than the radio button named optStation), this is equivalent to the following BASIC code:&lt;br /&gt;&lt;br /&gt;optStation.Value = False&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Determining which check box the user chose&lt;br /&gt;&lt;br /&gt;A check box can have one of three possible values stored in the Value property:&lt;br /&gt;&lt;br /&gt;0 - unchecked&lt;br /&gt;1 - checked&lt;br /&gt;2 - grayed&lt;br /&gt;&lt;br /&gt;An unselected check box has the Value property set to 0. Clicking on an unselected check box changes the Value property to 1.&lt;br /&gt;&lt;br /&gt;A selected check box has the Value property set to 1. Clicking on a selected check box changes the Value property to 0.&lt;br /&gt;&lt;br /&gt;A grayed check box has the Value property set to 2. Clicking on a grayed check box changes the Value property to 0.&lt;br /&gt;&lt;br /&gt;Note that a user can still click on a grayed check box, unlike a disabled check box which also looks gray.&lt;br /&gt;&lt;br /&gt;A selected check box obviously means that the user chose the command represented by the check box. Likewise, an unselected check box means the user did not choose the command represented by the check box. A grayed check box can draw the user's attention that the grayed check box's command represents a special exception or feature.&lt;br /&gt;&lt;br /&gt;You have only two ways to set a check box's Value property to 2 and have the check box appear grayed. The first approach is to change the Value property in the Property window when you design your program. The second way is to use BASIC code. The following BASIC code sets the Value property to 2 for a check box named chkBold:&lt;br /&gt;&lt;br /&gt;chkBold.Value = 2&lt;br /&gt;&lt;br /&gt;To determine which check box the user chooses, you have to review the Value properties of all your check boxes. For example, if a check box named chkBold is blank, this is equivalent to the following BASIC code:&lt;br /&gt;&lt;br /&gt;chkBold.Value = 0&lt;br /&gt;&lt;br /&gt;If the check box is selected, this is equivalent to:&lt;br /&gt;&lt;br /&gt;chkBold.Value = 1&lt;br /&gt;&lt;br /&gt;If the check box is grayed, this is equivalent to:&lt;br /&gt;&lt;br /&gt;chkBold.Value = 2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Retrieving data from Drive, Directory, and File list boxes.&lt;br /&gt;&lt;br /&gt;When a user makes a selection from the Drive list box, Visual Basic stores the selection as a string in the Drive list box's Drive property. If a user clicks on c: in a Drive list box named drvWhichDrive, for example, this is equivalent to the following BASIC code:&lt;br /&gt;&lt;br /&gt;drvWhichDrive.Drive = "c:"&lt;br /&gt;&lt;br /&gt;When a user makes a selection from the Directory list box, Visual Basic stores the selection as a string in the Directory list box's Path property.&lt;br /&gt;&lt;br /&gt;If a user clicks on c:\dos in a Directory list box named dirFolder, for example, this is equivalent to the following BASIC code:&lt;br /&gt;&lt;br /&gt;dirFolder.Path = "c:\dos"&lt;br /&gt;&lt;br /&gt;When a user makes a selection from a File list box, Visual Basic stores the file name as a string in the File list box's FileName property.&lt;br /&gt;&lt;br /&gt;If a user clicks on autoexec.bat in a File list box named filGetFiles, for example, this is equivalent to the following BASIC code:&lt;br /&gt;&lt;br /&gt;filGetFiles.FileName = "c:\dos\autoexec.bat"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Obtaining choices from a combo box&lt;br /&gt;&lt;br /&gt;When a user chooses or types an item in a combo box, Visual Basic stores this information in the combo box's Text property.&lt;br /&gt;&lt;br /&gt;The text that a combo box displays is stored in the combo box's List property. When the user actually types an item or clicks on an item in the combo box, the user's choice is stored in the combo box's Text property.&lt;br /&gt;&lt;br /&gt;If the user types or selects an item named " ASAP " in a combo box named cboPriorities, for example, this is equivalent to the following BASIC code:&lt;br /&gt;&lt;br /&gt;cboPriorities.Text = " ASAP "&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Getting values from horizontal and vertical scroll bars&lt;br /&gt;&lt;br /&gt;Scroll bars that are not part of a text box, list box, or combo box represent a number. This number is stored in the scroll bar's Value property.&lt;br /&gt;&lt;br /&gt;The value that a scroll bar can represent is determined by the scroll bar's Min and Max properties. The lowest possible value is -32,768. The highest possible value is 32,767.&lt;br /&gt;&lt;br /&gt;Scroll bars let users visually represent a value, rather than typing a number from the keyboard. Ideally, you want to use a scroll bar along with a label that shows the actual value of the scroll bar. That way, as users move the scroll box in the scroll bar, they can also see the value of the scroll bar changing.&lt;br /&gt;&lt;br /&gt;Although scroll bars can represent a range of values, your program eventually needs to read a single value from the scroll bar. If you want to retrieve the value of a horizontal scroll bar named hsbSensitivity, for example, you have to set a variable to equal the Value property of the scroll bar. So if you have a variable named MouseSensitivity and a scroll bar named hsbSensitivity, you could use the following command:&lt;br /&gt;&lt;br /&gt;MouseSensitivity = hsbSensitivity.Value&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. What does the following BASIC command do?&lt;br /&gt;&lt;br /&gt;WhatIsIt = chkBold.Value&lt;br /&gt;&lt;br /&gt;a. The command tried to identify UFOs named chkBold.Value&lt;br /&gt;b. The command questions the need for anything named chkBold.Value&lt;br /&gt;c. The command makes the computer ask, "What do you want me to do?  Tell me and then leave me alone.  I'm feeling bold today."&lt;br /&gt;d. The command yanks a number that's stored in the Value property of a check box named chkBold and stuffs the number in a variable named WhatIsIt. If the check box named chkBold is selected, the value of WhatIsIt is 1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Examine the following command and explain what this code does.&lt;br /&gt;&lt;br /&gt;FrmDataSheet!txtMessage.Text = "Warning!"&lt;br /&gt;&lt;br /&gt;a. The command tells Visual Basic, "Okay, look for a form named frmDataSheet, and on this form find a text box named txtMessage. When you find that, stuff the Test property with the string "Warning!""&lt;br /&gt;b. The command tells everyone that the person who wrote this command probably had a good reason for not being present to help you interpret this command.&lt;br /&gt;c. The command warns you that your computer is about to explode and you had better take cover immediately.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Retrieving data from a list box&lt;br /&gt;&lt;br /&gt;A user can select one or more items from a list box depending on the list box's MultiSelect property. If the MultiSelect property is set to 0 (the default value) and a user selects an item, the list box stores the item in the Text property.&lt;br /&gt;&lt;br /&gt;If the user selects an item named " Cat food " in a list box named 1st Groceries, this is equivalent to the following BASIC code:&lt;br /&gt;&lt;br /&gt;1stGroceries.Text = "Cat food"&lt;br /&gt;&lt;br /&gt;If a list box's MultiSelect property is 1 or 2, users can hold down the Shift key and click on an item to select two or more items in the list box. Because a list box's Text property can hold only one string at a time, you can't store all the selections made by a user in the list box's Text property.&lt;br /&gt;&lt;br /&gt;To retrieve data from a list box that allows multiple selections, you have to do the following:&lt;br /&gt;&lt;br /&gt;1. Create a second list box to temporarily store any selected items from the first list box.&lt;br /&gt;2. Set this second list box's Visible property to False so that the list box isn't visible on the user interface.&lt;br /&gt;3. Every time a user selects an Item from the first list box, copy the item into the second (invisible) list box.&lt;br /&gt;&lt;br /&gt;The invisible list box contains only those items selected from another list box, and stores all items in a List property. Items in a list are assigned an index number. The first item in the list is given an index number of 0, the second item in a list is given an index number of 1, and so on. To better understand this concept, create on a blank form two list boxes and a command button with the following properties:&lt;br /&gt;&lt;br /&gt;If you don't feel like typing in the following program, just load the LISTBOXES.VBP program off the CD-ROM.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - First List Box&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Value - 1stChoose&lt;br /&gt;&lt;br /&gt;Property - MultiSelect&lt;br /&gt;Value - 1 - Simple&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Second List box&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Value - 1stTemp&lt;br /&gt;&lt;br /&gt;Property - Visible&lt;br /&gt;Value - True&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object - Command button&lt;br /&gt;&lt;br /&gt;Property - Name&lt;br /&gt;Value - cmdStore&lt;br /&gt;&lt;br /&gt;Property - Caption&lt;br /&gt;Value - Store&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If the Visible property of the second list box is False, the box is (obviously) invisible and you can't see what is happening. So, when you test the procedure, set the Visible property for the second list box to True so that you can see what happens. Then, after you've become educated, change the Visible property back to the original False setting.&lt;br /&gt;&lt;br /&gt;The following procedure stores items in the 1stChoose list box:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load( )&lt;br /&gt;  1stChoose.AddItem "Butter"&lt;br /&gt;  1stChoose.AddItem "Lard"&lt;br /&gt;  1stChoose.AddItem "Cat food"&lt;br /&gt;  1stChoose.AddItem "Milk"&lt;br /&gt;  1stChoose.AddItem "Ammunition"&lt;br /&gt;  1stChoose.AddItem "Ice Cream"&lt;br /&gt;  1stChoose.AddItem "Cookies"&lt;br /&gt;  1stChoose.AddItem "Sugar"&lt;br /&gt;  1stChoose.AddItem "Camouflage"&lt;br /&gt;  1stChoose.AddItem "Survival rations"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;This loads the 1stChoose list box with items for the user to select.&lt;br /&gt;&lt;br /&gt;An event procedure to retireve multiple selected items from the 1stChoose list box may look like the following:&lt;br /&gt;&lt;br /&gt;Private Sub cmdStore_Click( )&lt;br /&gt;  Dim I&lt;br /&gt;  1stTemp.Clear&lt;br /&gt;  For I = 0 to 1stChoose.ListCount - 1&lt;br /&gt;     If 1stChoose.Selected(I) Then&lt;br /&gt;        1stTemp.AddItem 1stChoose.List(I)&lt;br /&gt;     End If&lt;br /&gt;  Next I&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is how Visual Basic responds to the code:&lt;br /&gt;&lt;br /&gt;1. The first line tells Visual Basic, "Follow these instructions whenever the user clicks on the command button named cmdStore."&lt;br /&gt;&lt;br /&gt;2. The second line says, "Declare a variable called I and assume the data type is Variant."&lt;br /&gt;&lt;br /&gt;3. The third line says, "Find a list box named 1stTemp and clear out anything the box may be storing."&lt;br /&gt;&lt;br /&gt;4. The fourth line says, "Set the value of I to 0. Continue to count by one until the value of I equals the number of items displayed in the 1stChoose list box."&lt;br /&gt;&lt;br /&gt;5. The fifth line says, "If the user selected an item displayed in the 1stChoose list box, follow the instructions in the sixth line."&lt;br /&gt;&lt;br /&gt;6. The sixth line says, "Copy the item selected in the list box named 1stChoose and put the copied item in the list box named 1stTemp."&lt;br /&gt;&lt;br /&gt;7. The seventh line says, "This is the end of all the instructions to follow for now."&lt;br /&gt;&lt;br /&gt;8. The eighth line says, "Add one to the value of I and start back at line five."&lt;br /&gt;&lt;br /&gt;9. The ninth line says, "This is the end of the instructions to follow when the user clicks on the command button named cmdStore."&lt;br /&gt;&lt;br /&gt;These instructions do nothing more than copy all selected items from one list box into a second list box, which is invisible.&lt;br /&gt;&lt;br /&gt;Each item in a list box (and a combo box, for that matter) is identified by an index number. The top item of the list is assigned an index number of 0, the second item from the top is assigned an index number of 1, and so on.&lt;br /&gt;&lt;br /&gt;To get at the items stored in the list box named 1stTemp, you have to use index numbers. The following command retrieves the top item stored in the 1stTemp list box:&lt;br /&gt;&lt;br /&gt;1stTemp.List(0)&lt;br /&gt;&lt;br /&gt;The following command retrieves the second item from the top in the 1stTemp list box:&lt;br /&gt;&lt;br /&gt;1stTemp.List(1)&lt;br /&gt;&lt;br /&gt;Each increase in the index number retrieves the next item further from the top.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 17&lt;br /&gt;&lt;br /&gt;MATH 101: ARITHMETIC, LOGICAL AND COMPARISON OPERATORS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Adding, subtracting, multiplying, and dividing numbers&lt;br /&gt;Using the not, And, Or, and Xor operators&lt;br /&gt;Comparing numbers and strings&lt;br /&gt;Comparing strings and operators&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After a program gets data from the user (either as a number or as a string), the next step is to do something with that data. If your program mimics an overworked clerical worker, the program may just lose the data and blame the loss on something else. But most likely, you want your program to calculate some sort of result with the data the program receives from the user.&lt;br /&gt;&lt;br /&gt;To calculate a result, your program needs to get data from the user interface and then somehow change, modify, mutilate, or spindle that data. Changing anything involves an operation, so the special commands to work with data are called operators.&lt;br /&gt;&lt;br /&gt;Visual Basic provides the following three types of operators:&lt;br /&gt;&lt;br /&gt;Arithmetic&lt;br /&gt;Logical&lt;br /&gt;Comparison&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Arithmetic Operators&lt;br /&gt;&lt;br /&gt;Arithmetic operators essentially turn your $2,000 computer into a $4.95 pocket calculator. These operators let you add, subtract, multiply, and divide numbers or variables that represent numbers. Table 17-1 shows the most common arithmetic operators.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;||&lt;br /&gt;TABLE 17-1&lt;br /&gt;Arithmetic Operators&lt;br /&gt;&lt;br /&gt;Operator - +&lt;br /&gt;What the Operator Does - Adds two numbers&lt;br /&gt;&lt;br /&gt;Operator - -&lt;br /&gt;What the Operator Does - Subtracts two numbers&lt;br /&gt;&lt;br /&gt;Operator - *&lt;br /&gt;What the Operator Does - Multiplies two numbers&lt;br /&gt;&lt;br /&gt;Operator - /&lt;br /&gt;What the Operator Does - Divides two numbers and returns a floating-point (decimal) number, such as 3.14, 16.2, or 392.2398&lt;br /&gt;&lt;br /&gt;Operator - \&lt;br /&gt;What the Operator Does - Divides two numbers and returns an integer, such as 8, 16, 302, or 25&lt;br /&gt;&lt;br /&gt;Operator - Mod (or modulo)&lt;br /&gt;What the Operator Does - Divides two numbers and returns only the remainder&lt;br /&gt;&lt;br /&gt;Operator - ^&lt;br /&gt;What the Operator Does - Raises a number to an exponential power&lt;br /&gt;&lt;br /&gt;Operator - &amp;amp;&lt;br /&gt;What the Operator Does - Adds (concatenates) two strings&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Adding two numbers with the + operator&lt;br /&gt;&lt;br /&gt;To add two numbers, use the addition operator (+), as shown in the following example:&lt;br /&gt;&lt;br /&gt;X = 10&lt;br /&gt;Y = 15.4&lt;br /&gt;Sum = X + Y&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In case these three BASIC commands mystify you, here's how they work:&lt;br /&gt;&lt;br /&gt;1. The first command says, "Create a variable called X and set the value of X to 10."&lt;br /&gt;2. The second command says, "Create a variable called Y and set the value of Y to 15.4."&lt;br /&gt;3. The third command says, "Create a variable called Sum and set the value of Sum equal to the value of X plus the value of Y." In this case, the value of Sum equals 10 + 15.4, or 25.4.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Subtracting two numbers with the - operator&lt;br /&gt;&lt;br /&gt;To subtract two numbers, use the subtraction operator (-), as shown in the following example:&lt;br /&gt;&lt;br /&gt;Income = 2000&lt;br /&gt;Taxes = 2500&lt;br /&gt;Real_Income = Income - Taxes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here's how Visual Basic interprets these three BASIC commands:&lt;br /&gt;&lt;br /&gt;1. The first command says, "Create a variable called Income and set the value of Income to 2000".&lt;br /&gt;2. The second command says, "Create a variable called Taxes and set the value of Taxes to 2500."&lt;br /&gt;3. The third command says, "Create a variable called Real_Income and set the value of Real_Income equal to the value of Income minus the value of Taxes." In this case, the value of Rea1_Income equals 2000 - 2500, or -500.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Negating numbers with the - operator&lt;br /&gt;&lt;br /&gt;The subtraction operator ( - ), used by itself, can turn a positive number into a negative number and vice versa. To negate a number, place the -operator in front of any number or variable, as shown in the following example:&lt;br /&gt;&lt;br /&gt;Amount = 250&lt;br /&gt;Balance = - Amount&lt;br /&gt;&lt;br /&gt;This is how the tiny little brain of Visual Basic interprets these BASIC commands:&lt;br /&gt;&lt;br /&gt;1. The first command says, "Create a variable called Amount and set the value of Amount to 250."&lt;br /&gt;2. The second command says, "Create a variable called Balance and set the value of Balance to the negative value of Amount." In this case, the value of Balance is -250.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Multiplying two numbers with the * operator&lt;br /&gt;&lt;br /&gt;To multiply two numbers, use the multiplication operator (*), as shown in the following example:&lt;br /&gt;&lt;br /&gt;Hours = 25&lt;br /&gt;Wages = 5.75&lt;br /&gt;Salary = Hours * Wages&lt;br /&gt;&lt;br /&gt;To see how Visual Basic understands these three BASIC commands, this is how they work:&lt;br /&gt;&lt;br /&gt;1. The first command says, "Create a variable called Hours and set the value of Hours to 25."&lt;br /&gt;2. The second command says, "Create a variable called Wages and set the value of Wages to 5.75."&lt;br /&gt;3. The third command says, "Create a variable called Salary and set the value of Salary equal to the value of Hours multiplied by the value of Wages." In this case, the value of Salary equals 25 * 5.75, or 143.75.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Dividing two numbers with the /operator&lt;br /&gt;&lt;br /&gt;To divide two numbers and calculate a floating-point (decimal) number, use the forward-slash division operator ( / ), as shown in the following example:&lt;br /&gt;&lt;br /&gt;GamesWon = 104&lt;br /&gt;TotalGames = 162&lt;br /&gt;WinningPercentage = GamesWon / Total Games&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Visual Basic interprets these three BASIC commands as follows:&lt;br /&gt;&lt;br /&gt;1. The first command says, "Create a variable called GamesWon and set the value of GamesWon to 104."&lt;br /&gt;2. The second command says, "Create a variable called TotalGames and set the value of Total Games to 162."&lt;br /&gt;3. The third command says, "Create a variable called WinningPercentage and set the value of WinningPercentage equal to the value of GamesWon divided by the value of TotalGames." In this case, the value of WinningPercentage equals 104 / 162, or 0.6419753.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Dividing two numbers with the \ operator&lt;br /&gt;&lt;br /&gt;To divide two numbers and calculate an integer, use the backslash division operator ( \ ), as shown in the following example:&lt;br /&gt;&lt;br /&gt;CrateCapacity = 72&lt;br /&gt;Bottles_in_Crate = 1900&lt;br /&gt;FullCrates = Bottles_in_Crate \ CrateCapacity&lt;br /&gt;&lt;br /&gt;So how does Visual Basic interpret these three BASIC commands? Glad you asked. Here's how:&lt;br /&gt;&lt;br /&gt;1. The first command says "Create a variable called CrateCapacity and set the value of CrateCapacity to 72."&lt;br /&gt;2. The second command says, "Create a variable called Bottles_in_Crate and set the value of Bottles_in_Crate to 1900."&lt;br /&gt;3. The third command says, "Create a variable called FullCrates and set the value of FullCrates equal to the value of Bottles_in_Crate divided by the value of CrateCapacity." In this case, the value of FullCrates equals 1900 \ 72, or 26.&lt;br /&gt;&lt;br /&gt;Dividing two numbers often calculates a floating-point (decimal) number, so how does Visual Basic handle rounding? Consider the following example:&lt;br /&gt;&lt;br /&gt;Operand1 = 2.5&lt;br /&gt;Operand2 = 1.5&lt;br /&gt;Result = Operand1 \ Operand2&lt;br /&gt;&lt;br /&gt;Before Visual Basic performs a calculation using the \ operator, the operands are rounded to the nearest whole number. (If an operand is halfway between two whole numbers, such as 2.5 or 1.5, then the operand is rounded up.) In this example, 0perand1 is rounded up to 3 and 0perand2 is rounded up to 2; therefore, Result = 3 \ 2, or 1.5. Because the \ operator must return an integer, the value of Result is rounded down to 1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Dividing with the modulo (Mod) operator&lt;br /&gt;&lt;br /&gt;To divide two numbers and calculate the remainder, use the modulo operator ( Mod ), as shown in the following example:&lt;br /&gt;&lt;br /&gt;CrateCapacity = 72&lt;br /&gt;Bottles_in_Crate = 1900&lt;br /&gt;LooseBottles = Bottles-in-Crate Mod CrateCapacity&lt;br /&gt;&lt;br /&gt;For those curiosity seekers, this is how Visual Basic interprets these commands:&lt;br /&gt;&lt;br /&gt;1. The first command says, "Create a variable called CrateCapacity and set the value of CrateCapacity to 72."&lt;br /&gt;2. The second command says, "Create a variable called Bottles_in_Crate and set the value of Bottles_in_Crate to 1900."&lt;br /&gt;3. The third command says, "Create a variable called LooseBottles and set the value of LooseBottles equal to the remainder of the value of Bottles_in_Crate divided by the value of CrateCapacity." In this case, the value of LooseBottles equals 1900 Mod 72, or 28.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Calculating an exponential with the ^ operator&lt;br /&gt;&lt;br /&gt;An exponential is a fancy mathematical term that means to multiply the same number by itself a certain number of times. For example, multiplying the number 2 four times is represented by 2 and small 4, or 2 * 2 * 2 * 2.&lt;br /&gt;&lt;br /&gt;Because you can't type 2 and small 4, and typing 2 * 2 * 2 * 2 is a bit cumbersome, Visual Basic provides the caret operator (^), as shown in the following example:&lt;br /&gt;&lt;br /&gt;2 ^ 4&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Adding (concatenating) two strings with the &amp;amp; operator&lt;br /&gt;&lt;br /&gt;Adding or concatenating two strings means smashing them together. For this operation, use the ampersand operator ( &amp;amp; ), as shown in the following example:&lt;br /&gt;&lt;br /&gt;FirstName = "John "&lt;br /&gt;LastName = "Doe"&lt;br /&gt;FullName = FirstName &amp;amp; LastName&lt;br /&gt;&lt;br /&gt;When concatenating strings, always make room for a space between the two strings. Otherwise Visual Basic just slams the two strings together as one word like "JohnDoe."&lt;br /&gt;&lt;br /&gt;This is how Visual Basic follows these three BASIC commands:&lt;br /&gt;&lt;br /&gt;1. The first command says, "Create a variable called FirstName and set the value of FirstName to " John " (note the space at the end)."&lt;br /&gt;&lt;br /&gt;2. The second command says, "Create a variable called LastName and set the value of LastName to " Do  "."&lt;br /&gt;&lt;br /&gt;3. The third command says, "Create a variable called FullName and set the value of FullName equal to the value of FirstName and the value of LastName smashed together. " In this case, the value of FullName equals "John" &amp;amp; "Doe", or "John Doe".&lt;br /&gt;&lt;br /&gt;Besides concatenating strings using the ampersand character (&amp;amp;), you can also use the plus sign (+). However, you should use the ampersand character instead because the plus sign is also used with numerical addition. Using the ampersand simply makes your code easier to read.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Logical Operators&lt;br /&gt;&lt;br /&gt;Logical operators manipulate True and False values. Visual Basic represents a value of True as -1 and a value of False as 0. Table 17-2 shows the most common logical operators.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;||&lt;br /&gt;Table 17-2&lt;br /&gt;Logical Operators&lt;br /&gt;&lt;br /&gt;Operator - And&lt;br /&gt;How to Use - Variable1 and Variable2&lt;br /&gt;&lt;br /&gt;Operator - Or&lt;br /&gt;How to Use - Variable1 Or Variable2&lt;br /&gt;&lt;br /&gt;Operator - Xor&lt;br /&gt;How to Use - Variable1 Xor Variable2&lt;br /&gt;&lt;br /&gt;Operator - Not&lt;br /&gt;How to Use - Not Variable&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Using the Not operator&lt;br /&gt;&lt;br /&gt;It's a sad commentary on the negative impact that television has on children when their vocabulary degenerates to the monosyllabic utterance, "Not!"&lt;br /&gt;&lt;br /&gt;Of course, the computer world laid claim to Not long before MTV materialized. The Not operator simply changes a True value to False and a False value to True, as in the following example:&lt;br /&gt;&lt;br /&gt;Variable Name - Another_Computer_Book&lt;br /&gt;Value - True&lt;br /&gt;&lt;br /&gt;Variable Name - Not Another_Computer_Book&lt;br /&gt;Value - False&lt;br /&gt;&lt;br /&gt;For clarity, cool programmers like to use parentheses. If you use parentheses in the preceeding example, it would look like this:&lt;br /&gt;&lt;br /&gt;Not(Another_Computer_Book)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Using the And operator&lt;br /&gt;&lt;br /&gt;The And operator compares the True or False values of two variables and calculates a new True or False value. This allows your program to mae decisions, as the following example illustrates:&lt;br /&gt;&lt;br /&gt;KicktheCat = CatPresent And CatMisbehaving&lt;br /&gt;&lt;br /&gt;So when is the variable KicktheCat True or False? This depends on the True or False value of CatPresent and CatMisbehaving.&lt;br /&gt;&lt;br /&gt;KicktheCat        CatPresent        CatMisbehaving&lt;br /&gt;&lt;br /&gt;True            True            True&lt;br /&gt;False            False             False&lt;br /&gt;False            True            False&lt;br /&gt;False            False            True&lt;br /&gt;&lt;br /&gt;The And operator returns a True value only if both CatPresent and CatMisbehaving are True.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Using the Or operator&lt;br /&gt;&lt;br /&gt;Like the And operator, the Or operator compares the True or False values of two variables and calculates a new True or False value. This allows your program to make decisions, as the following example illustrates:&lt;br /&gt;&lt;br /&gt;LoafInside = GameOnTV Or WeatherBad&lt;br /&gt;&lt;br /&gt;So when is the variable LoafInside True or False?  This depends on the True or False values of GameOnTV and WeatherBad.&lt;br /&gt;&lt;br /&gt;LoafInside    GameOnTV    WeatherBad&lt;br /&gt;&lt;br /&gt;True        True        True&lt;br /&gt;True        False        True&lt;br /&gt;False        True        True  &lt;br /&gt;False        False        False&lt;br /&gt;&lt;br /&gt;The Or operator returns a False value only if both GameOnTV and WeatherBad are False.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Using the Xor operator&lt;br /&gt;&lt;br /&gt;As the the And or Or operators, the Xor operator compares the True of False values to two variables and calculates a new True or False value. This allows your program to make decisions, as the following example illustrates:&lt;br /&gt;&lt;br /&gt;TellOffBoss = BossPresent Xor AtWork&lt;br /&gt;&lt;br /&gt;So when is the variable TellOffBoss True or False?  This depends on the True or False value of BossPresent and AtWork.&lt;br /&gt;&lt;br /&gt;TellOffBoss    BossPresent        AtWork&lt;br /&gt;&lt;br /&gt;True        True            False&lt;br /&gt;True        False            True&lt;br /&gt;False        True            True&lt;br /&gt;False        False            False&lt;br /&gt;&lt;br /&gt;The Xor operator returns a False value if both BossPresent and AtWork are True or if both are False.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Comparison Operators&lt;br /&gt;&lt;br /&gt;Comparison operators compare two numbers or strings to see whether the numbers or strings are equal to, not equal to, greater than, or less than one another. Table 17-3 shows the most common arithmetic operators.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;||&lt;br /&gt;Table 17-3&lt;br /&gt;Comparison Operators&lt;br /&gt;&lt;br /&gt;Operator - &lt;&lt;br /&gt;Meaning - Less than&lt;br /&gt;&lt;br /&gt;Operator - &lt;=&lt;br /&gt;Meaning - Less than or equal to&lt;br /&gt;&lt;br /&gt;Operator - &gt;&lt;br /&gt;Meaning - Greater than&lt;br /&gt;&lt;br /&gt;Operator - &gt;=&lt;br /&gt;Meaning - Greater than or equal to&lt;br /&gt;&lt;br /&gt;Operator - =&lt;br /&gt;Meaning - Equal to&lt;br /&gt;&lt;br /&gt;Operator - &lt; &gt;&lt;br /&gt;Meaning - Not equal to&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Comparing numbers and strings&lt;br /&gt;&lt;br /&gt;As the following example illustrates, comparison operators compare the values of numbers and strings in order to return a value of True or False:&lt;br /&gt;&lt;br /&gt;Age = 18&lt;br /&gt;MinimumAge 21&lt;br /&gt;Pass = (Age &gt;= MinimumAge)&lt;br /&gt;&lt;br /&gt;This is how Visual Basic interprets these three BASIC commands:&lt;br /&gt;&lt;br /&gt;1. The first command says, "Create a variable called Age and set the value of Age to 18."&lt;br /&gt;2. The second command says, "Create a variable called MinimumAge and set the value of MinimumAge to 2l."&lt;br /&gt;3. The third command says, "Compare the value of Age and see whether the value is greater than or equal to the value of MinimumAge. If the value of Age is greater than or equal to the value of MinimumAge, create a variable called Pass and set the value of Pass to True. If the value of Age is not greater than or equal to the value of MinimumAge, create a variable called Pass and set the value of Pass to False."&lt;br /&gt;&lt;br /&gt;Comparing numbers is fairly easy, but comparing strings is a bit trickier. When comparing strings, Visual Basic calculates the ANSI character code value of each letter.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* ANSI character codes&lt;br /&gt;&lt;br /&gt;At the simplest level, computers understand only two numbers: zero and one. You can represent all numbers with zeros and ones, such numbers are called binary numbers.&lt;br /&gt;&lt;br /&gt;Since computers only understand numbers, not letters, humans created a simple system where certain numbers represent certain letters, punctuation marks, and characters. So the number 97 represents the letter a, the number 65 represents the letter A, and the number 33 represents an exclamation mark (!).&lt;br /&gt;&lt;br /&gt;To make sure that all computers use the same numbers to represent the same letters and punctuation marks, the American National Standards Institute (ANSI) defined an ANSI Character Set that specifies which number represents which letter or punctuation mark.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Comparing strings with the = and &lt;&gt; operators&lt;br /&gt;&lt;br /&gt;Two strings are equal only if they are absolutely identical. As you can see in the following example, the equal to operator ( = ) always calculates a False value unless the operator compares two identical strings, such as " a " = " a ":&lt;br /&gt;&lt;br /&gt;Operation - " a" = " a "&lt;br /&gt;Value of Operation - True&lt;br /&gt;&lt;br /&gt;Operation - " a " = " A "&lt;br /&gt;Value of Operation - False&lt;br /&gt;&lt;br /&gt;Operation - " a " = " aa "&lt;br /&gt;Value of Operation - False&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the next example, however, you see that the not equal to operator ( &lt;&gt;) always calculates a True value unless this operator compares two identical strings, such as " Abott " &lt;&gt; " Abott ":&lt;br /&gt;&lt;br /&gt;Operation -  " A " &lt;&gt; " a "&lt;br /&gt;Value of Operation - True&lt;br /&gt;&lt;br /&gt;Operation - "Abott" &lt;&gt; "Abott"&lt;br /&gt;Value of Operation - False&lt;br /&gt;&lt;br /&gt;Visual Basic always treats uppercase and lowercase letters as completely different entitles when comparing strings.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Comparing strings with the &gt;, &gt;=, &lt;, and &lt;= operators&lt;br /&gt;&lt;br /&gt;When comparing strings, Visual Basic calculates the ANSI character code for each letter in each string, beginning with the first letter. The string whose character has the higher ANSI character code is considered greater.&lt;br /&gt;&lt;br /&gt;For example, the letter A has an ANSI character code of 65 and the letter a has an ANSI character code of 97. So consider the following line:&lt;br /&gt;&lt;br /&gt;Flag = ("Air" &lt; "aardvark")&lt;br /&gt;&lt;br /&gt;Because the first letter in " Air " has a lower character code number than the first letter in "aardvark", Visual Basic considers the value of "Air" to be less than "aardvark", so the value of Flag is going to be True.&lt;br /&gt;&lt;br /&gt;Now consider the following example:&lt;br /&gt;&lt;br /&gt;Flag = ("air" &lt; "aardvark")&lt;br /&gt;&lt;br /&gt;Here the value of Flag is False. How does Visual Basic decide whether "air" is less than "aardvark"? First, Visual Basic calculates the ANSI character code for the first letter of each string. Because both begin with a, Visual Basic looks at the second letter. Because i has a higher ANSI character code than a, "air " is considered greater than "aardvark" and Flag is therefore False.&lt;br /&gt;&lt;br /&gt;Consider one final example:&lt;br /&gt;&lt;br /&gt;Flag = ("air" &lt; "airplane")&lt;br /&gt;&lt;br /&gt;In this example, the value of Flag is True. The first three letters of each string are identical, but the fourth letter is not. Because "air" doesn't have a fourth letter and "airplane" does, "airplane" is considered greater and Flag is therefore True.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. What is the difference between the / operator and the \ operator?&lt;br /&gt;&lt;br /&gt;a. One is called a forward slash and one is called a backslash. Other than that, they both look like typos.&lt;br /&gt;b. The / operator divides two numbers and the \ operator puts them back together again.&lt;br /&gt;c. The / operator calculates a floating-point (decimal) number, such as 3.54, and the \ operator calculates an integer, such as 5 or 34.&lt;br /&gt;d. The / operator doesn't work at all, so you have to use the \ operator instead.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Is the following statement True or False?&lt;br /&gt;&lt;br /&gt;"aeroplane" &lt; "airplane"&lt;br /&gt;&lt;br /&gt;a. False, because I don't know what to think; besides, the answer hasn't been the letter (a) for a long time.&lt;br /&gt;b. True, because the second letter in aeroplane is less than the second letter in airplane.&lt;br /&gt;c.. True and False, because I'm hedging my bets.&lt;br /&gt;d. False, because an aeroplane is an oldfashioned way of saying airplane, so both strings are exactly the same.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;**Precedence&lt;br /&gt;&lt;br /&gt;With all these operators crowding your BASIC commands, what happens if you lump them all together on one line, like this:&lt;br /&gt;&lt;br /&gt;Mess = 4 / 7 + 9 * 2&lt;br /&gt;&lt;br /&gt;If you guessed that the value of Mess is 18.57143, congratulations! But how does Visual Basic handle this? First, Visual Basic calculates those operators that have higher priority, or precedence.&lt;br /&gt;&lt;br /&gt;Not all operators are equal. Some have a higher precedence than others, which means that they demand attention first, just like crying babies. Table 17-4 lists the order in which Visual Basic pays attention to the various operators. The higher an operator appears in Table 17-4, the higher that operator's precedence, so the exponential operator (^) has higher precedence than the less than operator ( &lt; ).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;||&lt;br /&gt;Table 17-4&lt;br /&gt;Precedence of Operators&lt;br /&gt;&lt;br /&gt;Operator - Exponential ( ^ )&lt;br /&gt;Type of Operator - Arithmetic&lt;br /&gt;&lt;br /&gt;Operator - Negation ( - )&lt;br /&gt;Type of Operator - Arithmetic&lt;br /&gt;&lt;br /&gt;Operator - Multiplication and Division ( * and / )&lt;br /&gt;Type of Operator - Arithmetic&lt;br /&gt;&lt;br /&gt;Operator - Integer division ( \ )&lt;br /&gt;Type of Operator - Arithmetic&lt;br /&gt;&lt;br /&gt;Operator - Modulo ( mod )&lt;br /&gt;Type of Operator - Arithmetic&lt;br /&gt;&lt;br /&gt;Operator - Addition and Subtraction ( + and - )&lt;br /&gt;Type of Operator - Arithmetic&lt;br /&gt;&lt;br /&gt;Operator - String concatenation ( &amp;amp; )&lt;br /&gt;Type of Operator - Arithmetic&lt;br /&gt;&lt;br /&gt;Operator - Equality ( = )&lt;br /&gt;Type of Operator - Comparison&lt;br /&gt;&lt;br /&gt;Operator - Inequality ( &lt;&gt; )&lt;br /&gt;Type of Operator - Comparison&lt;br /&gt;&lt;br /&gt;Operator - Less than ( &lt; )&lt;br /&gt;Type of Operator - Comparison&lt;br /&gt;&lt;br /&gt;Operator - Greater than ( &gt; )&lt;br /&gt;Type of Operator - Comparison&lt;br /&gt;&lt;br /&gt;Operator - Less than or equal to ( &lt;= )&lt;br /&gt;Type of Operator - Comparison&lt;br /&gt;&lt;br /&gt;Operator - Greater than or equal to ( &gt;= )&lt;br /&gt;Type of Operator - Comparison&lt;br /&gt;&lt;br /&gt;Operator - Like&lt;br /&gt;Type of Operator - Comparison&lt;br /&gt;&lt;br /&gt;Operator - Is&lt;br /&gt;Type of Operator - Comparison&lt;br /&gt;&lt;br /&gt;Operator - Not&lt;br /&gt;Type of Operator - Logical&lt;br /&gt;&lt;br /&gt;Operator - And&lt;br /&gt;Type of Operator - Logical&lt;br /&gt;&lt;br /&gt;Operator - Or&lt;br /&gt;Type of Operator - Logical&lt;br /&gt;&lt;br /&gt;Operator - Xor&lt;br /&gt;Type of Operator - Logical&lt;br /&gt;&lt;br /&gt;Operator - Eqv&lt;br /&gt;Type of Operator - Logical&lt;br /&gt;&lt;br /&gt;Operator - Imp&lt;br /&gt;Type of Operator - Logical&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;How does Visual Basic calculate the value of Mess in the following equation?&lt;br /&gt;&lt;br /&gt;Mess = 4 / 7 + 9 * 2&lt;br /&gt;&lt;br /&gt;To help you understand how Visual Basic calculates a result, these are the steps Visual Basic follows:&lt;br /&gt;&lt;br /&gt;1. Multiplication and division have a higher precedence than addition, so Visual Basic looks at the multiplication and division operators first.&lt;br /&gt;&lt;br /&gt;2. Because multiplication and division have the same precedence, Visual Basic starts with the one furthest to the left. So Visual Basic calculates the value of 4 / 7 and comes up with 0.57143. Now the equation has been simplified to:&lt;br /&gt;&lt;br /&gt;Mess = 0.57143 + 9 * 2&lt;br /&gt;&lt;br /&gt;3. Visual Basic sees that the multiplication operator has a higher precedence than the addition operator, so Visual Basic calculates the value of 9 * 2 and comes up with 18. The equation is now:&lt;br /&gt;&lt;br /&gt;Mess = 0.57143 + 18&lt;br /&gt;&lt;br /&gt;The final value of Mess is 18.57143.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What if you really wanted Visual Basic to add the two numbers first before doing any division or multiplication? For clarity, and to make sure that calculations come out the way you intend, enclose particular operations in your equations in parentheses,&lt;br /&gt;as shown in the following example:&lt;br /&gt;&lt;br /&gt;Mess = 4 / (7 + 9) *  2&lt;br /&gt;&lt;br /&gt;This is how Visual Basic calculates the result:&lt;br /&gt;&lt;br /&gt;1. The parentheses tell Visual Basic to add 7 + 9 first, which creates the following equation:&lt;br /&gt;&lt;br /&gt;Mess = 4 / 16 * 2&lt;br /&gt;&lt;br /&gt;2. Because the division and multiplication operators have the same precedence, Visual Basic begins with the leftmost operator. Visual Basic calculates 4 / 16, and comes up with 0.25. The equation is now:&lt;br /&gt;&lt;br /&gt;Mess = 0.25 * 2&lt;br /&gt;&lt;br /&gt;3. Finally, Visual Basic multiplies these numbers and assigns the value of 0.5 to the variable Mess.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Whenever you use two or more operators, use parentheses to provide clarity and to ensure that Visual Basic calculates everything in the exact order you want.&lt;br /&gt;&lt;br /&gt;To help you better understand precedence, the enclosed CD-ROM provides a program that shows you how precedence works when using parentheses and when omitting parentheses while calculating a numeric result.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 18&lt;br /&gt;&lt;br /&gt;STRINGS AND THINGS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Converting the case of strings&lt;br /&gt;Using parts of strings to search for and replace other strings&lt;br /&gt;Converting strings into numbers and numbers into strings&lt;br /&gt;Converting strings into ASCII values&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In addition to manipulating numbers, your program can manipulate strings as well. Strings are any combination of letters, numbers, or symbols that you want the program to treat literally.&lt;br /&gt;&lt;br /&gt;For example, computers blindly interpret phone numbers and social security numbers as mathematical expressions. A typical computer interprets the phone number 123-4567 as the expression, "Subtract 4567 from the number 123."&lt;br /&gt;&lt;br /&gt;To tell your program to treat strings literally, always surround your strings with quotation marks, "like this". So if you want to assign the string 123-4567 to a variable, you use quotation marks, as in the following example:&lt;br /&gt;&lt;br /&gt;Private Sub Count( )&lt;br /&gt;  Phone = "123-4567"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;If you forget to add the quotation marks, Visual Basic stupidly tries to interpret the string of numbers as an actual command. In this case, Visual Basic would try to subtract 4567 from 123.&lt;br /&gt;&lt;br /&gt;After you designate particular data as a string, Visual Basic provides all sorts of weird ways to examine, manipulate, and mutilate the string.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Manipulating Strings&lt;br /&gt;&lt;br /&gt;You are not limited to using strings exactly as they originally appear. You can modify them in many ways. You can convert the case of a string, use parts of a string to look for and replace other strings, and shorten a string by removing extra spaces.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Counting the length of a string&lt;br /&gt;&lt;br /&gt;A string is only as long as the number of characters (including spaces) that the string contains. To count the length of a string, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;VariableName = Len("String")&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;Dim Name As String&lt;br /&gt;Dim NameLength As Integer&lt;br /&gt;  Name = "Bo the cat"&lt;br /&gt;  NameLength = Len(Name)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;In this case, the length of the string "Bo the cat" is 10 (eight letters and two spaces), so this value is assigned to the variable called Name Length.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Converting from uppercase to lowercase&lt;br /&gt;&lt;br /&gt;To convert a string to all lowercase letters, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;Lcase ("String")&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;Dim Name As String, LowerCase As String&lt;br /&gt;  Name = "DOESN'T THIS LOOK OBNOXIOUS?"&lt;br /&gt;  LowerCase = LCase(Name)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this case, the value of Lower Case is the following string:&lt;br /&gt;&lt;br /&gt;doesn't this look obnoxious?&lt;br /&gt;&lt;br /&gt;Notice that the LCase command affects only letters. (How do you present a lowercase question mark, anyway?)&lt;br /&gt;&lt;br /&gt;To convert a string to all uppercase letters, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;Ucase("String")&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;Dim Name As String, UpperCase As String&lt;br /&gt;  Name = "whisper when you speak"&lt;br /&gt;  UpperCase = UCase(Name)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;In this case, the value of UpperCase is the following string:&lt;br /&gt;&lt;br /&gt;WHISPER WHEN YOU SPEAK&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Reversing strings&lt;br /&gt;&lt;br /&gt;The newest string manipulation command in Visual Basic reverses strings, which can be useful for playing with palindromes (phrases that appear the same written forward as they do backward). To reverse a string, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;StrReverse("String")&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;Dim Phrase As String&lt;br /&gt;  Phrase = "Madam, I'm Adam"&lt;br /&gt;  Phrase = StrReverse(Phrase)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;In this case, the value of Phrase is the following string:&lt;br /&gt;&lt;br /&gt;madA m'I ,madaM&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Extracting characters from a string&lt;br /&gt;&lt;br /&gt;Sometimes a string contains more information than you want. For example, you may have stored a person's full name in a variable called FullName, as in the following:&lt;br /&gt;&lt;br /&gt;FullName = "John Doe"&lt;br /&gt;&lt;br /&gt;To extract characters starting from the left of the string, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;Left(FullName, N)&lt;br /&gt;&lt;br /&gt;The preceding command says, "See that string over there called FullName? Yank out N number of characters, starting from the left." For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_CIick( )&lt;br /&gt;  Dim FulIName As String, First As String&lt;br /&gt;  FulIName = "John Doe"&lt;br /&gt;  First = Left(FullName, 4)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;In the preceding example, the value of First is John.&lt;br /&gt;&lt;br /&gt;To extract characters starting from the right of the string, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;Right(FullName, N)&lt;br /&gt;&lt;br /&gt;This command says, "See that string over there called FullName? Yank out N number of characters, starting from the right."&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;  Dim FulIName As String, Last As String&lt;br /&gt;  FulIName = "John Doe"&lt;br /&gt;  Last = Right(FulIName, 3)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;In this example, the value of Last is Doe.&lt;br /&gt;&lt;br /&gt;Another command for extracting characters from a string is the Mid command, such as:&lt;br /&gt;&lt;br /&gt;Mid(FulIName, X, Y)&lt;br /&gt;&lt;br /&gt;This command says, "See that string over there called FullName? Count X number of characters from the left, and rip out the next Y number of characters. For example,&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;Dim FulIName As String, Middle As String&lt;br /&gt;  FulIName = "John Q. Doe"&lt;br /&gt;  Middle = Mid(FulIName, 6, 2)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;In this example, the value of Middle is Q. (including the period).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Finding part of a string with another string&lt;br /&gt;&lt;br /&gt;If one string is buried in the middle of another string, you can find the location of the burial string by using the following BASIC command:&lt;br /&gt;&lt;br /&gt;InStr("TargetString", "WantedString")&lt;br /&gt;&lt;br /&gt;This command returns a number defining the exact location from the left where the "WantedString" begins inside the "Target String". For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;  Dim FulIName As String&lt;br /&gt;  Dim Location As Integer&lt;br /&gt;  FulIName = "John Plain Doe"&lt;br /&gt;  Location = InStr(FulIName, "Plain")&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;In this case, the value of Location is 6.&lt;br /&gt;&lt;br /&gt;If the string you want isn't located inside the string you're searching for, the InStr command returns 0.&lt;br /&gt;&lt;br /&gt;When you search for a string within another string, you have to search for the exact uppercase or lowercase string. For example, the following command returns a value of 0:&lt;br /&gt;&lt;br /&gt;InStr("John Plain Doe", "PLAIN")&lt;br /&gt;&lt;br /&gt;In this case, "Plain" is not the same string as "PLAIN", so InStr returns 0. Essentially, a zero is the Visual Basic way of saying, "Sorry, I can't find your exact string anywhere."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Replacing part of a string with another string&lt;br /&gt;&lt;br /&gt;In case you get the creative urge to write your own word processor in Visual Basic (complete with search and replace features), you can do so with the following BASIC command:&lt;br /&gt;&lt;br /&gt;Mid("TargetString", Position) = "NewString"&lt;br /&gt;&lt;br /&gt;This command says, "See that string called Target String? Find the value defined by Position, count that number of characters from the left, and insert the string called NewString."&lt;br /&gt;&lt;br /&gt;Of course, you have to be careful when inserting a new string into an existing one. For example, consider the following code:&lt;br /&gt;&lt;br /&gt;FullName = "John Plain Doe"&lt;br /&gt;Mid(FulIName, 6) = "Vanilla"&lt;br /&gt;&lt;br /&gt;Here's how Visual Basic interprets this code:&lt;br /&gt;&lt;br /&gt;First, Visual Basic assigns the string "John Plain Doe" to the variable called FullName.&lt;br /&gt;&lt;br /&gt;Next, Visual Basic looks at the string "John Plain Doe", finds the sixth character from the left, and inserts the string "Vanilla" replacing the original string beginning with the sixth character. So the following is what happens:&lt;br /&gt;&lt;br /&gt;John Plain Doe       (Original string)&lt;br /&gt;     ^            (Sixth character from the left)&lt;br /&gt;John Vanillaoe          (New string)&lt;br /&gt;&lt;br /&gt;After you tell Visual Basic to replace part of a string with another one, Visual Basic gets overzealous and wipes out anything that gets in the way of the new string.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Trimming spaces from strings&lt;br /&gt;&lt;br /&gt;Strings aren't always nice and neat. Sometimes spaces lie in front of or behind the string, as the following examples illustrate:&lt;br /&gt;&lt;br /&gt;"         This is an example of leading spaces"&lt;br /&gt;"This is an example of trailing spaces        "&lt;br /&gt;&lt;br /&gt;To strip away leading spaces, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;LTrim("TargetString")&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;  Dim FullName As String&lt;br /&gt;  FullName = "          John Doe"&lt;br /&gt;  FullName = LTrim(FullName)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The value of FullName is "John Doe" with the leading spaces removed.&lt;br /&gt;&lt;br /&gt;To strip away trailing spaces, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;RTrim("TargetString")&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;  Dim FullName As String&lt;br /&gt;  FullName = "John        "&lt;br /&gt;  FullName = RTrim(FullName)&lt;br /&gt;  FullName = FullName &amp;amp; " " &amp;amp; "Doe"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;In the preceding example, the RTrim command removes the trailing spaces so the value of FullName is just plain "John". Then the last command adds the value of FullName("John") to a blank space and the string "Doe" to create the string "John Doe".&lt;br /&gt;&lt;br /&gt;In case you have both leading and trailing spaces, you can combine the two commands like this:&lt;br /&gt;&lt;br /&gt;LTrim(RTrim("TargetString"))&lt;br /&gt;&lt;br /&gt;This command says, "First, remove all trailing spaces and then remove all leading spaces." For an even simpler method, use the following BASIC command instead:&lt;br /&gt;&lt;br /&gt;Trim("TargetString")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;  Dim FulIName As String&lt;br /&gt;  FulIName = "        John Dull        "&lt;br /&gt;  FulIName = Trim(Ful]Name)&lt;br /&gt;  FulIName = FulIName &amp;amp; " " &amp;amp; "Doe"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The Trim command removes both the leading and trailing spaces in one quick stroke, then the last command adds the string "John Dull" to a blank string (" ") and the string "Doe" to create "John Dull Doe".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Converting Strings and Values&lt;br /&gt;&lt;br /&gt;Visual Basic handles numbers and strings differently. There may come a time, however, when you need to convert a string into a number so that you can use the string for calculations. Or you may need to convert a number into a string so that you can manipulate the string. You also may need to convert a string into the equivalent ASCII or ANSI value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Converting a string into a number&lt;br /&gt;&lt;br /&gt;What if you have a text box in which users can type their hourly wages? Unfortunately, the Text property of any text box stores data as a string, not as a number. To convert this string into a number, you have to use one of the following BASIC commands:&lt;br /&gt;&lt;br /&gt;CDbl("TargetString")&lt;br /&gt;&lt;br /&gt;CSng("TargetString")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first command says, "Take the string called Target String and convert TargetString to a Double data type."&lt;br /&gt;&lt;br /&gt;The second command says, "Take the string called TargetString and convert TargetString to a Single data type.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Private Sub Form_Click( )&lt;br /&gt;  Dim GetNumber As Double&lt;br /&gt;  GetNumber = CDbl(txtHourlyWage.Text)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The following is how Visual Basic interprets this code:&lt;br /&gt;&lt;br /&gt;1. The first statement says, "Declare a variable called GetNumber as a Double data type."&lt;br /&gt;&lt;br /&gt;2. The second statement says, "Get the string stored in the Text property of a text box called txtHourlyWage and convert the string to a number that's a Double data type."&lt;br /&gt;&lt;br /&gt;3. Finally, the value stored in the txtHourlyWage. Text property is assigned to the GetNumber variable.&lt;br /&gt;&lt;br /&gt;If the user types 6.25 in the txtHourlyWage text box, the value of GetNumber is 6.25.&lt;br /&gt;&lt;br /&gt;If the user types 6.25 Hourly wage or My hourly wage is 6.25 in the txtHourlyWage text box, Visual Basic chokes and screams about a type mismatch error because neither CDbl nor CSng knows how to handle characters.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Converting a number into a string&lt;br /&gt;&lt;br /&gt;What if you have a number and need to convert it into a string so that you can do fancy string manipulations to the number? Then you have to use the following BASIC command:&lt;br /&gt;CStr(Number)&lt;br /&gt;&lt;br /&gt;This command says, "Take the number represented by Number and turn this number into a string."&lt;br /&gt;&lt;br /&gt;For example, Visual Basic considers these to be two completely different creatures:&lt;br /&gt;&lt;br /&gt;10          '  This is a number&lt;br /&gt;"10"        '  This is a string&lt;br /&gt;&lt;br /&gt;The following converts a number into a string:&lt;br /&gt;&lt;br /&gt;CStr(10)        '  The string " 10"&lt;br /&gt;CStr(10.5)     '  The string " 10.5"&lt;br /&gt;CStr( - 10)     '  The string "-10"&lt;br /&gt;&lt;br /&gt;When Visual Basic converts a number into a string, the string has an extra leading space if the string is a positive number or a minus sign (-) if the string is a negative number.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Converting a string into an equivalent ASCII value&lt;br /&gt;&lt;br /&gt;As a programmer, you have to practically memorize the ASCII table at some point, so you may as well find a copy of one and hang it near your computer somewhere so that you can find this table easily.&lt;br /&gt;&lt;br /&gt;An ASCII table shows the codes that computers use to represent most of the characters you need. For example, the letter A has an ASCII value of 65, and the letter a has an ASCII value of 97.&lt;br /&gt;&lt;br /&gt;Whenever you need the ASCII value of a one-character string, you can use this BASIC command:&lt;br /&gt;&lt;br /&gt;Asc("Character")&lt;br /&gt;&lt;br /&gt;The following shows how to convert a character into its ASCII value:&lt;br /&gt;&lt;br /&gt;X = Asc ("A")      '  X = 65&lt;br /&gt;X = Asc ("a")      '  X = 97&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Converting an ANSI value into a string&lt;br /&gt;&lt;br /&gt;Microsoft Windows doesn't use the ASCII table. Instead, Windows uses the ANSI table, which is practically the same as the ASCII table anyway. (You can read about the ANSI table in Chapter 17)&lt;br /&gt;&lt;br /&gt;To use an ANSI value, use the following BASIC command:&lt;br /&gt;&lt;br /&gt;Chr("Character")&lt;br /&gt;&lt;br /&gt;The only time you need to use the ANSI value of anything is for special control codes, such as for line feeds, carriage returns, and new lines.&lt;br /&gt;&lt;br /&gt;The following commands shows common ANSI values:&lt;br /&gt;&lt;br /&gt;LineFeed = Chr(I0)&lt;br /&gt;FormFeed = Chr(12)&lt;br /&gt;Carriage = Chr (13)&lt;br /&gt;&lt;br /&gt;By using all these fancy string-manipulation commands, you can make sure that your strings look exactly the way you want them to before displaying them in a text box or label. Either that, or you can just have fun playing with words and numbers and pretend you're doing serious research on your job.&lt;br /&gt;&lt;br /&gt;To show you how Visual Basic can manipulate strings, examine the ELIZA.VBP program on the enclosed CD-ROM. This program is similar to the famous ELIZA artificial intelligence program that mimics a psychiatrist who simply echoes back portions of what the user types in.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 19&lt;br /&gt;&lt;br /&gt;DEFINING CONSTANTS AND USING COMMENTS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Naming and calculating constants&lt;br /&gt;Declaring the scope of constants&lt;br /&gt;Creating and using the three types of comments&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A constant is a fixed value that never changes, no matter what happens to your program. Numbers, strings, and dates can be constant values.&lt;br /&gt;&lt;br /&gt;But why bother using constants? Several good reasons exist, none of which make any sense until you start writing your own programs.&lt;br /&gt;&lt;br /&gt;For example, suppose that you want to write a program that pays employees according to the current minimum wage. If the minimum wage is $5.95, you have to type the number 5.95 everywhere in your program.&lt;br /&gt;&lt;br /&gt;Unfortunately, the number 5.95 means nothing in itself. Even worse, if the minimum wage changes from $5.95 to $6.25, you have to change 5.95 to 6.25 everywhere in your program.&lt;br /&gt;&lt;br /&gt;To overcome these problems, you can use constants. A constant is simply a word that represents a specific value. A constant not only uses plain English to describe what the value means, but a constant also lets you change values quickly and easily throughout an entire program.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Naming Constants&lt;br /&gt;&lt;br /&gt;Constant names must meet the following criteria. They must:&lt;br /&gt;&lt;br /&gt;Begin with a letter&lt;br /&gt;Be 40 characters or fewer&lt;br /&gt;Contain only letters, numbers, and the underscore character (_); punctuation marks and spaces are not allowed&lt;br /&gt;Be any word except a Visual Basic reserved keyword&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To make constant names stand out, use all uppercase letters. For example, the following are acceptable constant names:&lt;br /&gt;&lt;br /&gt;AGE&lt;br /&gt;MY_BIRTHDAY&lt;br /&gt;MINIMUM_WAGE&lt;br /&gt;LIFEBOAT CAPACITY&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To provide additional information about the type of data a constant represents, use a three-letter prefix as part of the constant name such as:&lt;br /&gt;&lt;br /&gt;intAGE       (int represents an Integer data value)&lt;br /&gt;curMINIMUM_WAGE         (cur represents a Currency data value)&lt;br /&gt;sngGPA        (sng represents a Single data value)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Table 19-1 provides Microsoft's list of suggested three-letter prefixes for naming constants (or variables, for that matter).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;||&lt;br /&gt;Table 19-1&lt;br /&gt;Three-Letter Prefixes for Naming Constants and Variables&lt;br /&gt;&lt;br /&gt;Data Type - Boolean&lt;br /&gt;Prefix -  bln&lt;br /&gt;Example - blnIsItDeadYet&lt;br /&gt;&lt;br /&gt;Data Type - Byte&lt;br /&gt;Prefix -  byt&lt;br /&gt;Example - bytThisNumber&lt;br /&gt;&lt;br /&gt;Data Type - Currency&lt;br /&gt;Prefix -  cur&lt;br /&gt;Example - curCEOBonus&lt;br /&gt;&lt;br /&gt;Data Type - Data (Time)&lt;br /&gt;Prefix -  dtm&lt;br /&gt;Example - dtmAnniversary&lt;br /&gt;&lt;br /&gt;Data Type - Double&lt;br /&gt;Prefix -  dbl&lt;br /&gt;Example - dblHeight&lt;br /&gt;&lt;br /&gt;Data Type - Integer&lt;br /&gt;Prefix -  int&lt;br /&gt;Example - intTotalNumber&lt;br /&gt;&lt;br /&gt;Data Type - Long&lt;br /&gt;Prefix -  lng&lt;br /&gt;Example - lngWidth&lt;br /&gt;&lt;br /&gt;Data Type - Single&lt;br /&gt;Prefix -  sng&lt;br /&gt;Example - sngAverage&lt;br /&gt;&lt;br /&gt;Data Type - String&lt;br /&gt;Prefix -  str&lt;br /&gt;Example - strMyName&lt;br /&gt;&lt;br /&gt;Data Type - Variant&lt;br /&gt;Prefix -  vnt&lt;br /&gt;Example - vntWhatEver&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Declaring Constants&lt;br /&gt;&lt;br /&gt;Before you can use a constant, you have to declare the constant. To declare a constant, you just give the constant a name and assign it a specific value, such as any of the following:&lt;br /&gt;&lt;br /&gt;Numbers&lt;br /&gt;Strings&lt;br /&gt;Dates&lt;br /&gt;&lt;br /&gt;The following code declares number, string, and date constants:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  Const intAGE = 21&lt;br /&gt;  Const strCOMPANY = "Acme Manufacturing"&lt;br /&gt;  Const dtmCHRISTMAS = #25 December 1995#&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Place all constant declarations at the top of your event procedures. Instead of typing one constant declaration on each line, you can smash them all together and separate them with commas, as illustrated in the following code:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  Const intAGE = 21, strCOMPANY = "Acme Manufacturing"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Note that number constants are only numbers, string constants are anything enclosed in quotation marks and date constants are dates surrounded by the pound sign (#).&lt;br /&gt;&lt;br /&gt;Here are some of the ways in which dates can display:&lt;br /&gt;&lt;br /&gt;#12-25-95#&lt;br /&gt;#December 25, 1995#&lt;br /&gt;#Dec-25-95#&lt;br /&gt;#25 December 1995#&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Calculating constants&lt;br /&gt;&lt;br /&gt;Constants normally represent a fixed value. However, constants can also be mathematic values based on other constants. For example:&lt;br /&gt;&lt;br /&gt;Const intRETIREMENT_AGE = 65&lt;br /&gt;Const sngHALFWAY-THERE = intRETIREMENT_AGE / 2&lt;br /&gt;&lt;br /&gt;In this case, the value of the constant intRETIREMENT_AGE is 65 and the value of the constant sngHALFWAY_THERE is 65/2, or 32.5.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Using constants&lt;br /&gt;&lt;br /&gt;After you declare a constant, you can use the constant just like any other value. Consider the following:&lt;br /&gt;&lt;br /&gt;Const curMINIMUM_WAGE = 5.75&lt;br /&gt;Salary = curMINIMUM_WAGE * 20&lt;br /&gt;&lt;br /&gt;Here's how Visual Basic interprets this code:&lt;br /&gt;&lt;br /&gt;1. The first command says, "Create a constant named curMINIMUM_WAGE and set the value of curMINIMUM_WAGE to 5.75."&lt;br /&gt;&lt;br /&gt;2. The second command says, "Multiply the value of curMINIMUM_WAGE by 20 and store this value in the variable called Salary." In this case, the value of curMINIMUM_WAGE is 5.75, so you multiply 5.75 by 20, which equals 115. Then Visual Basic stores this value in Salary.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Scope of Constants&lt;br /&gt;&lt;br /&gt;Visual Basic lets you declare the scope of constants in the following three ways:&lt;br /&gt;&lt;br /&gt;Local&lt;br /&gt;Module&lt;br /&gt;Public&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Local constants&lt;br /&gt;&lt;br /&gt;You can use a local constant only within the procedure in which you declare the constant. The purpose of local constants is to isolate specific constants in a single procedure where they are used.&lt;br /&gt;&lt;br /&gt;Declare a local constant within an event procedure, as in the following:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  Const intSPEED_LIMIT = 55&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;You can use a local constant only in the one event procedure in which you declare the constant. However, what if you want to create a constant that two or more event procedures can share? In that case, you have to create a module constant.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Module constants&lt;br /&gt;&lt;br /&gt;A module constant can be used only in an event procedure stored in the same file.&lt;br /&gt;&lt;br /&gt;To declare a module constant, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Open the Code window by pressing F7, choosing View-&gt;Code, or double-clicking anywhere on the form.&lt;br /&gt;2. Click the Object list box in the Code window and choose (General).&lt;br /&gt;3. Click the Procedure list box and choose (Declarations).&lt;br /&gt;4. Now type your constant declaration using the Const statement, as in the following:&lt;br /&gt;&lt;br /&gt;Const intDRINKING_AGE = 21&lt;br /&gt;&lt;br /&gt;Module constants are useful for sharing a constant value among one or more event procedures, but isolating the constant to only those event procedures stored in the same file. If you want a constant that any procedure in your program can use, you need to create a public constant.&lt;br /&gt;&lt;br /&gt;To help you identify module constants buried in your code, Microsoft recommends that you put the letter m in front of your constant name such as:&lt;br /&gt;&lt;br /&gt;Const mintDRINKING_AGE = 21&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Public constants&lt;br /&gt;&lt;br /&gt;A public constant (also called a global constant) can be the most convenient to use because every procedure in your Visual Basic program can access such a constant. However, cool programmers use public constants only when absolutely necessary; cluttering up your program with public constants that only a few procedures ever use is bad programming practice.&lt;br /&gt;&lt;br /&gt;Using public constants is poor programming etiquette because changing a public constant can affect your entire program. Experienced programmers may blush in embarrassment for you if they catch you using public constants needlessly, and you may never get invited to any of the really great programmer parties as a result.&lt;br /&gt;&lt;br /&gt;You need to declare public constants in a BAS (module) file. To declare a public constant, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Open the Project window.&lt;br /&gt;&lt;br /&gt;To do this, press Ctrl+R and click on the BAS (module) file where you want to put the public constant. (If you need to create a BAS file, click the Module icon or choose Module from the Insert menu.)&lt;br /&gt;&lt;br /&gt;2. Open the Code window by pressing F7, choosing View-&gt;Code, or double-clicking anywhere on the form.&lt;br /&gt;3. Click on the Object list box in the Code window and choose (General).&lt;br /&gt;4. Click on the Procedure list box and choose (Declarations).&lt;br /&gt;5. Type your public constant using the Public command, as in the following:&lt;br /&gt;&lt;br /&gt;Public Const  AGE_LIMIT = 18&lt;br /&gt;&lt;br /&gt;To help you identify public (or global) constants buried in your code, Microsoft recommends that you put the letter g in front of your constant name such as:&lt;br /&gt;&lt;br /&gt;Const gsngHEIGHT_LIMIT = 21.67&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want to see a list of all the global constants that Visual Basic has already defined for you, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Choose Help-&gt;lndex.  A dialog box appears.&lt;br /&gt;2. Click the Index tab.&lt;br /&gt;3. Type Constants in the Type in the keyword to find text box.&lt;br /&gt;4. Under the Constants category, click on Visual Basic.&lt;br /&gt;5. Click Display.  Visual Basic displays the Visual Basic Constants window.&lt;br /&gt;6. Click on the constant category that you want to view, such as Button Constants.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Using Comments&lt;br /&gt;&lt;br /&gt;When you're coding your program (note the proper use of the word coding), the way your program works may be clear to you. Unfortunately, if you put your program aside and try to modify it five years later, you may have forgotten why you wrote certain commands and even how some of those commands work.&lt;br /&gt;&lt;br /&gt;For just this reason, add plenty of comments to your programs. Comments are short descriptions that programmers add to their program to explain what certain commands mean or to explain what is supposed to happen in a particular part of the program.&lt;br /&gt;&lt;br /&gt;As far as the computer is concerned, comments do absolutely nothing to help or hinder the way your program works. However, from a programmer's point of view, comments help explain how and why a program functions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Creating comments&lt;br /&gt;&lt;br /&gt;Visual Basic lets you create comments by using the apostrophe ( ' ) symbol, followed by anything you care to type. The following, for example, is a valid comment:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  '  This event procedure does absolutely nothing&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;As far as Visual Basic is concerned, the computer ignores anything that appears to the right of the apostrophe symbol.&lt;br /&gt;&lt;br /&gt;Comments can appear on separate lines or they can appear as part of another line, as in the following example:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  X = Y * 2    ' Y represents the number of employees&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;You can also cram several comments together on multiple lines:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  Y = 200      ' Y represents the number of employees&lt;br /&gt;  X = Y * 2&lt;br /&gt;  ' X represents the number of employees who would like&lt;br /&gt;  ' to slash the tires on the boss's car.&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Just remember that the computer ignores anything that appears to the right of the apostrophe symbol and considers it a comment.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Commenting for readability&lt;br /&gt;&lt;br /&gt;The main reason for using comments is to make your programs easy to understand. For this reason, most cool programmers put comments at the beginning of every procedure.&lt;br /&gt;&lt;br /&gt;These comments explain what data the procedure gets (if any) and what calculations the procedure performs. By just looking at the comments, anyone can quickly see what the procedure does without needing to decipher several lines of cryptic BASIC code. For example, can you figure out what the following event procedure does?&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  A = SQR(B ^ 2 + C ^ 2)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;To make the procedure's function easier to understand, add a bunch of comments at the top of this procedure:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  ' The following equation uses the Pythagorean theorem&lt;br /&gt;  ' for calculating the length of a side of a right&lt;br /&gt;   ' triangle if the lengths of two sides are known. In&lt;br /&gt;   ' this case, the length of one side of the triangle is&lt;br /&gt;   ' represented by B and the length of the second side of&lt;br /&gt;   ' the triangle is represented by C.&lt;br /&gt;  A = SQR(B ^ 2 + C " 2)&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If several people share the responsibilities for writing procedures, you can use comments to note the name of the programmer and the date each procedure was last modified. (That way, you know who to blame when the procedure doesn't work.) For example:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  ' Programmer: JOHN DOE&lt;br /&gt;  ' Last modified: 1/1/80 (our computer clock doesn't work)&lt;br /&gt;  A = SQR((B ^ 2 + C ^ 2))&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Of course, if you get too wordy, your comments can be more intrusive than helpful - like billboards along the highway. Just remember: Provide enough information to be helpful, but not so much that people nod off to sleep while reading your comments. You're not writing a classic novel here, just a brief description that other people can understand.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. Why do you want to add comments to your program?&lt;br /&gt;&lt;br /&gt;a. To summarize and explain how your BASIC code works.&lt;br /&gt;b. To exercise your literary skills and prove that programmers can write, too.&lt;br /&gt;c. To prove that you have something to say besides BASIC commands.&lt;br /&gt;d. So that you can leave cryptic messages for other programmers to decipher&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Comment on the simplicity and brevity of this lesson.&lt;br /&gt;&lt;br /&gt;a. All right! Now I can quit and go home early.&lt;br /&gt;b. Why can't all the lessons in this book be this simple and short?&lt;br /&gt;c. I still can't write a program, but I know how to use comments. Maybe I need to get a job as a commentator.&lt;br /&gt;d. Comments are cool. If we can write comments in our programs, does that mean we can write programs with our word&lt;br /&gt;   processors?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Comments for legibility&lt;br /&gt;&lt;br /&gt;If your program contains lots of BASIC code, you can use comments and blank lines to make your code easy to read. For example, to make each chunk more easily seen, separate chunks of code:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  Const dblINTEREST_RATE = .055   ' 5.5% interest rate&lt;br /&gt;&lt;br /&gt;  Dim Msg As String           ' Declares Msg as a string   ' variable&lt;br /&gt;  BankBalance = 500&lt;br /&gt;  BankBalance = BankBalance * dblINTEREST_RATE&lt;br /&gt;&lt;br /&gt;  ' Subtract bank fees&lt;br /&gt;  BankFees = BankBalance * 2&lt;br /&gt;  BankBalance = BankBalance - BankFees&lt;br /&gt;&lt;br /&gt;  ' Display a message box saying that the user owes the&lt;br /&gt;  ' bank a certain amount of money.&lt;br /&gt;  Msg = "Please pay this amount: " &amp;amp; - BankBalance&lt;br /&gt;  MsgBox Msg,  vbCritical, "Amount You Owe"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As the preceeding example shows, you can insert hard returns to add blank lines between chunks of code, thereby enabling yourself to see more easily what each chunk actually does.&lt;br /&gt;&lt;br /&gt;Stripping out all comments and blank lines gives you the following equivalent, but uglier, version:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;  Const INTEREST_RATE = .055&lt;br /&gt;  Dim Msg As String&lt;br /&gt;  BankBalance = 500&lt;br /&gt;  BankBalance = BankBalance * INTEREST_RATE&lt;br /&gt;  BankFees = BankBalance * 2&lt;br /&gt;  BankBalance = BankBalance - BankFees&lt;br /&gt;  Msg = "Please pay this amount:  "  &amp;amp; -BankBalance&lt;br /&gt;  MsgBox Msg, vbCritical,  "Amount You Owe"&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Notice how this new version seems cramped and cluttered, much like your bathroom counter or your garage.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Comments for disability&lt;br /&gt;&lt;br /&gt;With comments, you can not only add explanations about your program and visually break up your code but also temporarily disable one or more BASIC commands.&lt;br /&gt;&lt;br /&gt;For example, as you're writing a program, you may find that a command isn't working as you want it to. To test how your program works without this command, you have two choices:&lt;br /&gt;&lt;br /&gt;Erase the command.&lt;br /&gt;Comment the command out.&lt;br /&gt;&lt;br /&gt;If you erase a command and then decide you need it, you have to type the command all over again. If you comment the command out, however, you only have to erase the apostrophe symbol in order to put the command back in.&lt;br /&gt;&lt;br /&gt;The following example contains a fairly long line of numbers:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;   X = 3.14 * 650 - (909 / 34.56) + 89.323&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;If you erase the second line, typing the line again can be a real pain in the neck. However, you can just comment the line out, as follows:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;   ' X = 3.14 * 650 - (909 / 34.56) + 89.323&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Remember, the computer ignores anything that appears to the right of the apostrophe symbol. So, to the computer, this procedure now looks like the following:&lt;br /&gt;&lt;br /&gt;Private Sub Command1_Click( )&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Placing the apostrophe in front of this statement turns the statement into a comment and disables this new comment as a BASIC command. By removing the apostrophe symbol, you can quickly turn the comment back into a real-life BASIC command.&lt;br /&gt;&lt;br /&gt;By using comments wisely, you can ensure that you or another programmer can easily understand any programs you write. Then again, if you really want to sabotage a programming project, add comments that don't make any sense or leave them out altogether and see what happens.&lt;br /&gt;&lt;br /&gt;If you want to comment multiple lines of code quickly, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Highlight the lines of code you want to turn into a comment.&lt;br /&gt;2. Choose View-&gt;Toolbars-&gt;Edit.&lt;br /&gt;3. Click on the Comment Block icon.  Visual Basic adds an apostrophe to the front of each line that you highlighted in Step 1.&lt;br /&gt;&lt;br /&gt;To uncomment blocks of code, just repeat the above three steps except click on the Uncomment Block icon on the Editor toolbar in Step 3.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 20&lt;br /&gt;&lt;br /&gt;KILLING BUGS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter:&lt;br /&gt;&lt;br /&gt;Examining the various types of bugs&lt;br /&gt;Embarking on the big bug hunt&lt;br /&gt;Killing the bugs you find&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Even if you've written millions of different programs before, you are still going to make a mistake at one time or another. You may misspell a word or forget to type a command. So no matter how carefully you write your program, the program may not work exactly as you design it to. The problems hindering your program from working are bugs.&lt;br /&gt;&lt;br /&gt;Every program in the world has bugs, including Netscape Navigator, WordPerfect, Lotus 1-2-3, Quicken, and Microsoft Windows 98. The only difference between the bugs in your program and the bugs in a commercial program is that nobody is paying you to eliminate bugs in your program. However, with a fair amount of planning, application design, and just plain common sense, you can avoid quite a few bugs.&lt;br /&gt;&lt;br /&gt;Don't worry. Many bugs are relatively harmless. These minor bugs normally aren't going to prevent you from using a program correctly, but they may slow down your computer or display odd colors or objects on the screen at random times.&lt;br /&gt;&lt;br /&gt;Major bugs are more devastating. For example, a major bug allegedly blew up one of NASA's multimillion-dollar weather satellites because someone mistyped a single command in the program.&lt;br /&gt;&lt;br /&gt;Nobody is perfect, so no program can be guaranteed to be completely bug-free. Even an experienced professional with a doctorate in computer science regularly writes bug-ridden programs.&lt;br /&gt;&lt;br /&gt;Bugs are a fact of life, like cockroaches in a kitchen. You may never get rid of them all, but you can kill as many as possible along the way.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Why computer problems are called bugs&lt;br /&gt;&lt;br /&gt;The first computer in the world used mechanical relays instead of modern electronics. One day the computer stopped working for no apparent reason. The scientists checked their programming (the program was supposed to have worked), the electric cord (it was plugged in), and the wires inside the computer (they were still connected).&lt;br /&gt;&lt;br /&gt;Eventually, someone noticed that a moth had gotten smashed in one of the relays, preventing the relay from closing all the way. Because the moth's dead body prevented the computer from working, problems with computers were henceforth known as bugs (which is a lot easier to say than Chihuahuas, so we should be glad that a dog didn't get smashed in the first computer).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Types of Bugs&lt;br /&gt;&lt;br /&gt;The art of killing bugs is known as debugging. Before you can kill a bug, you first have to find the bug. With small programs, such as ones that display Hello, world! on the screen, you have only so many places a bug can hide. With large programs, a bug can be hiding anywhere, and this can be as frustrating as trying to find a single tsetse fly in a high-rise apartment building.&lt;br /&gt;&lt;br /&gt;To make hunting for bugs easier, computer scientists classify bugs in three categories:&lt;br /&gt;&lt;br /&gt;Syntax errors&lt;br /&gt;Run-time errors&lt;br /&gt;Logic errors&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Syntax errors&lt;br /&gt;&lt;br /&gt;A syntax error is a bug that occurs when you misspell a command. If you type INTTEGER instead of INTEGER, for example, Visual Basic is going to have no idea what INTTEGER means and isn't going to even bother trying to run the rest of your program.&lt;br /&gt;&lt;br /&gt;When Visual Basic runs across a syntax error, Visual Basic politely high-lights the misspelled word on the screen to show you exactly what the problem is. Just type the correct spelling and run your program again.&lt;br /&gt;&lt;br /&gt;Even one syntax error is going to keep your program from running. When you finally get your program to run for the first time, you know that your program is completely free of syntax errors. Then you have to worry only about run-time and logic errors.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Run-time errors&lt;br /&gt;&lt;br /&gt;A run-time error occurs when your program gets data that the program doesn't quite know how to handle. A run-time error is more subtle than a syntax error. Your program may be riddled with run-time errors, but you may never know this until you actually run your program.&lt;br /&gt;&lt;br /&gt;To simulate a run-time error in your own life, pull into the drive-through window at your nearest Burger King. When the cashier asks, "May I help you?" order a Big Mac. Because the cashier expects you to order something from Burger King's menu, this person has no idea how to respond to your question and is likely to suffer a run-time error.&lt;br /&gt;&lt;br /&gt;For an example of a run-time error in a program, consider this formula for calculating a result:&lt;br /&gt;&lt;br /&gt;TaxRate = TaxesOwed / YearlyIncome&lt;br /&gt;&lt;br /&gt;This equation normally works - unless the YearIy Income equals 0. Because dividing any number by 0 is impossible, the program stops running if the value in YearlyIncome is 0.&lt;br /&gt;&lt;br /&gt;To discover a run-time error, you must test your program for every possible occurrence: from someone pressing the wrong key to some idiot typing a negative number for his or her age.&lt;br /&gt;&lt;br /&gt;Because the number of things that can ever go wrong is nearly infinite (Murphy's Law), you can understand why every large program in the world has bugs. (Now isn't this a comforting thought to remember the next time you fly in a computer-controlled airplane?)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Logic errors&lt;br /&gt;&lt;br /&gt;The trickiest type of bug is a logic error. A logic error occurs when the program doesn't work correctly because you gave the program the wrong commands or the commands you issued are out of sequence with other commands. Huh? How can you give a program the wrong commands when you're the one writing the program? Believe it or not, entering the wrong commands is easy.&lt;br /&gt;&lt;br /&gt;Anyone raising teenagers knows that when you tell them to mow the lawn or clean up their rooms, they may do the task - but not quite the way you wanted the task accomplished. Instead of mowing the lawn in neat rows, a teenager may move around in circles and give up. Or instead of cleaning a room by picking up dirty clothes and tossing out papers, a teenager may shove the whole mess under the bed or out into the hallway.&lt;br /&gt;&lt;br /&gt;In both cases, the teenager followed your instructions, but your instructions weren't specific enough. If a teenager can find a loophole in your instructions, he or she will, and a computer is no different.&lt;br /&gt;&lt;br /&gt;Because you thought you gave the computer the right commands to follow, you have no idea why your program isn't working. Now you have to find the one spot where your instructions aren't clear enough. If you have a large program, this may mean searching the entire program, line-by-line. (Isn't programming fun?)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Bug Hunting&lt;br /&gt;&lt;br /&gt;Basically, you need to go through four steps to hunt down and kill bugs in your program:&lt;br /&gt;&lt;br /&gt;1. Realize that your program has a bug.&lt;br /&gt;2. Find the bug.&lt;br /&gt;3. Find what's causing the bug.&lt;br /&gt;4. Squash the bug.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Realizing that your program has a bug&lt;br /&gt;&lt;br /&gt;The best way to discover bugs in your program is to let unsuspecting individuals use your program. (In the world of commercial software, these unsuspecting individuals are often called paying customers.)&lt;br /&gt;&lt;br /&gt;The more people you find to test your program, the more likely that these guinea pigs are going to uncover bugs you never knew existed. Bugs can be as glaring as ones that cause the computer to crash, or they can be as sneaky as ones that round off numbers to the wrong decimal place.&lt;br /&gt;&lt;br /&gt;After you conclude that your program has a bug, you have to track the bug down. (For the optimists in the group, you can call your program's bugs undocumented features.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Finding the bug&lt;br /&gt;&lt;br /&gt;Finding where a bug is hiding is the toughest part. The simplest (and most tedious) way to find a bug's hiding place is to run your program and examine it line-by-line. The moment the bug appears, you know exactly which line caused the bug.&lt;br /&gt;&lt;br /&gt;For small programs, this approach is acceptable. For large programs, this is crazy.&lt;br /&gt;&lt;br /&gt;As a faster alternative, just examine the parts of your program in which you think the bug may be hiding. If your program doesn't print correctly, for example, the bug may be in your BASIC code that tells the computer how to print.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Finding what's causing the bug&lt;br /&gt;&lt;br /&gt;After you isolate where you think the bug is hiding, you have to figure out what is causing the bug in the first place.&lt;br /&gt;&lt;br /&gt;Suppose that your program is to print your name on the screen but is printing your social security number instead. The program may seem to be printing everything correctly but is simply getting the wrong type of information to print.&lt;br /&gt;&lt;br /&gt;By using your incredible powers of deductive reasoning, you realize that the bug is (probably) wherever your program first tries to print your name.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Squashing the bug&lt;br /&gt;&lt;br /&gt;After you find the cause of your bug, you've reached the time to correct your program. But be careful! Sometimes correcting one bug introduces two or three more by mistake. Huh? How can that be?&lt;br /&gt;&lt;br /&gt;Compare bug squashing to repairing a problem with the plumbing in your house. The easiest solution may be to tear out a wall and put in new pipes. This may solve the plumbing problem, but tearing out a wall can also tear out electrical wires inside the wall. So now you've fixed your plumbing problems but also created a new electrical problem. If you put up a new wall with electrical wiring, you may inadvertently block a vent for the central air-conditioning. Move the wall back 3 feet, and now the roof may be too weak in the middle to hold up the wall. See - your small plumbing "bug" has just multiplied.&lt;br /&gt;&lt;br /&gt;So when fixing a bug, be careful. Sometimes rewriting a huge chunk of code is easier than trying to fix a bug within the code.&lt;br /&gt;&lt;br /&gt;The best way to avoid bugs is to not have any in the first place. Of course, that's like saying to avoid money problems, just make sure you always have enough money.&lt;br /&gt;&lt;br /&gt;Because bugs appear in even the best of programs, the most you can hope for is to reduce the number of bugs that can pop up in your programs. Here are some tips that may help:&lt;br /&gt;&lt;br /&gt;To avoid bugs, write (and test) lots of tiny programs and paste them together to make one huge program. The smaller your programs, the easier isolating any bugs is going to be. In military terms, this is known as the divide and conquer method.&lt;br /&gt;&lt;br /&gt;Test your program each time you modify it. If your program worked fine until you changed three lines, the problem probably can be isolated to those three lines.&lt;br /&gt;&lt;br /&gt;Have someone you can pin the blame on. If your program refuses to work, blame your spouse, your dog, or your favorite deity. This isn't going to help fix your program, but blaming someone or something else can make you feel better for a moment or two.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** How Visual Basic Tracks and Kills Bugs&lt;br /&gt;&lt;br /&gt;Visual Basic provides two primary ways to help you track and kill bugs:&lt;br /&gt;   stepping and watching.&lt;br /&gt;&lt;br /&gt;Stepping means that you go through your program line-by-line and examine each instruction. After each line runs, look to see what the program did. If your program works the way you wanted it to, the line is okay. If not, you just located a bug.&lt;br /&gt;&lt;br /&gt;Watching lets you see what data your program is using at any given time. If you watch for specific data, such as a name or phone number, you can see whether your program is storing, printing, or modifying the specific data correctly.&lt;br /&gt;&lt;br /&gt;By stepping through a program line-by-line and watching to see what data your program is using, you can find any bugs in your program.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Stepping through a program line-by-line&lt;br /&gt;&lt;br /&gt;If you have absolutely no idea where your bug may be, you need to examine your entire program line-by-line. To step through a program, Visual Basic provides three commands:&lt;br /&gt;&lt;br /&gt;Debug-&gt;Step Into (or press F8)&lt;br /&gt;Debug-&gt;Step Over (or press Shift+F8)&lt;br /&gt;Debug-&gt;Step Out (or press Ctrl+Shift+F8)&lt;br /&gt;&lt;br /&gt;The Step Into command runs through your entire program one line at a time, including every line stored in every procedure in your program.&lt;br /&gt;&lt;br /&gt;The Step Over command runs through your entire program but whenever Visual Basic runs into a procedure, Visual Basic skips over the instructions that make up that procedure.&lt;br /&gt;&lt;br /&gt;The Step Out command is used with the Step Into command. The Step Into command shows you, line-by-line, how a procedure is working. However, if you suddenly decide that you don't want to examine how a procedure is working, line-by-line, use the Step Out command.&lt;br /&gt;&lt;br /&gt;You can combine the three commands at any time. First, use the Step Into command to examine your program line-by-line. Next, use the Step Out command to get out of any procedures that the Step Into command starts displaying. Finally, use the Step Over command to skip over any procedures that you're positive already work.&lt;br /&gt;&lt;br /&gt;To use the Step Into or Step Over commands, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Press F8 or Shift+F8, or choose Debug-&gt;Step Into or Step Over.&lt;br /&gt;   Visual Basic displays and outlines a line in your program.&lt;br /&gt;2. Choose Run-&gt;End when you want to stop.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Watching your variables&lt;br /&gt;&lt;br /&gt;Stepping through your program line-by-line can be even more useful if you watch how your program handles data at the same time. To help you see what values your variables contain at any given time, Visual Basic provides a Watch window.&lt;br /&gt;&lt;br /&gt;The Watch window tells Visual Basic, "These are the variables I want to examine. Show me the contents of these variables as I step through my program line-by-line."&lt;br /&gt;&lt;br /&gt;To use the Watch window to watch your variables, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Open the Code window by pressing F7, choosing View-&gt;Code, or clicking on the View Code icon in the Project Explorer window.&lt;br /&gt;2. Highlight the variable that you want to watch and choose Debug-&gt;Add Watch.  An Add Watch dialog box appears.&lt;br /&gt;3. Click on OK.&lt;br /&gt;4. Press F8 or Shift+F8 to choose the Step Into (if you want to examine the guts of a procedure) or Step Over (if you want to skip over the code trapped inside a procedure) commands. The Watch window displays the value of your watched variable each time you choose the Step Into or Step Over command.&lt;br /&gt;5. Choose Run-&gt;End or click on the End icon In the toolbar when you want to stop.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Setting breakpoints&lt;br /&gt;&lt;br /&gt;Both the Step Into and Step Over commands start from the beginning of your program and continue until they reach the end. This is acceptable for small programs, but the process can get tedious for large programs.&lt;br /&gt;&lt;br /&gt;To skip over large sections of your program that you know (or hope) already work, you can set a breakpoint. A breakpoint tells Visual Basic, "Run the program up until you reach me. Then wait until I give you the Step Into, Step Over, or Run command."&lt;br /&gt;&lt;br /&gt;To set a breakpoint, follow these steps:&lt;br /&gt;&lt;br /&gt;1. Open the Code window by pressing F7, choosing View-&gt;Code, or clicking on the View Code icon in the Project Explorer window.&lt;br /&gt;2. Click on the line where you want to set your breakpoint&lt;br /&gt;3. Press F9 (or choose Debug-&gt;Toggle Breakpoint).&lt;br /&gt;&lt;br /&gt;After you set a breakpoint, press F5 to run your program until it reaches your breakpoint. At this point, you can use the Step Into or Step Over commands along with the Add Watch command.&lt;br /&gt;&lt;br /&gt;To remove a breakpoint, just follow the above three steps again, clicking on the line that contains the breakpoint you want to remove.&lt;br /&gt;&lt;br /&gt;To quickly remove all breakpoints in your program, press Ctrl+Shift+F9 or choose Debug-&gt;Clear All Breakpoints.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ PART V&lt;br /&gt;&lt;br /&gt;MAKING DECISIONS (SOMETHING YOU STOP DOING WHEN YOU GET MARRIED)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this part....&lt;br /&gt;&lt;br /&gt;Programs contain nothing more complicated than instructions that tell the computer what to do next. The simplest programs just contain one massive list of instructions that the computer follows, one instruction after another, like a shopping list.&lt;br /&gt;&lt;br /&gt;But blindly following instructions doesn't make for a very useful program. Most programs need to receive data and then decide how to use the data.&lt;br /&gt;&lt;br /&gt;This decision-making capability can make your computer seem alive, responsive, and intelligent. (Well, alive, anyway.) When a program can tell your computer how to make its own decisions, your computer can begin doing something useful.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 21&lt;br /&gt;&lt;br /&gt;THE IF-THEN AND IF-THEN-ELSE STATEMENTS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter.....&lt;br /&gt;&lt;br /&gt;Specifying a condition&lt;br /&gt;Using If-Then and If-Then-End If statements&lt;br /&gt;Using If-Then-Else and If-Then-ElseIf statements&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Everyone has made decisions based on certain conditions, such as, "Don't worry, honey. If the ball game is over early, then I am going to mow the lawn." Or "If you stop feeding the cat, then maybe it won't keep getting fatter." Visual Basic is no different when making decisions is at hand. When you write a program, Visual Basic can check for certain conditions and then respond.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Conditions&lt;br /&gt;&lt;br /&gt;A condition must represent a value that is either True or False. Conditions can be:&lt;br /&gt;&lt;br /&gt;A single variable&lt;br /&gt;An expression&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If a condition is a single variable, that variable must have a value that is either True or False. You can check the value of a variable in two ways. The first way is to specifically check if a variable is equal to True, as in the following example:&lt;br /&gt;&lt;br /&gt;If TooHot = True Then&lt;br /&gt;&lt;br /&gt;The second way (which is shorter to write) lets you eliminate = True and just write the following:&lt;br /&gt;&lt;br /&gt;If TooHot Then&lt;br /&gt;&lt;br /&gt;You don't have to specify whether this variable is equal to True because Visual Basic checks whether the value is True or False anyway.&lt;br /&gt;&lt;br /&gt;If you want to specifically test whether a variable is False, you can do the following:&lt;br /&gt;&lt;br /&gt;If TooCold = False Then&lt;br /&gt;&lt;br /&gt;As ashortcut, eliminate = False and just write&lt;br /&gt;&lt;br /&gt;If Not TooCold Then&lt;br /&gt;&lt;br /&gt;If a condition is an expression, that entire expression must represent a value that is either True or False, such as:&lt;br /&gt;&lt;br /&gt;If Age &gt;+ 21 Then&lt;br /&gt;&lt;br /&gt;In the above example, the condition is Age &gt;= 21.&lt;br /&gt;&lt;br /&gt;For this condition, if the value of Age is greater than or equal to 21, the expression is True. Otherwise, the expression is False.&lt;br /&gt;&lt;br /&gt;In the following example, if the string stored in the Text property of a text box called txtName contains the string "Captain Mike", the expression is True. Otherwise, the expression is False.&lt;br /&gt;&lt;br /&gt;If (txtName.Text = "Captain Mike") Then&lt;br /&gt;&lt;br /&gt;The parentheses in the preceding line of code don't affect your precious code one bit; they just help make the condition easier to identify.&lt;br /&gt;&lt;br /&gt;In the following example, the expression Cat Present And CatMisbehaving evaluates to False:&lt;br /&gt;&lt;br /&gt;CatPresent = False&lt;br /&gt;CatMisbehaving = True&lt;br /&gt;If CatPresent And CatMisbehaving Then&lt;br /&gt;&lt;br /&gt;To make the condition in an If-Then statement easier to see, you can also surround the condition with optional parentheses, as in the following line of code:&lt;br /&gt;&lt;br /&gt;If (CatPresent And CatMisbehaving) Then&lt;br /&gt;&lt;br /&gt;Now that you understand what and how conditions work, you can find out how to plug them into an If-Then statement in the following section, "The If-Then Statement."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** The If-Then Statement&lt;br /&gt;&lt;br /&gt;To make decisions, Visual Basic uses something called an If-Then statement. An If-Then statement is the way Visual Basic checks whether a condition is True or False.&lt;br /&gt;&lt;br /&gt;If the condition is True, Visual Basic follows a certain instruction. If the condition is False, Visual Basic ignores this instruction.&lt;br /&gt;&lt;br /&gt;All of this may look rather wordy, so here's the condensed version of the statement:&lt;br /&gt;&lt;br /&gt;If Condition Then Instruction&lt;br /&gt;&lt;br /&gt;Essentially, this code tells Visual Basic that if a certain condition is True, Visual Basic needs to obey the instruction that follows.&lt;br /&gt;&lt;br /&gt;Whatever the condition may be, the condition must always return a True or False value.&lt;br /&gt;&lt;br /&gt;Here are a few real-life examples:&lt;br /&gt;&lt;br /&gt;If Number &gt; 25 Then txtNote.Text = "Full"&lt;br /&gt;&lt;br /&gt;Here's how Visual Basic interprets this code:&lt;br /&gt;&lt;br /&gt;1. This command says, "Check a variable called Number and see whether the value is greater than 25. If the value is greater than 25, then stuff the string "Full" into the Text property of a text box called txtNote."&lt;br /&gt;&lt;br /&gt;2. "If the value of the Number variable is equal to or less than 25, then skip to the next instruction in your Visual Basic program."&lt;br /&gt;&lt;br /&gt;If Hungry Or Bored Then Message = "Let's eat."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here's how Visual Basic interprets this code:&lt;br /&gt;&lt;br /&gt;1. This command says, "Check the value of a variable called Hungry and check the value of a variable called Bored. If either one has a value of True, then create a variable called Message and set the value equal to the string " Let ' s eat."&lt;br /&gt;&lt;br /&gt;2. "If both the variable Hungry and the variable Bored are False, skip to the next instruction in your Visual Basic program."&lt;br /&gt;&lt;br /&gt;The typical If-Then statement tests whether a certain condition is True or False and then follows a single instruction. But what happens if you want to test for a condition and then make the computer follow two or more instructions? In that case, you have to use a different form of the If-Then statement that is called the If-Then-End If statement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** The If-Then-End If Statement&lt;br /&gt;&lt;br /&gt;The If-Then-End If statement lets Visual Basic check a single condition. If the condition is True, the program follows a bunch of instructions. Here's the proper If-Then-End If syntax:&lt;br /&gt;&lt;br /&gt;If Condition Then&lt;br /&gt;  Instruction1&lt;br /&gt;  Instruction2&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Essentially, this code tells Visual Basic, "Check a condition; if the condition is True, then obey all the following instructions until you reach End If."&lt;br /&gt;&lt;br /&gt;Here is an honest-to-goodness example:&lt;br /&gt;&lt;br /&gt;If Electricity_is_Out = True Then&lt;br /&gt;  Light-candles = True&lt;br /&gt;  TxtWarning.Text = "You just lost all your work."&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;And here's how Visual Basic interprets this code:&lt;br /&gt;&lt;br /&gt;1. The first line says, "Check the value for a variable called Electricity_is_Out. If the variable's value is True, then follow the&lt;br /&gt;   next two instructions. If the value is False, then do nothing."&lt;br /&gt;2. "Assign a value of True to the variable Light_candles."&lt;br /&gt;3. "Assign the string "You just lost all your work."  to the Text property of the txtWarning text box."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** If-Then-Else Statement&lt;br /&gt;&lt;br /&gt;The If-Then statement gives your program the capability to make decisions based on certain conditions. If this isn't the pinnacle of your computer programming career, hold on to your hats for the If-Then-Else statement.&lt;br /&gt;&lt;br /&gt;The problem with using an If-Then statement or an If-Then-End If statement is that you may need too many of them to check for both True and False conditions. Is there an easier way? The answer, of course, is yes! Visual Basic offers something called an If-Then-Else statement.&lt;br /&gt;&lt;br /&gt;The simplest If-Then-Else statement looks like this:&lt;br /&gt;&lt;br /&gt;If Condition Then&lt;br /&gt;   Instructions1&lt;br /&gt;Else&lt;br /&gt;   Instructions2&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;This statement tells Visual Basic, "If the condition is True, then follow the first batch of instructions. If the condition is False, then follow the second batch of instructions."&lt;br /&gt;&lt;br /&gt;So how can you modify the following?&lt;br /&gt;&lt;br /&gt;If Day &gt; 15 Then txtReadMe.Text = "Bills are past due!"&lt;br /&gt;If Day &lt;= 15 Then txtReadMe.Text = "Pay your bills!"&lt;br /&gt;&lt;br /&gt;Depending on the condition you use, you can rewrite these statements in two ways. If you use the condition Day &gt; 15, you get the following:&lt;br /&gt;&lt;br /&gt;If Day &gt; 15 Then&lt;br /&gt;  txtReadMe.Text = "Bills are past due!"&lt;br /&gt;Else&lt;br /&gt;  txtReadMe.Text = "Pay your bills!"&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;But if you use the condition Day &lt;= 15, you get the following:&lt;br /&gt;&lt;br /&gt;If Day &lt;= 15 Then&lt;br /&gt;  txtReadMe.Text = "Pay your bills!"&lt;br /&gt;Else&lt;br /&gt;  txtReadMe.Text = "Bills are past due!"&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Both types of If-Then-Else statements are perfectly acceptable. Which statement you choose to use is just a matter of personal preference.&lt;br /&gt;&lt;br /&gt;You can shove as many instructions as you want between the If-Then and Else lines and the Else and End If lines.&lt;br /&gt;&lt;br /&gt;One possible drawback with an If-Then-Else statement is that if the first condition is False, Visual Basic blindly follows the second group of instructions. If you don't want this to happen, you have to specify a condition for the second set of instructions. To do that, you have to use an If-Then-ElseIf statement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** The If-Then-ElseIf Statement&lt;br /&gt;&lt;br /&gt;An If-Then-ElseIf statement looks like the following:&lt;br /&gt;&lt;br /&gt;If Condition1 Then&lt;br /&gt;  Instructions1&lt;br /&gt;ElseIf Condition2 Then&lt;br /&gt;  Instructions2&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;This code tells Visual Basic, "If Condition1 is True, then follow the first set of instructions. But if Condition1 is False, then check to see if Condition2 is True. If Condition2 is True, then follow the second set of instructions. If Condition2 is False, then don't do anything at all."&lt;br /&gt;&lt;br /&gt;With an If-Then-Else statement, the computer always follows at least one set of instructions. But with an If-Then-ElseIf statement, the computer could possible ignore all instructions - much like a rebellious teenager.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;If Day &gt; 15 Then&lt;br /&gt;   txtReadMe.Text - "Bills are past due!"&lt;br /&gt;ElseIf Day &gt; 10 Then&lt;br /&gt;   txtReadMe.Text = "Pay your bills!"&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;So what happens if the value of Day is 12?&lt;br /&gt;&lt;br /&gt;1. Visual Basic checks the first condition and concludes that the expression 12 &gt; 15 is False (because the value of Day is 12).&lt;br /&gt;2. Then Visual Basic checks the second condition and concludes that the expression 12 &gt; 10 is True, so Visual Basic assigns the string, "Pay your bills!" to the Text property of a text box called txtReadMe.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here's the tricky part. What happens if the value of Day is 6?&lt;br /&gt;&lt;br /&gt;1. Visual Basic checks the first condition and concludes that the statement 6 &gt; 15 is False, so Visual Basic ignores the first set of instructions.&lt;br /&gt;&lt;br /&gt;2. Next, Visual Basic checks the second condition and concludes that the statement 6 &gt; 10 is False, so Visual Basic ignores the second set of instructions.&lt;br /&gt;&lt;br /&gt;3. Finally, Visual Basic reaches the end of the If-Then-ElseIf statement. Because none of the statements were True, none of the instructions were followed.&lt;br /&gt;&lt;br /&gt;To handle multiple possibilities, you need to add more ElseIf conditions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Making multiple choices with If-Then-ElseIf&lt;br /&gt;&lt;br /&gt;For checking multiple conditions, use multiple ElseIfs, as follows:&lt;br /&gt;&lt;br /&gt;If Condition1 Then&lt;br /&gt;   Instructions1&lt;br /&gt;ElseIf Condition2 Then&lt;br /&gt;   Instructions2&lt;br /&gt;ElseIf Condition3 Then&lt;br /&gt;   Instructions3&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;This code tells Visual Basic, "If Condition1 is True, then follow Instructions1. But if Condition1 is False, check whether Condition2 is True. If Condition2 is True, then follow Instructions2. If Condition1 is False and Condition2 is False, then check to see whether Condition3 is True. If Condition3 is True, then follow Instructions3."&lt;br /&gt;&lt;br /&gt;Once again, the possibility exists that all condi tions are going to be False, so the computer may never follow any of the instructions.&lt;br /&gt;&lt;br /&gt;You can use as many ElseIf lines as you need. Of course, the more you use, the more confusing your entire If-Then-ElseIf statement gets. ("Now if Condition3 is False but Condition4 is True, wait a minute, what's supposed to happen?")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Making sure that the computer follows at least one set of instructions&lt;br /&gt;&lt;br /&gt;You can have a huge If-Then-ElseIf statement and still not have a single instruction that the computer follows. To make sure that the computer follows at least one set of instructions, add an Else statement at the end, as shown in the following:&lt;br /&gt;&lt;br /&gt;If Condition1 Then&lt;br /&gt;   Instructions1&lt;br /&gt;ElseIf Condition2 Then&lt;br /&gt;   Instructions2&lt;br /&gt;Else&lt;br /&gt;   InstructionsDefault&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;This code tells Visual Basic, "If Condition1 is True, then follow the first set of instructions. But if Condition1 is False, check the value of Condition2. If Condition2 is True, then follow the second set of instructions. If all conditions are False, then go ahead and follow the last set of instructions."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* * Nesting If-Then statements&lt;br /&gt;&lt;br /&gt;If you want, you can nest your statements (cram multiple If-Then statements inside one another), such as:&lt;br /&gt;&lt;br /&gt;If Age &gt; 21 Then&lt;br /&gt;   If Rating = 10 Then&lt;br /&gt;      txtAction.Text "Ask for a date,"&lt;br /&gt;   End If&lt;br /&gt;Else&lt;br /&gt;   txtAction.Text = "Sorry, you're too young."&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;If the value of Age were 23 and the value of Rating were 10, Visual Basic interprets this code as follows:&lt;br /&gt;&lt;br /&gt;1. Visual Basic checks the first condition and concludes that the expression Age &gt; 21 is True (because the value of Age is 23).&lt;br /&gt;&lt;br /&gt;2. Then Visual Basic checks the second condition and concludes that the expression Rating = 10 is True, so Visual Basic assigns the string, "Ask for a date." to the Text property of a text box called txtAction.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If the value of Age were 23 but the value of Rating were only 9, Visual Basic interprets this code as follows:&lt;br /&gt;&lt;br /&gt;1. Visual Basic checks the first condition and concludes that the expression Age &gt; 2 1 is True ( because the value of Age is 23).&lt;br /&gt;&lt;br /&gt;2. Then Visual Basic checks the second condition and concludes that the expression Rating = 10 is False, so nothing happens.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Finally, if the value of Age were 13 and the value of Rating were 10, Visual Basic interprets this code as follows:&lt;br /&gt;&lt;br /&gt;1. Visual Basic checks the first condition and concludes that the expression Age &gt; 21 is False (because the value of Age is 13).&lt;br /&gt;&lt;br /&gt;2. Visual Basic skips to the Else part of the If-Then-Else statement and stuffs the string " Sorry, you' re too young. " in the Text property of the text box called txtAction. Notice that in this case, the value of Rating is irrelevant.&lt;br /&gt;&lt;br /&gt;Be careful when nesting If-Then statements inside one another because nested If-Then statements may act in ways that you didn't expect. For example, in the preceding code, if the value of Age were 23 but the value of Rating were only 9, you may be surprised to find that this code isn't going to put any string in the Text property of the text box called txtAction.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 22&lt;br /&gt;&lt;br /&gt;THE SELECT CASE STATEMENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter....&lt;br /&gt;&lt;br /&gt;Examining the Select Case statement&lt;br /&gt;Making sure that the computer follows at least one set of instructions.&lt;br /&gt;Using nested control structures&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The main problem with using massive If-Then-ElseIf statements, which I discuss in Chapter 21, is that these statements are ugly, hard to read and understand, and cumbersome to write. Consider the following:&lt;br /&gt;&lt;br /&gt;If Caller = "Frank" Then&lt;br /&gt;  txtReply.Text = "Yes!"&lt;br /&gt;ElseIf Caller = "Matt" Then&lt;br /&gt;  txtReply.Text = "Okay, but only if you buy."&lt;br /&gt;ElseIf Caller = "Jeff" Then&lt;br /&gt;  txtReply.Text = "I'm washing my hair tonight."&lt;br /&gt;ElseIf Caller = "Steve" Then&lt;br /&gt;  txtReply.Text = "This is a recording."&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So what's the alternative to an endless proliferation of ElseIfs that can be confusing to look at?&lt;br /&gt;&lt;br /&gt;One alternative is to toss your copy of Visual Basic out the window and find someone to write your programs for you. But the more practical alternative is to use something called the Select Case statement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** The Select Case Statement&lt;br /&gt;&lt;br /&gt;The Select Case statement looks like the following:&lt;br /&gt;&lt;br /&gt;Select Case VariableName&lt;br /&gt;  Case X&lt;br /&gt;     Instructions1&lt;br /&gt;  Case Y&lt;br /&gt;     Instructions2&lt;br /&gt;  Case Z&lt;br /&gt;     Instructions3&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This statement tells Visual Basic, "Look at the value of the variable called VariableName. If this value is equal to X, then follow Instructions1. If this value is equal to Y, then follow Instructions2. If this value is equal to Z, then follow Instructions3."&lt;br /&gt;&lt;br /&gt;Replacing the multiple If-Then-ElseIf statement at the beginning of this chapter with the Select Case statement changes the code to look like the following:&lt;br /&gt;&lt;br /&gt;Select Case Caller&lt;br /&gt;  Case "Frank*&lt;br /&gt;     txtReply.Text "Yes!"&lt;br /&gt;  Case "Matt"&lt;br /&gt;     txtReply.Text - "Okay, but only if you buy."&lt;br /&gt;  Case "Jeff"&lt;br /&gt;     txtReply.Text "I'm washing my hair tonight.&lt;br /&gt;  Case "Steve"&lt;br /&gt;     txtReply.Text "This is a recording."&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Notice the cleaner look and the elimination of repetitive words such as ElseIf and Then.&lt;br /&gt;&lt;br /&gt;Depending on how many values you need to check, you can sandwich as many Case lines in a Select Case statement as you want.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Using the Select Case Statement with Comparison Operators&lt;br /&gt;&lt;br /&gt;Normally, the Select Case statement requires an exact value to examine. However, by using comparison operators, such as &lt;, &lt;=, or &lt;&gt;, you can make the Select Case statement examine whether a variable falls within a range of values.&lt;br /&gt;&lt;br /&gt;To make a Select Case statement use comparison operators, you have to use the magic reserved word is. Therefore, the following Select Case statement:&lt;br /&gt;&lt;br /&gt;Select Case Day&lt;br /&gt;  Case is &gt; 15&lt;br /&gt;     txtReadMe.Text = "Bills are past duel"&lt;br /&gt;  Case is &gt; 10&lt;br /&gt;     txtReadMe.Text = "Pay your bills!"&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;is equivalent to the following If-Then statement:&lt;br /&gt;&lt;br /&gt;If Day &gt; 15 Then&lt;br /&gt;  txtReadMe.Text - "Bills are past due!"&lt;br /&gt;ElseIf Day &gt; 10 Then&lt;br /&gt;  txtReadMe.Text = "Pay your bills!"&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Making Sure the Computer Follows at Least One Set of Instructions&lt;br /&gt;&lt;br /&gt;Like the If-Then-ElseIf statement, the possibility that none of the instructions within the Select Case statement are going to be followed exists. To make sure that the computer follows at least one set of instructions, you have to use the magical Else command again. Take a look at the following example:&lt;br /&gt;&lt;br /&gt;Select Case Day&lt;br /&gt;  Case 1&lt;br /&gt;     Instructions1&lt;br /&gt;  Case 2&lt;br /&gt;     Instructions2&lt;br /&gt;  Case3&lt;br /&gt;     Instructions3&lt;br /&gt;  Case Else&lt;br /&gt;     InstructionsDefault&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The preceding code tells Visual Basic, "If the value of Day equals 1, then follow the first set of instructions. If the value of Day equals 2, then follow the second set of instructions. If the value of Day equals 3, then follow the third set of instructions. If the value of Day doesn't equal 1, 2, or 3, then follow the last set of instructions."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** Nesting Case Statements&lt;br /&gt;&lt;br /&gt;Some of the simplest toys that amuse children to no end are those Chinese boxes stacked one inside the other. Each time you open a box, you find a smaller one inside. Eventually, you reach a point where no more boxes remain and you have to stop.&lt;br /&gt;&lt;br /&gt;Normally an ordinary Select Case statement contains one or more groups of instructions, such as the following:&lt;br /&gt;&lt;br /&gt;Select Case ID&lt;br /&gt;  Case 123&lt;br /&gt;     chkFrank.Value = True&lt;br /&gt;  Case 124&lt;br /&gt;     chkBob.Value&lt;br /&gt;  Case 125&lt;br /&gt;      chkMartha.Value = True&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Rather than shoving boring old instructions inside a Select Case statement, however, you can shove If-Then and Select Case statements within a Select Case statement, as the following example illustrates:&lt;br /&gt;&lt;br /&gt;Select Case IQ&lt;br /&gt;  Case 120&lt;br /&gt;     Select Case Age&lt;br /&gt;        Case is &lt;= 9&lt;br /&gt;           txtAnalysis.Text = "You must be a smart kid."&lt;br /&gt;     End Select&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here's how Visual Basic interprets this code:&lt;br /&gt;&lt;br /&gt;1. The first line says, "Check the value stored in a variable called IQ. Then continue to the second line."&lt;br /&gt;&lt;br /&gt;2. The second line says, "If the value of IQ is exactly equal to 120, continue to the third line. If the value of IQ is anything else (such as 119, 121, or 3), skip to the seventh line.&lt;br /&gt;&lt;br /&gt;3. The third line says, "Check the value stored in a variable called Age.  Then continue to the fourth line."&lt;br /&gt;&lt;br /&gt;4. The fourth line says, "If the value stored in the variable called Age is equal to or less than 9, then continue to the fifth line. If the value of Age is anything greater than 9 (such as 13, 86, or 10), then skip to the sixth line."&lt;br /&gt;&lt;br /&gt;5. The fifth line says, "Assign the string, " You must be a smart kid." to the Text property of a text box called txtAnalysis."&lt;br /&gt;&lt;br /&gt;6. The sixth line says, "This is the end of one Select Case statement."&lt;br /&gt;&lt;br /&gt;7. The seventh line says, "This is the end of another Select Case statement."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For kicks and grins, you can put an If-Then statement inside a Select Case statement or a Select Case statement inside an If-Then statement. (Some fun, huh?)&lt;br /&gt;&lt;br /&gt;Although no theoretical limit exists as to how many If-Then or Select Case statements you can place inside one another, the fewer you use, the easier your code is going to be to figure out. As a general rule, if you have nested more than three If-Then or Case Select statements inside one another, you probably don't know what you're doing.&lt;br /&gt;&lt;br /&gt;When nesting multiple statements, you should indent statements so that seeing where they begin and end is easier. For example, notice how confusing the following program appears without indentation:&lt;br /&gt;&lt;br /&gt;Select Case Salary&lt;br /&gt;Case 1200&lt;br /&gt;If Name = "Bob" Then&lt;br /&gt;txtReview.Text = "No raise this year, ha, ha, ha!"&lt;br /&gt;ElseIf Name = "Karen" Then&lt;br /&gt;txt Review.Text = "Okay, how about a 5% raise?"&lt;br /&gt;End If&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here's what the same program looks like with indentation:&lt;br /&gt;&lt;br /&gt;Select Case Salary&lt;br /&gt;  Case 1200&lt;br /&gt;     If Name = "Bob" Then&lt;br /&gt;        txtReview.Text = "No raise this year, ha, ha, ha!"&lt;br /&gt;     ElseIf Name = "Karen" Then&lt;br /&gt;        txt Review.Text = "Okay, how about a 5% raise?"&lt;br /&gt;     End If&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;From the computer's point of view, both programs are the same. But from a programmer's point of view, the program using indentation is much easier to read and understand.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;* Test your newfound knowledge&lt;br /&gt;&lt;br /&gt;1. What is the limit to the number of control structures (If-Then or Select Case statements) you can nest?&lt;br /&gt;&lt;br /&gt;a. The limit is determined by the restrictions your government may place upon you.&lt;br /&gt;b. The limit is determined by the theoretical applications pursuant to the implications of Einstein's theory of relativity, as reworded by a lawyer.&lt;br /&gt;c. The limit is 65.  If you go over that, you risk getting pulled over by a state trooper.&lt;br /&gt;d. No limit exists. But if you have too many nested control structures, your program is going to be harder to read and understand.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. To make nested control structures easier to read and understand, what do you need to do?&lt;br /&gt;&lt;br /&gt;a. Avoid using nested control structures&lt;br /&gt;b. Avoid programming altogether.&lt;br /&gt;c. Limit the number of nested control structures you use, and use indentation to make each If-Then or Select Case statement easy to find.&lt;br /&gt;d. Print in big, bold, block letters and use short statements like "See Dick run.  Dick runs fast."&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ PART VI&lt;br /&gt;&lt;br /&gt;GETTING LOOPY&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In this part....&lt;br /&gt;&lt;br /&gt;Every program contains instructions that tell the computer what to do. Sometimes these instructions are used only once, such as instructions that tell the computer what to do when the program loads.&lt;br /&gt;&lt;br /&gt;But other times, the computer may need certain instructions over and over again. Rather than retyping these instructions each time, programmers invented something magical called loops.&lt;br /&gt;&lt;br /&gt;Essentially a loop tells the computer, "See those instructions over there? Keep repeating them again and again a certain number of times, and then stop." By using loops, programmers spare themselves the tedium of repeatedly writing the same instructions - and saving time is what programmers know how to do best.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;++ CHAPTER 23&lt;br /&gt;&lt;br /&gt;THE DO WHILE AND DO-LOOP WHILE LOOPS&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In This Chapter ....&lt;br /&gt;&lt;br /&gt;Using the Do While loop&lt;br /&gt;Finding out how often the Do While loop runs&lt;br /&gt;Examining how the Do-Loop While loop works and when to use it&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Do While loops don't do anything without checking if a certain condition is True first. If a certain condition is True, then the Do While loop goes ahead and does something. Otherwise, it jumps to the next instruction in the Visual Basic program.&lt;br /&gt;&lt;br /&gt;You can find Do While loops in such everyday experiences as when office workers tell themselves, "Keep stuffing office supplies in my briefcase while no one is looking. The moment someone looks in my direction, stop and do something else."&lt;br /&gt;&lt;br /&gt;A Do While loop looks like this:&lt;br /&gt;&lt;br /&gt;Do While Condition&lt;br /&gt;  Instructions&lt;br /&gt;Loop&lt;br /&gt;&lt;br /&gt;The condition must be a variable or an expression that represents a True or False value. A Do While loop can hold one or more instructions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;** How the Do While Loop Works&lt;br /&gt;&lt;br /&gt;The first time Visual Basic sees a Do While loop, it says, "Okay, is the value of the condition True or False? If it's False, ignore all the instructions inside the Do While loop. If it's True, follow all the instructions inside the Do While loop."&lt;br /&gt;&lt;br /&gt;For example, the following code has a Do While loop:&lt;br /&gt;&lt;br /&gt;Counter = 0&lt;br /&gt;Do While Counter &lt;&gt; 5&lt;br /&gt;   Counter = Counter + 1&lt;br /&gt;   txtCounter.Text = CStr(Counter)&lt;br /&gt;Loop&lt;br /&gt;&lt;br /&gt;Visual Basic interprets the code like this:&lt;br /&gt;&lt;br /&gt;1. The first line says, "Stuff 
