100% found this document useful (1 vote)
29 views

Clearly Visual Basic Programming with Microsoft Visual Basic 2012 3rd Edition Diane Zak pdf download

The document provides information about various editions of Visual Basic programming textbooks authored by Diane Zak and others, available for download in multiple formats. It includes links to purchase or access these eBooks, as well as details about the content and structure of the textbooks. Additionally, it outlines copyright information and the publisher's rights regarding the material.

Uploaded by

fadlitajwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
29 views

Clearly Visual Basic Programming with Microsoft Visual Basic 2012 3rd Edition Diane Zak pdf download

The document provides information about various editions of Visual Basic programming textbooks authored by Diane Zak and others, available for download in multiple formats. It includes links to purchase or access these eBooks, as well as details about the content and structure of the textbooks. Additionally, it outlines copyright information and the publisher's rights regarding the material.

Uploaded by

fadlitajwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

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/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Microsoft Visual Basic 2015 RELOADED 6th Edition


Edition Diane Zak

https://ebookname.com/product/microsoft-visual-
basic-2015-reloaded-6th-edition-edition-diane-zak/

Microsoft Visual Basic 2008 Express Programming for the


Absolute Beginner 1st Edition Ford

https://ebookname.com/product/microsoft-visual-
basic-2008-express-programming-for-the-absolute-beginner-1st-
edition-ford/

Visual Basic Game Programming with DirectX 1st Edition


Jonathan S. Harbour

https://ebookname.com/product/visual-basic-game-programming-with-
directx-1st-edition-jonathan-s-harbour/

Vectors and Tensors in Engineering and Physics 2nd


Edition Danielson

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/

DK findout Animals First American Edition Baker

https://ebookname.com/product/dk-findout-animals-first-american-
edition-baker/

Data Structures and Algorithms in Java 5th


International student edition M.T. Goodrich And R.
Tamassia

https://ebookname.com/product/data-structures-and-algorithms-in-
java-5th-international-student-edition-m-t-goodrich-and-r-
tamassia/

The Politics of Denial Israel and the Palestinian


Refugee Problem 1st Edition Nur Masalha

https://ebookname.com/product/the-politics-of-denial-israel-and-
the-palestinian-refugee-problem-1st-edition-nur-masalha/

AACN Essentials of Critical Care Nursing First Edition


Marianne Chulay

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

CLEARLY VISUAL BASIC ®


PROGRAMMING WITH MICROSOFT ® VISUAL BASIC ® 2012

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

Printed in the United States of America


1 2 3 4 5 6 7 19 18 17 16 15 14 13

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

C H AP T E R 2 2 I’m Saving for the Future (Sequential Access Files) . . . . . . 497


C H AP T E R 2 3 The String Section (String Manipulation) . . . . . . . . . . . 515
C H AP T E R 2 4 I’m Suffering from Information Overload (Access Databases) . . 539
C H AP T E R 2 5 The Missing “LINQ” (Querying a Database) . . . . . . . . . . 569
iv
C H AP T E R 2 6 I Love This Class (Creating a Class) . . . . . . . . . . . . . 587
C H AP T E R 2 7 Getting “Web-ified” (Web Applications) . . . . . . . . . . . . 611
A PP E N D I X A Data Types . . . . . . . . . . . . . . . . . . . . . . . . 645
A PP E N D I X B Answers to Mini-Quizzes and TRY THIS Exercises . . . . . . Online
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . 647

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

C H AP T E R 2 First You Need to Plan the Party (Problem-Solving Process) . . 17


How Do Programmers Solve Problems? . . . . . . . . . . . . . . . . . . . . . 18
Step 1—Analyze the Problem . . . . . . . . . . . . . . . . . . . . . . . . 18
Step 2—Plan the Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 20
Step 3—Desk-Check the Algorithm . . . . . . . . . . . . . . . . . . . . . . 24
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

C H AP T E R 3 I Need a Tour Guide (Introduction to Visual Basic 2012) . . . . 35


Ok, the Algorithm Is Correct. What’s Next? . . . . . . . . . . . . . . . . . . . . 36
Creating a Visual Basic Windows Application . . . . . . . . . . . . . . . . . . . 38
So Many Windows! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Creating the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Save, Save, Save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Whose Property Is It? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Using the FORMAT Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Lock Them Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Ok, Let’s See the Interface in Action! . . . . . . . . . . . . . . . . . . . . . . 52
Closing the Current Solution . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Opening an Existing Solution . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Exiting Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

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 4 Do-It-Yourself Designing (Designing Interfaces) . . . . . . . . 63


Delegating the Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Making the Interface More User-Friendly . . . . . . . . . . . . . . . . . . . . . . 68
Do What I Tell You to Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
The Me.Close() Instruction . . . . . . . . . . . . . . . . . . . . . . . . . 74
vi Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

C H AP T E R 5 The Secret Code (Assignment Statements) . . . . . . . . . . 87


The Fun Starts Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
The Val Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Who’s in Charge of This Operation? . . . . . . . . . . . . . . . . . . . . . . . . . 91
Your Assignment, if You Choose to Accept It . . . . . . . . . . . . . . . . . . . . . 94
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

C H AP T E R 6 Where Can I Store This? (Variables and Constants) . . . . . . . 107


Using Shoe Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
So, What’s Your Type? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Let’s Play the Name Game . . . . . . . . . . . . . . . . . . . . . . . . . . 110
You’ll Need a Reservation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
How Many Variables Should I Use? . . . . . . . . . . . . . . . . . . . . . . . . 111
The TryParse Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Check, Please…I’m Ready to Go . . . . . . . . . . . . . . . . . . . . . . . . 115
Using Constants to Keep Things…Well, the Same . . . . . . . . . . . . . . . . . . 116
Dressing Up the Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

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

C H AP T E R 8 Decisions, Decisions, Decisions (Selection Structure) . . . . . 151


Someone Might Need to Make a Decision . . . . . . . . . . . . . . . . . . . . . 152
The If…Then…Else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Stop That Runner! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

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

C H AP T E R 9 Time to Leave the Nest (Nested Selection Structures) . . . 185


Nested Selection Structures . . . . . . . . . . . . . . . . . . . . . . . . . 186
10-4, Over and Out . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
How Much Is It? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
That’s Way Too Logical for Me . . . . . . . . . . . . . . . . . . . . . . . . 198
Summary of Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

