This page intentionally left blank
STARTING OUT WITH
Visual Basic® 2012 Sixth Edit ion
This page intentionally left blank
STARTING OUT WITH
Visual Basic® 2012 Sixth Edit ion
Tony Gaddis Haywood Community College
Kip Irvine Florida International University
Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montréal Toronto
Delhi Mexico City Sa~o Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo
Editorial Director, ECS: Marcia Horton Acquisitions Editor: Matt Goldstein Editorial Assistant: Jenah Blitz-Stoehr Director of Marketing: Christy Lesko Marketing Manager: Yezan Alayan Senior Marketing Coordinator: Kathryn Ferranti Director of Production: Erin Gregg Senior Managing Editor: Scott Disanno Senior Production Project Manager: Marilyn Lloyd Manufacturing Buyer: Lisa McDowell Art Director: Anthony Gemmellaro Cover Designer: Joyce Cosentino Wells Manager, Rights and Permissions: Michael Joyce Cover Image: © Vladimir Nenov/Alamy Media Project Manager: Renata Butera Full-Service Project Manager: Jogender Taneja/iEnergizer Aptara®, Inc. Composition: Aptara®, Inc. Printer/Binder: Edwards Brothers, Inc. Cover Printer: Lehigh-Phoenix Color
Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on the Credits page at the end of the text.
Copyright © 2014, 2011, 2010 Pearson Education, Inc., publishing as Addison-Wesley. All rights reserved. Printed in the United States of America. This publication is protected by Copyright, and permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission(s) to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to 201-236-3290.
Many of the designations by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed in initial caps or all caps.
The programs and applications presented in this book have been included for their instructional value. They have been tested with care, but are not guaranteed for any particular purpose. The publisher does not offer any warranties or representations, nor does it accept any liabilities with respect to the programs or applications.
Library of Congress Cataloging-in-Publication Data available upon request.
10 9 8 7 6 5 4 3 2 1
ISBN 10: 0-13-312808-3 ISBN 13: 978-0-13-312808-6
v
Contents in Brief
Preface xvii
Chapter 1 Introduction to Programming and Visual Basic 1
Chapter 2 Creating Applications with Visual Basic 43
Chapter 3 Variables and Calculations 111
Chapter 4 Making Decisions 209
Chapter 5 Lists and Loops 285
Chapter 6 Procedures and Functions 355
Chapter 7 Multiple Forms, Modules, and Menus 403
Chapter 8 Arrays and More 469
Chapter 9 Files, Printing, and Structures 541
Chapter 10 Working with Databases 597
Chapter 11 Developing Web Applications 677
Chapter 12 Classes, Collections, and Inheritance 733
Appendix A Advanced User Interface Controls and Techniques 795
Appendix B Windows Presentation Foundation (WPF) 809
Appendix C Converting Mathematical Expressions to Programming Statements 821
Appendix D Answers to Checkpoints 823
Appendix E Glossary 841
Index 853
Credits 883