Clearly Visual Basic Programming with Microsoft Visual Basic 2012 3rd Edition Diane Zak pdf download
Clearly Visual Basic Programming with Microsoft Visual Basic 2012 3rd Edition Diane Zak pdf download
https://ebookname.com/product/clearly-visual-basic-programming-
with-microsoft-visual-basic-2012-3rd-edition-diane-zak/
https://ebookname.com/product/microsoft-visual-
basic-2015-reloaded-6th-edition-edition-diane-zak/
https://ebookname.com/product/microsoft-visual-
basic-2008-express-programming-for-the-absolute-beginner-1st-
edition-ford/
https://ebookname.com/product/visual-basic-game-programming-with-
directx-1st-edition-jonathan-s-harbour/
https://ebookname.com/product/vectors-and-tensors-in-engineering-
and-physics-2nd-edition-danielson/
The Democratic Promise The Individual Within the
Community First Printing Edition Constance Goh
https://ebookname.com/product/the-democratic-promise-the-
individual-within-the-community-first-printing-edition-constance-
goh/
https://ebookname.com/product/dk-findout-animals-first-american-
edition-baker/
https://ebookname.com/product/data-structures-and-algorithms-in-
java-5th-international-student-edition-m-t-goodrich-and-r-
tamassia/
https://ebookname.com/product/the-politics-of-denial-israel-and-
the-palestinian-refugee-problem-1st-edition-nur-masalha/
https://ebookname.com/product/aacn-essentials-of-critical-care-
nursing-first-edition-marianne-chulay/
Equity and Index Options Explained 1st Edition W. A.
Beagles
https://ebookname.com/product/equity-and-index-options-
explained-1st-edition-w-a-beagles/
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
THIRD EDITION
DIANE ZAK
Australia l Brazil l Japan l Korea l Mexico l Singapore l Spain l United Kingdom l United States
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Clearly Visual Basic: ª 2014 Course Technology, Cengage Learning
Programming with Microsoft
ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be
Visual Basic 2012, Third Edition reproduced, transmitted, stored or used in any form or by any means graphic, electronic,
Diane Zak or mechanical, including but not limited to photocopying, recording, scanning, digitizing,
taping, Web distribution, information networks, or information storage and retrieval
Executive Editor: Kathleen McMahon
systems, except as permitted under Section 107 or 108 of the 1976 United States
Senior Product Manager: Alyssa Pratt Copyright Act, without the prior written permission of the publisher.
Editorial Assistant: Sarah Ryan
Content Project Manager:
For product information and technology assistance, contact us at
Jennifer Feltri-George
Cengage Learning Customer & Sales Support, www.cengage.com/support
Quality Assurance: Nicole Spoto
For permission to use material from this text or product,
Art Director: Cheryl Pearl, GEX
submit all requests online at cengage.com/permissions
Cover Designer: GEX Publishing Services Further permissions questions can be emailed to
Text Designer: Shawn Girsberger [email protected]
Senior Print Buyer: Julio Esperas
Proofreader: Suzanne Huizenga Library of Congress Control Number: 2013932801
Indexer: Constance A. Angelo
ISBN-13: 978-1-285-08410-7
Compositor: Integra Software Services Pvt. Ltd.
ISBN-10: 1-285-08410-1
Course Technology
20 Channel Center Street
Boston, MA 02210
USA
Some of the product names and company names used in this book have been used for
identification purposes only and may be trademarks or registered trademarks of their
respective manufacturers and sellers.
Course Technology, a part of Cengage Learning, reserves the right to revise this
publication and make changes from time to time in its content without notice.
Example: Microsoft® is a registered trademark of the Microsoft Corporation.
Cengage Learning is a leading provider of customized learning solutions with office
locations around the globe, including Singapore, the United Kingdom, Australia,
Mexico, Brazil, and Japan. Locate your local office at: www.cengage.com/global
Cengage Learning products are represented in Canada by Nelson Education, Ltd.
To learn more about Course Technology, visit
www.cengage.com/coursetechnology
To learn more about Cengage Learning, visit www.cengage.com
Purchase any of our products at your local college store or at our preferred online store
www.cengagebrain.com
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Brief Contents
iii
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . xii
C H AP T E R 1 I Am Not a Control Freak! (Control Structures) . . . . . . . . . 1
C H AP T E R 2 First You Need to Plan the Party (Problem-Solving Process) . . 17
C H AP T E R 3 I Need a Tour Guide (Introduction to Visual Basic 2012) . . . . 35
C H AP T E R 4 Do-It-Yourself Designing (Designing Interfaces) . . . . . . . . 63
C H AP T E R 5 The Secret Code (Assignment Statements) . . . . . . . . . . 87
C H AP T E R 6 Where Can I Store This? (Variables and Constants) . . . . . . 107
C H AP T E R 7 What’s Wrong With It? (Syntax, Logic, and Run Time Errors) . . 131
C H AP T E R 8 Decisions, Decisions, Decisions (Selection Structure) . . . . . 151
C H AP T E R 9 Time to Leave the Nest (Nested Selection Structures) . . . . . 185
C H AP T E R 1 0 So Many Paths…So Little Time (Multiple-Alternative
Selection Structures) . . . . . . . . . . . . . . . . . . . 211
C H AP T E R 1 1 Testing, Testing…1, 2, 3 (Selecting Test Data) . . . . . . . . 237
C H AP T E R 1 2 How Long Can This Go On? (Pretest Loops) . . . . . . . . . . 261
C H AP T E R 1 3 Do It, Then Ask Permission (Posttest Loops) . . . . . . . . . 293
C H AP T E R 1 4 Let Me Count the Ways (Counter-Controlled Loops) . . . . . . 305
C H AP T E R 1 5 I’m on the Inside; You’re on the Outside (Nested Loops) . . . . 329
C H AP T E R 1 6 I Hear You Are Breaking Up (Sub Procedures) . . . . . . . . . 353
C H AP T E R 1 7 Talk to Me (Function Procedures) . . . . . . . . . . . . . . 383
C H AP T E R 1 8 A Ray of Sunshine (One-Dimensional Arrays) . . . . . . . . . 403
C H AP T E R 1 9 Parallel and Dynamic Universes (More on
One-Dimensional Arrays) . . . . . . . . . . . . . . . . . . 431
C H AP T E R 2 0 Table Tennis, Anyone? (Two-Dimensional Arrays) . . . . . . . 455
C H AP T E R 2 1 Building Your Own Structure (Structures) . . . . . . . . . . . 479
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
BRIEF CONTENTS
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Contents
v
Preface . . . . . . . . . . . . . . . . . . . . . . . . . xii
C H AP T E R 1 I Am Not a Control Freak! (Control Structures) . . . . . . . . 1
Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
The Sequence Structure . . . . . . . . . . . . . . . . . . . . . . . . . . 2
The Selection Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Repetition Structure . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS
C H AP T E R 7 What’s Wrong With It? (Syntax, Logic, and Run Time Errors) . . . 131
There’s a Bug in My Soup! . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Finding Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Locating Logic Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
I’ve Reached My Breaking Point . . . . . . . . . . . . . . . . . . . . . . . . 141
Run Time Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Are We in the Black or in the Red? . . . . . . . . . . . . . . . . . . . . . 160
You Deserve a Bonus . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Examining Another Problem Specification . . . . . . . . . . . . . . . . . . . 168
Hey, That’s Not the Way I Would Have Done It . . . . . . . . . . . . . . . . 173
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 vii
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CONTENTS
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
C H AP T E R 1 6 I Hear You Are Breaking Up (Sub Procedures) . . . . . . . 353
What’s the Proper Procedure? . . . . . . . . . . . . . . . . . . . . . . . . 354
The Weekly Pay Application . . . . . . . . . . . . . . . . . . . . . . . . 356
Send Me Something . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Just Give Me Its Value, Please . . . . . . . . . . . . . . . . . . . . . . . 360
Where Do You Live? . . . . . . . . . . . . . . . . . . . . . . . . . . . 364 ix
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface
xii
Clearly Visual Basic: Programming with Microsoft Visual Basic 2012, Third Edition is designed
for a beginning programming course. The book assumes students have no previous
programming knowledge or experience. However, students should be familiar with basic
Windows skills and file management. The book’s primary focus is on teaching programming
concepts, with a secondary focus on teaching the Visual Basic programming language. In other
words, the purpose of the book is to teach students how to solve a problem that requires a
computer solution. The Visual Basic language is used as a means of verifying that the solution
works correctly.
Approach
Rather than focusing on a specific programming language, Clearly Visual Basic:
Programming with Microsoft Visual Basic 2012, Third Edition focuses on programming
concepts that are common to all programming languages—such as input, output, selection,
and repetition. Concepts are introduced, illustrated, and reinforced using simple examples
and applications, which are more appropriate for a first course in programming. The
concepts are spread over many short chapters, allowing students to master the material one
small piece at a time. Because its emphasis is on teaching the fundamentals of programming,
the book covers only the basic controls, properties, and events available in Visual Basic.
Each chapter provides the steps for creating and/or coding one or more applications that use
the concepts covered in the chapter. The videos and PDF files that accompany each chapter
are designed to help students master the chapter’s concepts.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Organization and Coverage
Features
Clearly Visual Basic: Programming with Microsoft Visual Basic 2012, Third Edition is an
exceptional textbook because it also includes the following features:
READ THIS BEFORE YOU BEGIN This section is consistent with Cengage’s commitment to
helping instructors introduce technology into the classroom. Technical considerations and
assumptions about hardware, software, and default settings are listed in one place to help xiii
instructors save time and eliminate unnecessary aggravation.
DESIGNED FOR THE DIFFERENT LEARNING STYLES The book provides videos for visual and
auditory learners, and tutorial sections and Want More Info? files for kinesthetic learners.
VIDEOS These notes direct students to videos that accompany each chapter in the book. The
videos explain and/or demonstrate one or more of the chapter’s concepts, provide additional
information about the concepts, or cover topics related to the concepts. The videos are available
online at www.cengagebrain.com. Search for the ISBN of your title (from the back cover of your
book) using the search box at the top of the page. This will take you to the product page where
free companion resources can be found.
WANT MORE INFO? FILES These notes direct students to files that accompany each chapter in
the book. The files contain additional examples and further explanations of the concepts
covered in the chapter. The files are in PDF format. The files are available online at www.
cengagebrain.com.
FIGURES Figures that introduce new statements, functions, or methods contain both the syntax
and examples of using the syntax. Including the syntax in the figures makes the examples more
meaningful, and vice versa.
OBJECTIVES Each chapter begins with a list of objectives so you know the topics that will be
presented in the chapter. In addition to providing a quick reference to topics covered, this
feature provides a useful study aid.
MINI-QUIZZES Mini-Quizzes are strategically placed to test students’ knowledge at various
points in each chapter. Answers to the quiz questions are provided in Appendix B.
APPENDIX B Appendix B, which is available online at www.cengagebrain.com, contains the
answers to each chapter’s Mini-Quizzes and TRY THIS Exercises. The answers are provided to
give students immediate feedback and more opportunity for learning.
SUMMARY Each chapter contains a Summary section that recaps the concepts covered in the
chapter.
KEY TERMS Following the Summary section in each chapter is a listing of the key terms
introduced throughout the chapter, along with their definitions.
REVIEW QUESTIONS Each chapter contains Review Questions designed to test a student’s
understanding of the chapter’s concepts.
EXERCISES The Review Questions in each chapter are followed by Exercises, which provide
students with additional practice of the skills and concepts they learned in the chapter. The
Exercises are designated as TRY THIS, MODIFY THIS, INTRODUCTORY, INTERMEDIATE,
ADVANCED, FIGURE THIS OUT, and SWAT THE BUGS.
TRY THIS EXERCISES The TRY THIS Exercises should be the first Exercises students complete
after reading a chapter. These Exercises are similar to an application developed in the chapter,
and they allow students to test their understanding of the chapter’s concepts. The answers to
TRY THIS Exercises are provided in Appendix B.
MODIFY THIS EXERCISES In these Exercises, students modify an existing application.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
PREFACE Instructor Resources
FIGURE THIS OUT EXERCISES These Exercises require students to analyze a block of code and
then answer questions about the code.
SWAT THE BUGS EXERCISES The SWAT THE BUGS Exercises provide an opportunity for
students to detect and correct errors in an existing application.
xiv
New to This Edition!
VIDEOS The videos that accompany each chapter have been updated from the previous edition
of the book.
REVIEW QUESTIONS AND EXERCISES New Review Questions and Exercises have been added to
each chapter.
NEW EXAMPLES The chapters have been updated with new examples and sample applications.
CHAPTER 8 Chapter 8 now shows students how to prevent the “division by zero” run time
error. It also covers a control’s ForeColor property.
CHAPTER 9 Radio buttons are now covered in Chapter 9 rather than in Chapter 10.
CHAPTER 18 Class-level arrays are now covered in Chapter 18 rather than in Chapter 19.
Chapter 18 also covers the form’s Load event procedure.
CHAPTER 23 The Replace method is now covered in Exercise 13 in Chapter 23 rather than in
the chapter itself.
Instructor Resources
All of the resources available with this book can be found at www.cengagebrain.com. At the
CengageBrain.com home page, search for the ISBN of your title (from the back cover of your
book) using the search box at the top of the page. This will take you to the product page where
free companion resources can be found.
ELECTRONIC INSTRUCTOR’S MANUAL The Instructor’s Manual that accompanies this textbook
includes additional instructional material to assist in class preparation, including items such as
Sample Syllabi, Chapter Outlines, Technical Notes, Lecture Notes, Quick Quizzes, Teaching
Tips, Discussion Topics, and Additional Case Projects.
EXAMVIEW® This textbook is accompanied by ExamView, a powerful testing software package
that allows instructors to create and administer printed, computer (LAN-based), and Internet
exams. ExamView includes hundreds of questions that correspond to the topics covered in this
text, enabling students to generate detailed study guides that include page references for further
review. The computer-based and Internet testing components allow students to take exams at
their computers, and also save the instructor time by grading each exam automatically.
POWERPOINT PRESENTATIONS This book offers Microsoft PowerPoint slides for each chapter.
These are included as a teaching aid for classroom presentation, to make available to students on
the network for chapter review, or to be printed for classroom distribution. Instructors can add
their own slides for additional topics they introduce to the class.
DATA FILES Data Files are necessary for completing the computer activities in this book. The
Data Files are also provided for students at www.cengagebrain.com.
SOLUTION FILES Solutions to the chapter applications and the end-of-chapter Review
Questions and Exercises are available for instructors.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Acknowledgments
Acknowledgments
Writing a book is a team effort rather than an individual one. I would like to take this
opportunity to thank my team, especially Jennifer Feltri-George (Content Project Manager),
Alyssa Pratt (Senior Product Manager), Nicole Ashton (Quality Assurance), Suzanne Huizenga
(Proofreader), Carmel Isaac (Integra), Sreejith Govindan (Client Manager, Integra), and the
compositors at Integra. Thank you for your support, enthusiasm, patience, and hard work. Last, xv
but certainly not least, I want to thank the following reviewers for their invaluable ideas and
comments: Bill Hammerschlag, Dallas County Community College District; Bobbie Hyndman,
Amarillo College; and Linda Truman, Abraham Baldwin Technical College.
Diane Zak
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Read This Before
xvi
You Begin
Technical Information
Data Files
You will need data files to complete the computer activities in this book. Your instructor may
provide the data files to you. You may obtain the files electronically at www.cengagebrain.com,
and then navigating to the page for this book.
Each chapter in this book has its own set of data files, which are stored in a separate folder
within the ClearlyVB2012 folder. The files for Chapter 3 are stored in the ClearlyVB2012\Chap03
folder. Similarly, the files for Chapter 4 are stored in the ClearlyVB2012\Chap04 folder.
Throughout this book, you will be instructed to open files from or save files to these folders.
You can use a computer in your school lab or your own computer to complete the chapter
applications and Exercises in this book.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Read This Before You Begin
3. Expand the Projects and Solutions node in the Options dialog box and then click VB
Defaults. Verify that both Option Explicit and Option Infer are set to On. Also verify that
Option Strict and Option Compare are set to Off and Binary, respectively. Click the OK
button to close the Options dialog box.
Figures xvii
The figures in this book reflect how your screen will look if you are using Microsoft Visual
Studio Professional 2012 and a Microsoft Windows 8 system. Your screen may appear slightly
different in some instances if you are using another version of Microsoft Visual Studio or
Microsoft Windows.
To the Instructor
To complete the computer activities in this book, your students must use a set of data files.
These files can be obtained electronically at www.cengagebrain.com.
The material in this book was written using Microsoft Visual Studio Professional 2012 on a
Microsoft Windows 8 system. It was Quality Assurance tested using Microsoft Visual Studio
Professional 2012 and Microsoft Visual Studio Express 2012 for Web on both a Windows 8 and
a Windows 7 system. The book assumes that both Option Explicit and Option Infer are set to
On, Option Strict is set to Off, and Option Compare is set to Binary. To verify these settings,
start your edition of Visual Studio. Click TOOLS on the menu bar and then click Options.
Expand the Projects and Solutions node in the Options dialog box and then click VB Defaults.
Verify the four Option settings and then click the OK button to close the Options dialog box.
Data Files
You are granted a license to copy the data files to any computer or computer network used by
individuals who have purchased this book.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1
I Am Not a Control Freak!
(Control Structures)
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1 I Am Not a Control Freak! (Control Structures)
Control Structures
All computer programs, no matter how simple or how complex, are written using one or more
of three basic structures: sequence, selection, and repetition. These structures are called control
structures or logic structures because they control the flow of a program’s logic. You will use
the sequence structure in every program you write. In most programs, you also will use the
2 selection and repetition structures. For maximum flexibility and to write powerful programs,
you can use the three control structures in many different combinations throughout your
program. This chapter gives you an introduction to the three control structures. More detailed
information about each structure, as well as how to implement these structures using the Visual
Basic language, is provided in subsequent chapters.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Control Structures
Harold is standing outside facing a park bench. The bench is two steps away from Harold. Write the
instructions that direct Harold to sit down on the bench.
1. walk forward
2. walk forward
3. turn left 90 degrees algorithm
4. turn left 90 degrees
5. sit down on the bench
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1 I Am Not a Control Freak! (Control Structures)
shove Ginger off the bench. The if Ginger is on the bench, do this: instruction allows Harold to
make a decision about the status of Ginger, and it represents the beginning of a selection
structure. The Ginger is on the bench portion is the condition that Harold must evaluate to
make a decision. Notice that the condition results in either a true or a false answer: either
Ginger is on the bench (true) or she’s not (false). The end if instruction denotes the end of a
selection structure.
4
The last three instructions in the original algorithm turn Harold left 180 degrees and then sit
him down; Harold will still need to follow those instructions. Figure 1-2 shows the modified
problem specification, illustration, and algorithm. Notice that the gently shove Ginger off the
bench instruction is indented within the selection structure. Indenting in this manner indicates
that the instruction should be followed only when Ginger is on the bench—in other words, only
when the condition results in an answer of true. The instructions to be followed when a
selection structure’s condition evaluates to true are referred to as the structure’s true path.
Ch01-Harold Although the true path in Figure 1-2 includes only one instruction, it can include many
Selection instructions. (You can observe Harold as he follows Figure 1-2’s algorithm by viewing the
video Ch01-Harold Selection video.)
Harold is standing outside facing a park bench. The bench is two steps away from Harold. Harold’s cat
Ginger may be on the bench. Write the instructions that direct Harold to gently shove Ginger off the
bench (if necessary) and then sit down on the bench.
1. walk forward
2. walk forward condition
Figure 1-3 shows how the selection structure can be used in a game program. In this game,
our superhero gets one shot at the villain. He needs to raise his right arm before taking the
shot. If he hits the villain, he should say “Got Him” and then lower his right arm. If he doesn’t
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Control Structures
hit the villain, he should say “Missed Him” before lowering his right arm. Our superhero can
understand only these eight instructions: raise right arm, lower right arm, shoot at the villain, if
the villain was hit, do this:, otherwise, do this:, end if, say “Got Him”, say “Missed Him”.
The superhero gets one shot at the villain. He needs to raise his right arm before taking the shot. If he
hits the villain, he should say “Got Him” and then lower his right arm. If he doesn’t hit the villain, he
should say “Missed Him” before lowering his right arm. 5
Unlike the selection structure from Figure 1-2, which requires Harold to take a specific action
only when the structure’s condition evaluates to true, the selection structure in Figure 1-3
requires our superhero to take one action when the condition evaluates to true, but a different
action when it evaluates to false. In other words, the selection structure in Figure 1-3 has both a
true path and a false path. The otherwise, do this: instruction marks the beginning of the false
path instructions. Notice that the say “Got Him” and say “Missed Him” instructions are
indented within their respective paths. Indenting in this manner clearly indicates the instruction
to be followed when the condition evaluates to true (the villain was hit), as well as the one to be
Ch01-
followed when the condition evaluates to false (the villain was not hit). Although both paths in
Superhero
Figure 1-3’s selection structure contain only one instruction, each can contain many Selection
instructions. (You can observe our superhero in action by viewing the Ch01-Superhero video
Selection video.)
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Exploring the Variety of Random
Documents with Different Content
*** END OF THE PROJECT GUTENBERG EBOOK THE JEWELS OF
APTOR ***
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com