C H AP T E R 1 0 So Many Paths…So Little Time (Multiple-Alternative


Selection Structures) . . . . . . . . . . . . . . . . . . 211
Which Way Should I Go? . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
The Fitness Spa Health Club Application . . . . . . . . . . . . . . . . . . . 213
Don’t Be So Sensitive . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
What’s the Next Case on the Docket? . . . . . . . . . . . . . . . . . . . . . 220
Using Select Case in the Fitness Spa Health Club Application . . . . . . . . . . 222
Specifying a Range of Values in a Case Clause’s ExpressionList . . . . . . . . . . 223
Coding the ABC Corporation Application . . . . . . . . . . . . . . . . . . . 224
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

C H AP T E R 1 1 Testing, Testing…1, 2, 3 (Selecting Test Data) . . . . . . 237


Will Your Application Pass the Test? . . . . . . . . . . . . . . . . . . . . . . 238
The Coffee Palace–Version 1 Application . . . . . . . . . . . . . . . . . . . . 238
The Coffee Palace–Version 2 Application . . . . . . . . . . . . . . . . . . . . 241
Stop! This Is a Restricted Area! . . . . . . . . . . . . . . . . . . . . . . . 243
The Shady Hollow Hotel Application . . . . . . . . . . . . . . . . . . . . . . 245
The CD Shop Application . . . . . . . . . . . . . . . . . . . . . . . . . . 247
The Tiger Hotel Application . . . . . . . . . . . . . . . . . . . . . . . . . 250
I Need to Tell You Something . . . . . . . . . . . . . . . . . . . . . . . 251
Just When You Thought It Was Safe . . . . . . . . . . . . . . . . . . . . . 253
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259

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 1 2 How Long Can This Go On? (Pretest Loops) . . . . . . . . . . 261


Over and Over Again . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Do I Need a Loop? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
The Do…Loop Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
Counter Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
viii Cheerleader Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
My Dream Car Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
The Sales Express Application . . . . . . . . . . . . . . . . . . . . . . . . . . 276
The InputBox Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Can I Abbreviate That Assignment Statement? . . . . . . . . . . . . . . . . . . . 283
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288

C H AP T E R 1 3 Do It, Then Ask Permission (Posttest Loops) . . . . . . . . . . 293


Testing After the Fact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
More on the Do…Loop Statement . . . . . . . . . . . . . . . . . . . . . . . . 296
Pseudocode and Flowchart Containing a Posttest Loop . . . . . . . . . . . . . . . 297
The Bouncing Robot Application . . . . . . . . . . . . . . . . . . . . . . . . . 297
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Key Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301

C H AP T E R 1 4 Let Me Count the Ways (Counter-Controlled Loops) . . . . . . . 305


When Will It Stop? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
Spaceship–Version 1 Application . . . . . . . . . . . . . . . . . . . . . . . . 309
Spaceship–Version 2 Application . . . . . . . . . . . . . . . . . . . . . . . . 310
Hey, Turn That Noise Down! . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
The Monthly Payment Calculator Application . . . . . . . . . . . . . . . . . . . . 312
The Financial.Pmt Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
But They Said There Were No Strings Attached . . . . . . . . . . . . . . . . . . 315
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322

C H AP T E R 1 5 I’m on the Inside; You’re on the Outside (Nested Loops) . . . . . 329


One Loop Within Another Loop . . . . . . . . . . . . . . . . . . . . . . . . . . 330
What Time Is It? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
What Do I Owe Each Month? . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
But I Want to Do It a Different Way . . . . . . . . . . . . . . . . . . . . . . . 341
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346

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

C H AP T E R 1 7 Talk to Me (Function Procedures) . . . . . . . . . . . . . 383


What’s the Answer? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Price Calculator Application . . . . . . . . . . . . . . . . . . . . . . . . 387
Revisiting the Concert Tickets Application . . . . . . . . . . . . . . . . . . . 390
Which Way Is Better? . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397

C H AP T E R 1 8 A Ray of Sunshine (One-Dimensional Arrays) . . . . . . . . 403


Let’s Join the Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
You Are Just So One-Dimensional . . . . . . . . . . . . . . . . . . . . . . . 404
Airlines Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Modified Airlines Application . . . . . . . . . . . . . . . . . . . . . . . . 412
Salary Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
States Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425

C H AP T E R 1 9 Parallel and Dynamic Universes (More on


One-Dimensional Arrays) . . . . . . . . . . . . . . . . . 431
We Share the Same Subscripts . . . . . . . . . . . . . . . . . . . . . . . 432
West Coast Emporium Application . . . . . . . . . . . . . . . . . . . . . . 432
Will You Share That with Me? . . . . . . . . . . . . . . . . . . . . . . . . . 436
But I Don’t Know How Many There Are . . . . . . . . . . . . . . . . . . . . . 443
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449

C H AP T E R 2 0 Table Tennis, Anyone? (Two-Dimensional Arrays) . . . . . . 455


Let’s Table That Idea for Now . . . . . . . . . . . . . . . . . . . . . . . . 456
Revisiting the West Coast Emporium Application . . . . . . . . . . . . . . . . . 458
The GetUpperBound Method . . . . . . . . . . . . . . . . . . . . . . . . 461
Calendar Sales Application . . . . . . . . . . . . . . . . . . . . . . . . . 464
Medical Bills Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
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

Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470


Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472

C H AP T E R 2 1 Building Your Own Structure (Structures) . . . . . . . . . . . 479


x Putting the Pieces Together . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
Bonnette Pool & Spa Depot Application . . . . . . . . . . . . . . . . . . . . . . 482
Revisiting the West Coast Emporium Application…Again! . . . . . . . . . . . . . . . 485
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493

C H AP T E R 2 2 I’m Saving for the Future (Sequential Access Files) . . . . . . . 497


Sequential Access Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Write Those Lines of Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Now Read Those Lines of Text . . . . . . . . . . . . . . . . . . . . . . . . . . 502
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511

C H AP T E R 2 3 The String Section (String Manipulation) . . . . . . . . . . . . 515


Working with Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
How Many Characters Are There? . . . . . . . . . . . . . . . . . . . . . . . . . 516
I Need to Fit This in Somewhere . . . . . . . . . . . . . . . . . . . . . . . . . 519
Where Does It Begin? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
I Just Want a Part of It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
The Rearrange Name Application . . . . . . . . . . . . . . . . . . . . . . . . 522
Throw Away Those Characters . . . . . . . . . . . . . . . . . . . . . . . . . . 525
I Like This Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534

C H AP T E R 2 4 I’m Suffering from Information Overload (Access Databases) . . . 539


Keeping Good Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
Connecting…Connecting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
What Fields and Records? . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
It’s a Binding Contract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
Let the Computer Do It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
DataGridView Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
How Does Visual Basic Do It? . . . . . . . . . . . . . . . . . . . . . . . . . . 554
Thank You for Catching My Errors . . . . . . . . . . . . . . . . . . . . . . . 555
The Copy to Output Directory Property . . . . . . . . . . . . . . . . . . . . . . 557
I’ll Use My Own Controls, Thank You . . . . . . . . . . . . . . . . . . . . . . . 559
Coding the Next Record and Previous Record Buttons . . . . . . . . . . . . . . . 561
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
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 2 5 The Missing “LINQ” (Querying a Database) . . . . . . . . . 569
Asking Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570
The Red Dragon Games Application . . . . . . . . . . . . . . . . . . . . . 572
One for All . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580 xi
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582

C H AP T E R 2 6 I Love This Class (Creating a Class) . . . . . . . . . . . . 587


That’s a Real Classy Object . . . . . . . . . . . . . . . . . . . . . . . . . 588
The Bonnette Pool & Spa Depot Application . . . . . . . . . . . . . . . . . . 589
Who Owns That Property? . . . . . . . . . . . . . . . . . . . . . . . . . 591
Behave Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Constructive Behavior Is the Key to Success . . . . . . . . . . . . . . . . . 595
Methods Other than Constructors . . . . . . . . . . . . . . . . . . . . . . 596
Using the Pattern to Create an Object . . . . . . . . . . . . . . . . . . . . . 598
Pool Supplies Application . . . . . . . . . . . . . . . . . . . . . . . . . . 601
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607

C H AP T E R 2 7 Getting “Web-ified” (Web Applications) . . . . . . . . . . 611


Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
Creating a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . 614
Adding the Default.aspx Web Page to the Application . . . . . . . . . . . . . . . 616
What Is Your Title? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
Adding Static Text to a Web Page . . . . . . . . . . . . . . . . . . . . . 618
Viewing a Web Page in Full Screen View . . . . . . . . . . . . . . . . . . . 620
Adding Another Web Page to the Application . . . . . . . . . . . . . . . . . . 621
Adding a Link Button Control to a Web Page . . . . . . . . . . . . . . . . . . 621
Starting a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . 623
Adding an Image to a Web Page . . . . . . . . . . . . . . . . . . . . . . . 625
Closing and Opening an Existing Web Application . . . . . . . . . . . . . . . . 627
I Want to Move Somewhere Else . . . . . . . . . . . . . . . . . . . . . . . 628
Dynamic Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630
Coding the Submit Button’s Click Event Procedure . . . . . . . . . . . . . . . . 632
Can You Validate This? . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639

A PP E N D I X A Data Types . . . . . . . . . . . . . . . . . . . . . . 645


A PP E N D I X B Answers to Mini-Quizzes and TRY THIS Exercises . . . . . Online
Index . . . . . . . . . . . . . . . . . . . . . . . . . 647

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.

Organization and Coverage


Clearly Visual Basic: Programming with Microsoft Visual Basic 2012, Third Edition
contains 27 chapters and two appendices. In the chapters, students with no previous
programming experience learn how to analyze a problem specification and then plan and
create an appropriate computer solution. Pseudocode and flowcharts are used to plan the
solution, and desk-check tables are used to verify that the solution is correct before it is
coded. Students code the solutions using the Visual Basic 2012 language, and then desk-
check the code before it is executed. An entire chapter is devoted to teaching students how
to select appropriate test data. By the end of the book, students will have learned how to
write Visual Basic statements such as If…Then…Else, Select Case, Do…Loop, and
For…Next. Students also will learn how to create and manipulate variables, constants,
strings, sequential access files, structures, classes, and arrays. In addition, they will learn how
to connect an application to a Microsoft Access database, and then use Language Integrated
Query (LINQ) to query the database. They also will learn how to create simple Web
applications. The text also introduces students to OOP concepts and terminology. Appendix
A provides a listing of the data types available in Visual Basic. Appendix B, which is available
online at www.cengagebrain.com, contains the answers to the Mini-Quizzes and TRY THIS
Exercises in each chapter.

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 7 Run time errors are now introduced in Chapter 7.

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 16 Chapter 16 now covers the CheckedChanged event procedure.

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.

Using Your Own Computer


To use your own computer to complete the computer activities in this book, you will need the
following:
l A Pentium® 4 processor, 1.6 GHz or higher, personal computer running Microsoft Windows.
This book was written using Microsoft Windows 8, and Quality Assurance tested using
Microsoft Windows 7.
l Either Microsoft Visual Studio 2012 or the Express Editions of Microsoft Visual Studio 2012
(namely, Microsoft Visual Studio Express 2012 for Windows Desktop and Microsoft Visual
Studio Express 2012 for Web) installed on your computer. This book was written and
Quality Assurance tested using Microsoft Visual Studio Professional 2012 and Microsoft
Visual Studio Express 2012 for Web. At the time of this writing, you can download a free
copy of the Express Editions at www.microsoft.com/visualstudio/eng/products/visual-studio-
express-products. If necessary, use the following information when installing the Professional
or Express Editions of the software:

To configure Visual Studio 2012:


1. Start Visual Studio 2012, VS Express for Desktop, or VS Express for Web. If the Choose
Default Environment Settings dialog box appears when you start Visual Studio, select the
Visual Basic Development Settings option.
2. Click TOOLS on the menu bar and then click Options to open the Options dialog box.
Click the Projects and Solutions node. Use the information shown in Figure 3-2 in
Chapter 3 to select and deselect the appropriate check boxes.

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.

Visit Our Web Site


Additional materials designed for this textbook might be available at www.cengagebrain.com.
Search this site for more details.

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)

After studying Chapter 1, you should be able to:

Describe the three control structures


Write simple algorithms using the sequence, selection,
and repetition structures

All Microsoft screenshots used with permission from Microsoft Corporation.

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.

The Sequence Structure


You already are familiar with the sequence structure because you use it each time you follow a
set of directions, in order, from beginning to end. The directions might be a cookie recipe; or,
they might be the MapQuest directions to your favorite restaurant. The directions must be in
the correct order to produce the desired result. A cookie recipe, for example, must produce
edible cookies. The MapQuest directions, on the other hand, must deliver you to your intended
destination. In a computer program, the sequence structure directs the computer to process
the program instructions, one after another, in the order listed in the program. You will find the
sequence structure in every program.
You can observe how the sequence structure works by programming a robotic character named
Harold. Like a computer, Harold has a limited instruction set. In other words, he can understand
only a specific number of instructions, also called commands. For now, you will use only three of
the commands from Harold’s instruction set: walk forward, turn left 90 degrees, and sit down on
the bench. When told to walk forward, Harold takes one complete step forward. In other words,
he moves one of his feet forward one step and then moves his other foot to meet it.
For this first example, Harold is standing outside facing a park bench. The bench is two steps
away from Harold. Your task is to write the instructions, using only the commands that Harold
understands, that direct Harold to sit down on the bench. Figure 1-1 shows the problem
specification along with an illustration of the problem. It also shows five instructions that Harold
must follow to get him from where he is now to his ultimate destination, which is sitting on the
bench. The five instructions are called an algorithm, which is a set of step-by-step instructions
Ch01-Harold that accomplish a task. Harold must follow the instructions in order—in other words, in
Sequence sequence. (You can observe Harold following the algorithm shown in Figure 1-1 by viewing the
video Ch01-Harold Sequence 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.
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

Figure 1-1 An example of the sequence structure


Image by Diane Zak; Created with Reallusion CrazyTalk Animator

The Selection Structure


As with the sequence structure, you already are familiar with the selection structure, also called
the decision structure. The selection structure indicates that a decision needs to be made,
followed by an appropriate action derived from that decision. The decision is based on a
condition that must be evaluated before an action can occur. A condition can evaluate to either
true or false. You use the selection structure every time you drive your car and approach a
railroad crossing. Your decision, as well as the appropriate action, is based on a condition involving
the crossing signals (flashing lights and ringing bells). If the crossing signals are on (true), the
appropriate action is to stop your car before crossing the railroad tracks; otherwise (false), the
appropriate action is to proceed with caution over the railroad tracks. When used in a computer
program, the selection structure alerts the computer that a decision needs to be made based on
some condition, and it provides the appropriate action to take based on the result of that decision.
To observe how the selection structure works, we’ll make a slight change to the problem
specification shown in Figure 1-1. Sometimes Harold’s cat Ginger is sitting on the park bench
and needs to be gently pushed off before Harold can sit down. What changes will need to be
made to the original algorithm from Figure 1-1 as a result of this minor modification? The first
two instructions in the original algorithm position Harold directly in front of the bench; Harold
will still need to follow those instructions. However, before he follows the third instruction,
which is to turn left 90 degrees in preparation for sitting down, Harold will need to make a
decision about Ginger and then take the appropriate action based on the result. More
specifically, he will need to determine whether Ginger is on the bench; if she is on the bench,
then he needs to gently shove her off.
To write an algorithm to accomplish the current task, you need to use three additional
instructions from Harold’s instruction set: if Ginger is on the bench, do this:, end if, and gently

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.

Ginger might or might


not be on the bench

1. walk forward
2. walk forward condition

3. if Ginger is on the bench, do this:


gently shove Ginger off the bench indent
end if
4. turn left 90 degrees
5. turn left 90 degrees
6. sit down on the bench

Figure 1-2 An example of the selection structure


Image by Diane Zak; Created with Reallusion CrazyTalk Animator

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

1. raise right arm


2. shoot at the villain
condition

3. if the villain was hit, do this:


say “Got Him” indent
otherwise, do this:
say “Missed Him” indent
end if
4. lower right arm

Figure 1-3 Another example of the selection structure


Image by Diane Zak; Created with Reallusion CrazyTalk Animator

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.)

The Repetition Structure


The last of the three control structures is the repetition structure. Like the sequence and
selection structures, you already are familiar with the repetition structure. For example,
shampoo bottles typically include the repetition structure in the directions for washing your
hair. Those directions usually tell you to repeat the “apply shampoo to hair,” “lather,” and “rinse”
steps until your hair is clean. When used in a program, the repetition structure directs the
computer to repeat one or more instructions until some condition is met, at which time the

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.
Another Random Document on
Scribd Without Any Related Topics
not have those men shot; I'll not burn the rest of Yslemont; I'll see
that you are conducted to the Dutch frontier unmolested after you
carry out your engagements with me. Will you do it?"

"'If you say you'll do it, ... I'll not have those men
shot'"

Guild met his intent gaze with a gaze as searching:

"What is your daughter's name?"

"Her name is Karen."


"Where am I to find her?"

"Thirty miles out of London at Westheath. She is known there as


Karen Girard."

"What!" said Guild sharply.

"She chose to be so known in her profession."

"Her profession?"

"She has been on the stage—against my wishes. She is preparing


herself further—contrary to my wishes. Until she disassociates herself
from that profession she will not use the name of von Reiter."

Guild nodded slowly: "That is why your daughter is known as


Karen Girard?"

"That is why. She is a young girl—nineteen. She went to school in


her mother's country, Denmark. She imbibed notions there—and,
later, in England among art students and others. It is the well-born
who succumb most easily to nonsense once the discipline is relaxed.
She has had her way in spite of my authority. Now it is time for such
insubordination to cease. I wish to have my daughter back. I cannot
get her. You are—American—to all intents and purposes, and you
would be under no suspicion in England. Your appearance, your
speech, your manners all are above suspicion. You can do this. I
have made up my mind concerning you, and I trust you. Will you go
to England, find my daughter and bring her back to me here; or, if I
am ordered elsewhere, will you escort her to my country place in
Silesia which is called Rehthal?"

"Suppose I do not find her? Suppose I fail?"

"You will return here and report to me."

"If I fail and I return here and report my failure, does that mean
the execution of the gentlemen in the drawing-room yonder?"
"It does."

"And the destruction of Yslemont?"

"Absolutely."

"And—" the young man smiled—"incidentally it means my own


execution, does it not?"

"It does."

They gazed at each other with intense interest.

"Under such circumstances do you think I'll come back if I am not


successful?" inquired the younger man.

"I am satisfied that you will return if you say you will."

"Return to face my own execution?" repeated Guild, curiously.


"You believe that of me?—of a man about whom you know nothing—
a man who"—his animated features suddenly darkened and he
caught his breath a moment, then—"a man who considers your
nation a barbarous one, your rulers barbarians, your war
inexcusable, your invasion of this land the vilest example of
treachery and dishonour that the world has ever witnessed—you still
believe that such a man might consider himself bound to return here
if unsuccessful and face one of your murdering platoons? Do you?"
he repeated, the slightest intonation of violence beginning to ring in
the undertones of his voice.

Von Reiter's dry, blond features had become greyer and more set.
His light blue eyes never left the other; behind their pale, steady
scrutiny he seemed to be considering every word.

He drew in his breath, slowly; his very thin lips receded for a
moment, then the fixed tranquillity returned.
"We Germans," he said drily, "care nothing for what Europe may
think of us or say about us. Perhaps we are vandals, Goths, Huns—
whatever you call them. Perhaps we are barbarians. I think we are!
For we mean to scour the old world clean of its rottenness—cauterize
it, cut out the old sores of a worn-out civilization, scrape its surface
clean of the parasite nations. ... And, if fire be necessary to burn out
the last traces—" His light blue eyes glimmered a very reflection of
the word—"then let fire pass. It has passed, before—God's Angel of
the Flaming Sword has returned again to lead us! What is a cathedral
or two—or pictures or foolish statues—or a million lives? Yes, if you
choose, we are barbarians. And we intend to plow under the
accumulated decay of the whole world, and burn up its rubbish and
found our new world on virgin earth. Yes, we are barbarians. And
our Emperor is a barbarian. And God, who creates with one hand
and destroys with the other—God—autocrat of material creation,
inexorable Over-Lord of ultimate material annihilation, is the greatest
barbarian of all! Under His orders we are moving. In His name we
annihilate! Amen!"

A dead silence ensued. And after it had lasted a little while the tall
Prussian lifted his hand absently to his mustache and touched it
caressingly.

"I am satisfied, whatever your opinion may be of me or of my


people, that you will return if you say you will, successful or
otherwise. I promise you immunity if you return with my daughter; I
promise you a wall and a file of men if you return unsuccessful. But,
in either event, I am satisfied that you will return. Will you go?"

"Yes," said Guild, thoughtfully. They stood for a moment longer,


the young man gazing absently out of the window toward the
menacing smoke pall which was increasing above Yslemont.

"You promise not to burn the remainder of the village?" he asked,


turning to look at von Reiter.

"I promise not to burn it if you keep your promise."


"I'll try.... And the Burgomaster, notary, magistrate, and the others
are to be released?"

"If you do what I ask."

"Very well. It's worth trying for. Give me my credentials."

"You need no written ones. Letters are unsafe. You will go to my


daughter, who has leased a small cottage at Westheath. You will say
to her that you come from me; that the question which she was to
decide on the first of November must be decided sooner, and that
when she arrives at Rehthal in Silesia she is to telegraph me through
the General Staff of her arrival. If I can obtain leave to go to Silesia I
shall do so. If not, I shall telegraph my instructions to her."

"Will that be sufficient for your daughter to place her confidence


in a man absolutely strange to her and accompany that man on a
journey of several days?" asked Guild, slightly astonished.

"Not quite sufficient," said von Reiter, his dry, blond visage slightly
relaxing.

He drew a rather plain ring from his bony finger: "See if you can
wear that," he said. "Does it fit you?"

Guild tried it on. "Well enough."

"Is there any danger of its slipping off?"

Guild tried it on another finger, which it fitted snugly.

"It looks like any other plain gold ring," he remarked.

"Her name is engraved inside."

"Karen?"

"Karen."
There came a short pause. Then: "Do you know London?" asked
von Reiter.

"Passably."

"Oh! You are likely to require a touring car. You'll find it difficult to
get. May I recommend the Edmeston Agency? It's about the only
agency, now, where any gasoline at all is obtainable. The Edmeston
Agency. I use it when I am in London. Ask for Mr. Louis Grätz."

After a moment he added, "My chauffeur brought your luggage,


rücksack, stick, and so forth, from Yslemont. You will go to the
enemies' lines south of Ostend in my car. One of my aides-de-camp
will accompany you and show you a letter of instructions before
delivering you to the enemies' flag of truce. You will read the letter,
learn it by heart, and return it to my aide, Captain von Klipper.

"There is a bedroom above. Go up there. Food will be sent you.


Get what sleep you can, because you are to leave at sunrise. Is this
arrangement agreeable to you—Monsieur le Comte de Gueldres?"

"Perfectly, General Baron von Reiter."

"Also. Then I have the honour to wish you good night and a
pleasant sleep."

"I thank you and I have the honour to wish you the same," said
Guild, bowing pleasantly.

General von Reiter stood aside and saluted with stiff courtesy as
the young man passed out.

A few moments later a regimental band somewhere along the


Yslemont highway began to play "Polen Blut."

If blood were the theme, they ought to have played it well


enough.
CHAPTER III
TIPPERARY
At noon on the following day Kervyn Guild wrote to his friend
Darrel:

Dear Harry:

Instead of joining you on the Black Erenz for the late August
trout fishing I am obliged to go elsewhere.

I have had a most unpleasant experience, and it is not ended,


and I do not yet know what the outcome is to be.

From the fact that I have not dated this letter it will be
evident to you that I am not permitted to do so. Also you will
understand that I have been caught somewhere in the war zone
and that is why the name of the place from which I am writing
you is omitted—by request.

We have halted for luncheon at a wayside inn—the gentleman


who is kind enough to accompany me, and I—and I have
obtained this benevolent gentleman's authorization to write you
whatever I please as long as I do NOT

1st. Tell you where I am going.

2d. Tell you where I am.

3d. Tell you anything else that does not suit him.

And he isn't a censor at that; he is just a very efficient, polite,


and rather good-looking German officer serving as aide on the
staff of a certain German major-general.

Day before yesterday, after luncheon, I was playing a quiet


game of chess with the Burgomaster of a certain Belgian village,
and was taking a last look before setting out for Luxembourg on
foot, rücksack, stick, and all, when—well, circumstances over
which I had no control interrupted the game of chess. It was
white to go and mate in three moves. The Burgomaster was
playing black. I had him, Harry. Too bad, because he was the
best player in—well in that neighbourhood. I opened with a
Lopez and he replied most irregularly. It certainly was
interesting. I am sorry that I couldn't mate him and analyze the
game with him. However, thank Heaven, I did announce mate in
three moves, and the old gentleman was still defiantly studying
the situation. I admit he refused to resign.

I left that village toward evening in a large, grey automobile. I


and the gentleman who still accompanies me slept fairly well
that night, considering the fact that a town was on fire all
around us.

In the morning we made slow progress in our automobile.


Roads and fields were greenish grey with troops—a vast horde
of them possessed the valleys; they enveloped the hills like fog-
banks turning the whole world grey—infantry, artillery,
cuirassiers, Uhlans, hussars—all mist colour from helmet to heel
—and so are their waggons and guns and caissons and traction-
engines and motor-cycles and armoured cars and aeroplanes.

The latter are magnificent in an artistic sense—perfect


replicas of giant pigeon-hawks, circling, planing, sheering the air
or sailing high, majestic as a very lammergeier, fierce, relentless,
terrible.

My efficient companion who is reading this letter over my


shoulder as I write it, and who has condescended to permit a
ghost of a smile to mitigate, now and then, the youthful
seriousness of his countenance, is not likely to object when I say
to you that what I have seen of the German army on the march
is astoundingly impressive.

(He smiles again very boyishly and says he doesn't object.)

Order, precision, a knowledge of the country absolutely


unhesitating marks its progress. There is much singing in the
infantry ranks. The men march well, their physique is fine, the
cavalry are superbly mounted, the guns—(He shakes his head,
so never mind the guns.)

Their regimental bands are wonderful. It is a sheer delight to


listen to them. They play everything from "Polen Blut" and
"Sari," to Sousa, "Tannhäuser," and "A Hot Time," but I haven't
yet heard "Tipperary." (He seems puzzled at this, but does not
object.) I expect shortly to hear a band playing it. (I have to
explain to my efficient companion that "Tipperary" is a tune
which ought to take Berlin and Vienna by storm when they hear
it. It takes Berlin and Vienna to really appreciate good music. He
agrees with me.)

Yesterday we passed a convoy of prisoners, some were kilted.


I was not permitted to speak to them—but, Oh, those wistful
eyes of Scottish blue! I guess they understood, for they got all
the tobacco I had left. (My companion is doubtful about this, but
finally shrugs his shoulders.)

There is an awesome noise going on beyond us in—well in a


certain direction. I think that all the artillery ever made is
producing it. There's practically no smoke visible against the
clear blue August sky—nothing to see at all except the feathery
cotton fleece of shrapnel appearing, expanding, vanishing over a
hill on the horizon, and two aeroplanes circling high like a pair of
mated hawks.
And all the while this earth-rocking diapason continues more
terrible, more majestic than any real thunder I ever heard.

We have had luncheon and are going on. He drank five quarts
of Belgian beer! I am permitted a few minutes more and he
orders the sixth quart. This is what I have to say:

In case anything should go wrong with me give the enclosed


note to my mother. Please see to it that everything I have goes
to her. My will is in my box in our safe at the office. It is all quite
clear. There should be no trouble.

I expressed my trunk to your care in Luxembourg. You wrote


me that you had received it and placed it in storage to await my
leisurely arrival. In case of accident to me send it to my mother.

About the business, my share in any deals now on should go


to my brother. After that if you care to take George in when he
comes out of Harvard it would gratify his mother and me.

He's all to the good, you know. But don't do this if the
business does not warrant it. Don't do it out of sentiment, Harry.
If he promises to be of use, and if you have no other man in
view, and if, as I say, business conditions warrant such an
association with a view to eventual partnership, then if you care
to take in George it will be all right.

He has sufficient capital, as you know. He lacks only the


business experience. And he is intelligent and quick and it won't
take him long.

But if you prefer somebody else don't hesitate. George is


perfectly able to take care of his mother and himself.

This is all, I think. I'm sorry about the August fishing on the
Black Erenz. It is a lovely stream and full of trout. All
Luxembourg is lovely; it is a story-book country—a real land of
romance. I wish I might have seen it again. Never were such
forests, such silver streams, such golden glades, such wild-
flowers—never such hills, such meadows, such skies.

Well—if I come back to you, I come back. If not—good-bye,


old fellow—with all it implies between friends of many years.

Say to your kind friends, the Courlands, who so graciously


invited you to bring me with you to Lesse Forest, that I shall not
be able to accept their delightful hospitality, and that my inability
to do so must remain to me a regret as long as I live. (These
guns are thundering enough to crack the very sky! I really wish I
could hear some band playing "Tipperary.")

Good-bye for a while—or indefinitely. Good luck to you.

Kervyn Guild.

"Is that quite acceptable to you?" asked Guild of the young


Death's Head hussar beside him.

"Quite acceptable," replied the officer politely. "But what is there


remarkable in anybody drinking six quarts of beer?"

Guild laughed: "Here is the note that I desire to enclose with it, if
I may do so." And he wrote:

Dearest:

You must not grieve too much. You have George. It could not
be avoided, honourably. He and I are good Americans; we are,
perhaps, something else, too. But what the Book of Gold holds it
never releases; what is written there is never expunged. George
must do what I did when the time comes. I would have done
more—was meaning to—was on my way. Destiny has ordered it
otherwise.

While I live I think always of you. And it shall be so until the


last.
This letter is to be sent to you by Harry Darrel only in the
event of my death.

There's a good chance for me. But if things go wrong, then,


good-bye, dearest.

Kervyn.

P. S.

Tell George that it's up to him, now.

K.

He held out the letter cheerfully to the hussar, but the latter had
read it, and he merely nodded in respectful silence. So Guild folded
it, sealed it in an envelope, wrote on it, "For my Mother in case of my
death," and inclosed it in his letter to Darrel.

"Any time you are ready now," he said, rising from the little
enameled iron table under the arbour.

The hussar rose, clanking, and set a whistle to his lips. Then,
turning: "I shall have yet one more glass of beer," he said blandly,
but his eyes twinkled.

The grey car rolled up in a few moments. Over it at a vast height


something soared in hawk-like circles. It may have been a hawk.
There was no telling at such a height.

So they drove off again amid the world-shaking din of the guns
paralleling the allied lines toward the west. Ostend lay somewhere in
that direction, the channel flowed beyond; beyond that crouched
England—where bands were playing "Tipperary"—and where,
perhaps, a young girl was listening to that new battle song of which
the young hussar beside him had never even heard.
As the grey car hummed westward over the Belgian road, Guild
thought of these things while the whole world about him was
shaking with the earthquake of the guns.

"Karen," he repeated under his breath, "Karen Girard."

After a while sentinels began to halt them every few rods. The
chauffeur unrolled two white flags and set them in sockets on either
side of the hood. The hussar beside him produced a letter from his
grey despatch-pouch.

"General von Reiter's orders," he said briefly. "You are to read


them now and return the letter to me before the enemies'
parlementaire answers our flag."

Guild took the envelope, tore it open, and read:

Orders received since our interview make it impossible for me


to tell you where to find me on your return.

My country place in Silesia is apparently out of the question at


present as a residence for the person you are expected to bring
back with you. The inclosed clipping from a Danish newspaper
will explain why. Therefore you will sail from London on
Wednesday or Sunday, taking a Holland liner. You will land at
Amsterdam, go by rail through Utrecht, Helmond, Halen,
Maastricht. You will be expected there. If I am not there you will
remain over night.

If you return from your journey alone and unsuccessful you


will surrender yourself as prisoner to the nearest German post
and ask the officer in charge to telegraph me.

If you return successful you shall be permitted at Eijsden to


continue your journey with the person you bring with you,
across the Luxembourg border to Trois Fontaines, which is just
beyond the Grand Duchy frontier; and you shall then deliver the
person in question to the housekeeper of the hunting lodge,
Marie Bergner. The lodge is called Quellenheim, and it belongs
to me. If I am not there you must remain there over night. In
the morning if you do not hear from me, you are at liberty to go
where you please, and your engagements vis-à-vis to me are
cancelled.

von Reiter, Maj-Gen'l.

The inclosed newspaper clipping had been translated into French


and written out in long-hand. The translation read as follows:

Russia's invasion of East Prussia, Posen and Silesia has sent a


wave of panic over the eastern provinces of the German Empire,
if reports from Copenhagen and Stockholm are to be credited.
These reports are chiefly significant as indicating that the
Russian advance is progressing more rapidly than has been
asserted even by despatches from Petrograd.

A correspondent of the Daily Telegraph reports from


Stockholm that the whole of eastern Germany is upset by the
menace of Cossack raids. He hears that a diplomatic despatch
from Vienna contains information that the civilian inhabitants of
Koenigsberg, East Prussia, and Breslau, in Silesia, are
abandoning their homes and that only the military will remain in
these strongholds.

From Copenhagen it is reported, allegedly from German


sources, that Silesia expects devastation by fire and sword and
that the wealthy Prussian landholders, whose immense estates
cover Silesia, are leading the exodus toward the west. The
military authorities have done everything possible to check the
panic, fearing its hurtful influence on Germany's prospects, but
have been unable to reassure the inhabitants. Many of these
have seen bands of Cossacks who have penetrated a few miles
over the border and their warnings have spread like a forest fire.
For a long while the young man studied the letter, reading and re-
reading it, until, closing his eyes, he could repeat it word for word.

And when he was letter perfect he nodded and handed back the
letter to the hussar, who pouched it.

A moment later the car ran in among a horde of mounted Uhlans,


and one of their officers came galloping up alongside of the machine.

He and the hussar whispered together for a few minutes, then an


Uhlan was summoned, a white cloth tied to his lance-shaft, and away
he went on his powerful horse, the white flag snapping in the wind.
Behind him cantered an Uhlan trumpeter.

Toward sunset the grey automobile rolled west out into open
country. A vast flat plain stretched to the horizon, where the sunset
flamed scarlet and rose.

But it was almost dusk before from somewhere across the plain
came the faint strains of military music.

The hussar's immature mustache bristled. "British!" he remarked.


"Gott in Himmel, what barbarous music!"

Guild said nothing. They were playing "Tipperary."

And now, through the late rays of the afterglow, an Uhlan


trumpeter, sitting his horse on the road ahead, set his trumpet to his
lips and sounded the parley again. Far, silvery, from the misty
southwest, a British bugle answered.

Guild strained his eyes. Nothing moved on the plain. But, at a nod
to the chauffeur from the hussar, the great grey automobile rolled
forward, the two Uhlans walking their horses on either side.

Suddenly, east and west as far as the eye could see, trenches in
endless parallels cut the plain, swarming with myriads and myriads of
men in misty grey.
The next moment the hussar had passed a black silk handkerchief
over Guild's eyes and was tying it rather tightly.
CHAPTER IV
BAD DREAMS
His first night in London was like a bad dream to him. Lying half
awake on his bed, doggedly, tenaciously awaiting the sleep he
needed, at intervals even on its vision-haunted borderland, but never
drifting across it, he remained always darkly conscious of his errand
and of his sinister predicament.

The ineffaceable scenes of the last three days obsessed him; his
mind seemed to be unable to free itself. The quieter he lay, the more
grimly determined he became that sleep should blot out these tragic
memories for a few hours at least, the more bewildering grew the
confusion in his haunted mind. Continually new details were evoked
by his treacherous and insurgent memory—trifles terrible in their
minor significance—the frightened boy against the wall snivelling
against his ragged shirt-sleeve—the sprawling attitudes of the dead
men in the dusty grass—and how, after a few moments, a mangled
arm moved, blindly groping—and what quieted it.

Incidents, the petty details of sounds, of odours, of things


irrelevant, multiplied and possessed him—the thin gold-rimmed
spectacles on the Burgomaster's nose and the honest, incredulous
eyes which gazed through them at him when he announced
checkmate in three moves.

Did that tranquil episode happen years ago in another and calmer
life?—or a few hours ago in this?

He heard again the startling and ominous sounds of raiding


cavalry even before they had become visible in the misty street—the
flat slapping gallop of the Uhlan's horses on the paved way, the
tinkling clash of broken glass. Again the thick, sour, animal-like
stench of the unwashed infantry seemed to assail and sicken him to
the verge of faintness; and, half awake, he saw a world of fog set
thick with human faces utterly detached from limbs and bodies—
thousands and thousands of faces watching him out of thousands
and thousands of little pig-like eyes.

His nerves finally drove him into motion and he swung himself out
of bed and walked to the window.

His hotel was the Berkeley, and he looked out across Piccadilly
into a silent, sad, unlighted city of shadows. Only a single line of
lighted lamps outlined the broad thoroughfare. Crimson sparks
twinkled here and there—the lights of cabs.

The great darkened Ritz towered opposite, Devonshire House


squatted behind its grilles and shadowy walls on the right, and
beyond the great dark thoroughfare stretched away into the night,
melancholy, deserted save for the slight stirring of a policeman here
and there or the passage of an automobile running in silence without
lights.

He had been standing by the window for ten minutes or so, a


lighted cigarette between his lips, both hands dropped into the
pocket of his pyjamas, when he became aware of a slight sound—a
very slight one—behind him.

He turned around and his eyes fell upon the knob of the door.
Whether or not it was turning he could not determine in the dusk of
the room. The only light in it came through his windows from the
starry August night-sky.

After a moment he walked toward the door, bare-footed across


the velvet carpet, halted, fixed his eyes on the door knob.

After a moment it began to turn again, almost imperceptibly. And,


in him, every over-wrought nerve tightened to its full tension till he
quivered. Slowly, discreetly, noiselessly the knob continued to turn.
The door was not locked. Presently it began to open, the merest
fraction of an inch at a time; then, abruptly but stealthily, it began to
close again, as though the unseen intruder had caught sight of him,
and Guild stepped forward swiftly and jerked the door wide open.

There was only the darkened hallway there, and a servant with a
tray who said very coolly, "Thanky, sir," and entered the room.

"What-do-you-want?" asked Guild unsteadily.

"You ordered whiskey and soda for eleven o'clock, sir."

"I did not. Why do you try to enter my room without knocking?"

"I understood your orders were not to disturb you but to place the
tray on the night-table beside your bed, sir."

Guild regarded him steadily. The servant, clean-shaven, typical,


encountered the young man's gaze respectfully and with no more
disturbance than seemed natural under the circumstances of a not
unusual blunder.

Guild's nerves relaxed and he drew a deep, quiet breath.

"Somebody has made a mistake," he said. "I ordered nothing.


And, hereafter, anybody coming to my door will knock. Is that plain?"

"Perfectly, sir."

"Have the goodness to make it very plain to the management."

"I'm sorry, sir——"

"You understand, now?"

"Certainly, sir."
"Very well.... And, by the way, who on this corridor is likely to
have ordered that whiskey?"

"Sir?"

"Somebody ordered it, I suppose?"

"Very likely the gentleman next door, sir——"

"All right," said Guild quietly. "Try the door while I stand here and
look on."

"Very good, sir."

With equanimity unimpaired the waiter stepped to the next door


on the corridor, placed his tray flat on the palm of his left hand, and,
with his right hand, began to turn the knob, using, apparently, every
precaution to make no noise.

But he was not successful; the glassware on his tray suddenly


gave out a clear, tinkling clash, and, at the same moment the
bedroom door opened from within and a man in evening dress
appeared dimly framed by the doorway.

"Sorry, sir," said the waiter, "your whiskey, sir——"

He stepped inside the room and the door closed behind him. Guild
quietly waited. Presently the waiter reappeared without the tray.

"Come here," motioned Guild.

The waiter said: "Yes, sir," in a natural voice. Doubtless the man
next door could hear it, too.

Guild, annoyed, lowered his own voice: "Who is the gentleman in


the next room?"

"A Mr. Vane, sir."


"From where?"

"I don't know, sir."

"What is he, English?"

"Yes sir, I believe so."

"You don't happen to know his business, do you?"

"No, sir."

"I ask—it's merely curiosity. Wait a moment." He turned, picked up


a sovereign from a heap of coins on his night-table and gave it to the
waiter.

"No need to repeat to anybody what I have asked you."

"Oh, no, sir——"

"All right. Listen very attentively to what I tell you. When I arrived
here this afternoon I desired the management to hire for my use a
powerful and absolutely reliable touring car and a chauffeur. I
mentioned the Edmeston Agency and a Mr. Louis Grätz.

"Half an hour later the management informed me that they had


secured such a car for me from Mr. Louis Grätz at the Edmeston
Agency; that I was permitted sufficient gasoline to take me from
here to Westheath, back here again, and then to the docks of the
Holland Steamship Company next Sunday.

"I've changed my mind. Tomorrow is Wednesday and a steamer


sails from Fresh Wharf for Amsterdam. Tell the management that I'll
take that steamer and that I want them to telephone the Edmeston
Agency to have the car here at six o'clock tomorrow morning."

"Very good, sir."


"Go down and tell them now. Ask them to confirm the change of
orders by telephone."

"Very good, sir."

A quarter of an hour later the bell tinkled in his room: "Are you
there, sir? Thank you, sir. The car is to be here at six o'clock. What
time would you breakfast, Mr. Guild?"

"Five. Have it served here, please."

"Thank you, sir."

Guild went back to bed. Another detail bothered him now. If the
man next door had ordered whiskey and soda for eleven, to be
placed on the night-table beside the bed, why was he up and
dressed and ready to open the door when the jingle of glassware
awaited him?

Still there might be various natural explanations. Guild thought of


several, but none of them suited him.

He began to feel dull and sleepy. That is the last he remembered,


except that his sleep was disturbed by vaguely menacing dreams,
until he awoke in the grey light of early morning, scarcely refreshed,
and heard the waiter knocking. He rose, unlocked his door, and let
him in with his tray.

When the waiter went out again Guild relocked his door, turned on
his bath, took it red hot and then icy. And, thoroughly awake, now,
he returned to his room, breakfasted, dressed, rang for his account,
and a few minutes later descended in the lift to find his car and
chauffeur waiting, and the tall, many-medalled porter at salute by
the door.

"Westheath," he said to the smiling chauffeur. "Go as fast as you


dare and by the direct route."
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like