100% found this document useful (4 votes)
57 views

Full download Programming with Microsoft Visual Basic 2015 7th Edition Diane Zak pdf docx

Diane

Uploaded by

fonsafartas
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 (4 votes)
57 views

Full download Programming with Microsoft Visual Basic 2015 7th Edition Diane Zak pdf docx

Diane

Uploaded by

fonsafartas
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/ 55

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Programming with Microsoft Visual Basic 2015 7th


Edition Diane Zak

https://textbookfull.com/product/programming-with-microsoft-
visual-basic-2015-7th-edition-diane-zak/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Programming with Microsoft Visual Basic 2017 Diane Zak

https://textbookfull.com/product/programming-with-microsoft-visual-
basic-2017-diane-zak/

textboxfull.com

Visual Basic in easy steps Covers Visual Basic 2015 4th


Edition Mike Mcgrath

https://textbookfull.com/product/visual-basic-in-easy-steps-covers-
visual-basic-2015-4th-edition-mike-mcgrath/

textboxfull.com

Practical Microsoft Visual Studio 2015 1st Edition Peter


Ritchie (Auth.)

https://textbookfull.com/product/practical-microsoft-visual-
studio-2015-1st-edition-peter-ritchie-auth/

textboxfull.com

SQL Server Database Programming With Visual Basic NET


Concepts Designs and Implementations Ying Bai

https://textbookfull.com/product/sql-server-database-programming-with-
visual-basic-net-concepts-designs-and-implementations-ying-bai/

textboxfull.com
Starting Out With Visual Basic (8th Edition) Tony Gaddis

https://textbookfull.com/product/starting-out-with-visual-basic-8th-
edition-tony-gaddis/

textboxfull.com

Microsoft Visual Basic 2017 for Windows, Web, and Database


Applications: Comprehensive 1st Edition Corinne Hoisington

https://textbookfull.com/product/microsoft-visual-basic-2017-for-
windows-web-and-database-applications-comprehensive-1st-edition-
corinne-hoisington/
textboxfull.com

Visual Basic For Kids A Step by Step Computer Programming


Tutorial Philip Conrod

https://textbookfull.com/product/visual-basic-for-kids-a-step-by-step-
computer-programming-tutorial-philip-conrod/

textboxfull.com

Essentials of Modern Business Statistics with Microsoft


Excel 7th Edition David Anderson

https://textbookfull.com/product/essentials-of-modern-business-
statistics-with-microsoft-excel-7th-edition-david-anderson/

textboxfull.com

Beginning C 7 Programming with Visual Studio 2017 1st


Edition Benjamin Perkins

https://textbookfull.com/product/beginning-c-7-programming-with-
visual-studio-2017-1st-edition-benjamin-perkins/

textboxfull.com
PROGRAMMING WITH
MICROSOFT® VISUAL BASIC® 2015

Copyright 2016 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 2016 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.
Seventh Edition

PROGRAMMING
WITH MICROSOFT®
VISUAL BASIC® 2015

DIANE ZAK

Australia • Brazil • Mexico • Singapore • United Kingdom • United States

Copyright 2016 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.
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.

Important Notice: Media content referenced within the product description or the product
text may not be available in the eBook version.

Copyright 2016 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.
Programming with Microsoft® Visual Basic® © 2016 Cengage Learning
2015, Seventh Edition
WCN: 02-200-203
Diane Zak
Product Director: Kathleen McMahon ALL RIGHTS RESERVED. No part of this work covered by the copyright
herein may be reproduced, transmitted, stored or used in any form or by
Product Team Manager: Kristin McNary any means graphic, electronic, or mechanical, including but not limited to
Senior Product Manager: Jim Gish photocopying, recording, scanning, digitizing, taping, Web distribution,
Senior Content Developer: Alyssa Pratt information networks, or information storage and retrieval systems, except
as permitted under Section 107 or 108 of the 1976 United States Copyright
Product Assistant: Abigail Pufpaff
Act, without the prior written permission of the publisher.
Marketing Manager: Eric LaScola
Senior Production Director:
For product information and technology assistance, contact us at
Wendy Troeger Cengage Learning Customer & Sales Support, 1-800-354-9706
Production Director: Patty Stephan For permission to use material from this text or product, submit all
Senior Content Project Manager: requests online at www.cengage.com/permissions
Jennifer K. Feltri-George Further ­permissions ­questions can be emailed to
[email protected]
Managing Art Director: Jack Pendleton
Cover image(s):
Library of Congress Control Number: 2015940168
© Rudchenko Liliia/Shutterstock.com
ISBN: 978-1-285-86026-8
Unless otherwise noted all screenshots are
Cengage Learning
courtesy of Microsoft Corporation
20 Channel Center Street
Open Clip art source: OpenClipArt Boston, MA 02210
USA

Cengage Learning is a leading provider of customized learning solutions


with employees residing in nearly 40 different countries and sales in more
than 125 countries around the world. Find your local representative at
www.cengage.com

Cengage Learning products are represented in Canada by


Nelson Education, Ltd.

For your course and learning solutions, visit www.cengage.com


Purchase any of our products at your local college store or at our
preferred online store www.cengagebrain.com
Notice to the Reader
Publisher does not warrant or guarantee any of the products described herein or
perform any independent analysis in connection with any of the product informa-
tion contained herein. Publisher does not assume, and expressly disclaims, any
obligation to obtain and include information other than that provided to it by the
manufacturer. The reader is expressly warned to consider and adopt all safety
­precautions that might be indicated by the activities described herein and to avoid
all potential hazards. By following the instructions contained herein, the reader
­willingly assumes all risks in connection with such instructions. The publisher
makes no representations or warranties of any kind, including but not limited to,
the ­warranties of ­fitness for particular purpose or merchantability, nor are any such
­representations implied with respect to the material set forth herein, and the
­publisher takes no responsibility with respect to such material. The publisher shall
not be liable for any special, consequential, or exemplary damages resulting, in
whole or part, from the readers’ use of, or reliance upon, this material.

Printed in the United States of America


Print Number: 01 Print Year: 2016

Copyright 2016 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.
v

Brief Contents

Pref ace . . . . . . . . . . . . . . . . . . . . . . . . . xv i i
Read T h is B ef o re You Begi n . . . . . . . . . . . . . . . . xxi i
O verview An In t ro du ct io n to Programmi ng . . . . . . . . . . . . . . . 1
Chapter 1 An In t ro du ct io n to V i sual Basi c 2 0 1 5 . . . . . . . . . . . . . 9
Chapter 2 Des ig n in g Applicati ons . . . . . . . . . . . . . . . . . . 59
Chapter 3 U s in g Var iables and Constants . . . . . . . . . . . . . . . 111
Chapter 4 T h e Select io n Structure . . . . . . . . . . . . . . . . . . 179
Chapter 5 M o re o n t h e Selecti on Structure . . . . . . . . . . . . . . 247
Chapter 6 T h e Repet it io n Structure . . . . . . . . . . . . . . . . . 315
Chapter 7 Su b an d F u n ct ion Procedures . . . . . . . . . . . . . . . 389
Chapter 8 St r in g M an ipu lati on . . . . . . . . . . . . . . . . . . . . 449
Chapter 9 Ar r ays . . . . . . . . . . . . . . . . . . . . . . . . . 499
Chapter 10 St r u ct u res an d Sequenti al Access Fi l es . . . . . . . . . . . 559
Chapter 11 Clas s es an d Obj ects . . . . . . . . . . . . . . . . . . . 609
Chapter 12 Web Applicat io ns . . . . . . . . . . . . . . . . . . . . . 671
Chapter 13 Wo r k in g w it h Access Databases and LI NQ . . . . . . . . . . 723
Chapter 14 Acces s Dat abases and SQL . . . . . . . . . . . . . . . . 777
A ppendix A F in din g an d F ixing Program Errors . . . . . . . . . . . . . 821
A ppendix B GU I Des ig n Gu idel i nes . . . . . . . . . . . . . . . . . . 839
A ppendix C V is u al B as ic Co nv ersi on Functi ons . . . . . . . . . . . . . 845
A ppendix D V is u al B as ic 201 5 Cheat Sheet . . . . . . . . . . . . . . 847
A ppendix E Cas e Pro ject s . . . . . . . . . . . . . . . . . . . . . . 865
A ppendix F M u lt iple F o r m s and Di al og Box es . . . . . . . . . . . . O nl i ne
Index . . . . . . . . . . . . . . . . . . . . . . . . . . 869

Copyright 2016 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.
vi

Contents

P ref ace . . . . . . . . . . . . . . . . . . . . . . . . . xvi i


R ead T h is B ef o re Yo u Begi n . . . . . . . . . . . . . . . . xxi i

OVERVIEW A n In t ro du ct io n t o Pro grammi ng . . . . . . . . . . . . . . . 1


Programming a Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
The Programmer’s Job . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Employment Opportunities . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Visual Basic 2015 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
A Visual Basic 2015 Demonstration . . . . . . . . . . . . . . . . . . . . . . . 4
Using the Chapters Effectively . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

C HAPTER 1 A n In t ro du ct io n t o V is ual Basi c 2 0 1 5 . . . . . . . . . . . . . 9


L ESS ON A The Splash Screen Application . . . . . . . . . . . . . . . . . . . . . 11
Managing the Windows in the IDE . . . . . . . . . . . . . . . . . . . . . . . 14
The Windows Form Designer Window . . . . . . . . . . . . . . . . . . . . . . 15
The Solution Explorer Window . . . . . . . . . . . . . . . . . . . . . . . . . 16
The Properties Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Properties of a Windows Form . . . . . . . . . . . . . . . . . . . . . . . . . . 19
The Name Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
The Text Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
The StartPosition Property . . . . . . . . . . . . . . . . . . . . . . . . . . 20
The Font Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
The Size Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Setting and Restoring a Property’s Value . . . . . . . . . . . . . . . . . . . . . 21
Saving a Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Closing the Current Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Opening an Existing Solution . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Exiting Visual Studio 2015 . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

LESSON B The Toolbox W indow . . . . . . . . . . . . . . . . . . . . . . . . . . 28


The Label Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Setting the Text Property . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Setting the Location Property . . . . . . . . . . . . . . . . . . . . . . . . . 31

Copyright 2016 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.
vii
 

Changing a Property for Multiple Controls . . . . . . . . . . . . . . . . . . . . 31


Using the Format Menu’s Order Option . . . . . . . . . . . . . . . . . . . . . 32
The PictureBox Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Using the Format Menu to Align and Size . . . . . . . . . . . . . . . . . . . . 35
The Button Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Starting and Ending an Application . . . . . . . . . . . . . . . . . . . . . . . . 36
The Code Editor Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
The Me.Close() Instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

LESSON C Using the Timer Tool . . . . . . . . . . . . . . . . . . . . . . . . . . 48


Setting the FormBorderStyle Property . . . . . . . . . . . . . . . . . . . . . . 50
The MinimizeBox, MaximizeBox, and ControlBox Properties . . . . . . . . . . . . 50
Printing the Application’s Code and Interface . . . . . . . . . . . . . . . . . . . 51
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

CHAPTER 2 Des ig n in g Applicati ons . . . . . . . . . . . . . . . . . . 59


L ESS ON A Creating an Object-Oriented Application . . . . . . . . . . . . . . . . . 62
Planning an Object-Oriented Application . . . . . . . . . . . . . . . . . . . . . 62
Identifying the Application’s Tasks . . . . . . . . . . . . . . . . . . . . . . . 63
Identifying the Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Identifying the Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Drawing a Sketch of the User Interface . . . . . . . . . . . . . . . . . . . . . 66
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

L ESSON B Building the User Inter face . . . . . . . . . . . . . . . . . . . . . . . 72


Including Graphics in the User Interface . . . . . . . . . . . . . . . . . . . . 73
Selecting Fonts for the Interface . . . . . . . . . . . . . . . . . . . . . . . . 73
Adding Color to the Interface . . . . . . . . . . . . . . . . . . . . . . . . . 74
The BorderStyle, AutoSize, and TextAlign Properties . . . . . . . . . . . . . . . 75
Adding a Text Box to the Form . . . . . . . . . . . . . . . . . . . . . . . . . 76
Locking the Controls on a Form . . . . . . . . . . . . . . . . . . . . . . . . . 77
Assigning Access Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Controlling the Tab Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

Copyright 2016 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.
viii
Contents 

L ESS ON C Coding the Application . . . . . . . . . . . . . . . . . . . . . . . . . 86


Using Pseudocode to Plan a Procedure . . . . . . . . . . . . . . . . . . . . . 87
Using a Flowchart to Plan a Procedure . . . . . . . . . . . . . . . . . . . . . 88
Coding the btnClear_Click Procedure . . . . . . . . . . . . . . . . . . . . . . . 89
Assigning a Value to a Property During Run Time . . . . . . . . . . . . . . . . 90
Using the Focus Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Internally Documenting the Program Code . . . . . . . . . . . . . . . . . . . 92
Coding the btnPrint_Click Procedure . . . . . . . . . . . . . . . . . . . . . . . 93
Showing and Hiding a Control . . . . . . . . . . . . . . . . . . . . . . . . . 94
Writing Arithmetic Expressions . . . . . . . . . . . . . . . . . . . . . . . . . 95
Coding the btnCalc_Click Procedure . . . . . . . . . . . . . . . . . . . . . . . 97
The Val Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
The Format Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Testing and Debugging the Application . . . . . . . . . . . . . . . . . . . . . .101
Assembling the Documentation . . . . . . . . . . . . . . . . . . . . . . . . . 103
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .107
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

CHAPTER 3 U s in g Var iables an d Constants . . . . . . . . . . . . . . . 111


L ESS ON A Using Variables to Store Information . . . . . . . . . . . . . . . . . . 114
Selecting a Data Type for a Variable . . . . . . . . . . . . . . . . . . . . . .114
Selecting a Name for a Variable . . . . . . . . . . . . . . . . . . . . . . . .116
Declaring a Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Assigning Data to an Existing Variable . . . . . . . . . . . . . . . . . . . . . .118
The TryParse Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . .119
The Convert Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
The Scope and Lifetime of a Variable . . . . . . . . . . . . . . . . . . . . . . .123
Variables with Procedure Scope . . . . . . . . . . . . . . . . . . . . . . . .123
Variables with Class Scope . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Static Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Named Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Option Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133
Option Explicit and Option Infer . . . . . . . . . . . . . . . . . . . . . . . . 133
Option Strict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .138
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140

LESSON B Modifying the Meyer’s Purp le Bakery Application . . . . . . . . . . . . 144


Modifying the Calculate Button’s Code . . . . . . . . . . . . . . . . . . . . . .145
Using the ToString Method to Format Numbers . . . . . . . . . . . . . . . . . .152
Concatenating Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
The InputBox Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
The ControlChars.NewLine Constant . . . . . . . . . . . . . . . . . . . . . . .158
Designating a Default Button . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .162

Copyright 2016 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.
ix
 

Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .162


Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .163
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

LESSON C Modifying the Load and Click Event Procedures . . . . . . . . . . . . . 167


Coding the TextChanged Event Procedure . . . . . . . . . . . . . . . . . . . . 170
Associating a Procedure with Different Objects and Events . . . . . . . . . . . . .170
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .175
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

CHAPTER 4 T h e Select io n Structure . . . . . . . . . . . . . . . . . . 179


L ESS ON A Making Decisions in a Program . . . . . . . . . . . . . . . . . . . . 182
Flowcharting a Selection Structure . . . . . . . . . . . . . . . . . . . . . . . .185
Coding Selection Structures in Visual Basic . . . . . . . . . . . . . . . . . . . .187
Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189
Using Comparison Operators: Swapping Numeric Values . . . . . . . . . . . . .191
Using Comparison Operators: Displaying Net Income or Loss . . . . . . . . . . .194
Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Using the Truth Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Comparing Strings Containing One or More Letters . . . . . . . . . . . . . . . .203
Converting a String to Uppercase or Lowercase . . . . . . . . . . . . . . . . . .205
Using the ToUpper and ToLower Methods: Displaying a Message . . . . . . . . . 206
Summary of Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . .208
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .209
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .211
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .213

LESSON B Creating the Treeline Resor t Application . . . . . . . . . . . . . . . . 216


Adding a Group Box to the Form . . . . . . . . . . . . . . . . . . . . . . . .216
Coding the Treeline Resort Application . . . . . . . . . . . . . . . . . . . . . .218
Coding the btnCalc Control’s Click Event Procedure . . . . . . . . . . . . . . .219
The MessageBox.Show Method . . . . . . . . . . . . . . . . . . . . . . . . . 222
Completing the btnCalc_Click Procedure . . . . . . . . . . . . . . . . . . . . .226
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .229
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .230
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .230
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

L ESSON C Coding the KeyPress Event Procedures . . . . . . . . . . . . . . . . 233


Coding the Enter Event Procedures . . . . . . . . . . . . . . . . . . . . . . . 235
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .239
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .239
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .240
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241

Copyright 2016 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.
x
Contents 

C HAPTER 5 M ore o n t h e Select io n Structure . . . . . . . . . . . . . . 247


L ESS ON A Nested Selection Structures . . . . . . . . . . . . . . . . . . . . . 250
Flowcharting a Nested Selection Structure . . . . . . . . . . . . . . . . . . . .252
Coding a Nested Selection Structure . . . . . . . . . . . . . . . . . . . . . . .255
Logic Errors in Selection Structures . . . . . . . . . . . . . . . . . . . . . . .257
First Logic Error: Using a Compound Condition Rather than a Nested
Selection Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . .260
Second Logic Error: Reversing the Outer and Nested Decisions . . . . . . . . . .261
Third Logic Error: Using an Unnecessary Nested Selection Structure . . . . . . . 262
Fourth Logic Error: Including an Unnecessary Comparison in a Condition . . . . . 263
Multiple-Alternative Selection Structures . . . . . . . . . . . . . . . . . . . . .264
The Select Case Statement . . . . . . . . . . . . . . . . . . . . . . . . . . .267
Specifying a Range of Values in a Case Clause . . . . . . . . . . . . . . . . . 269
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .272
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .272
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .275

LESSON B Modifying the Treeline Resor t Application . . . . . . . . . . . . . . . . 280


Adding a Radio Button to the Interface . . . . . . . . . . . . . . . . . . . . .282
Adding a Check Box to the Interface . . . . . . . . . . . . . . . . . . . . . .283
Modifying the Calculate Button’s Code . . . . . . . . . . . . . . . . . . . . . .285
Comparing Boolean Values . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Modifying the ClearLabels Procedure . . . . . . . . . . . . . . . . . . . . . . .291
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .294
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .295
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .295
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296

LESSON C Using the TryParse Method for Data Validation . . . . . . . . . . . . . 300


Generating Random Integers . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Completing the Roll ‘Em Game Application . . . . . . . . . . . . . . . . . . . . 306
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .309
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .309
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .309
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

CHAPTER 6 T h e Repet it io n St r u ct u re . . . . . . . . . . . . . . . . . 315


L ESS ON A Repeating Program Instructions . . . . . . . . . . . . . . . . . . . . 317
The Projected Sales Application . . . . . . . . . . . . . . . . . . . . . . . . .320
The Do...Loop Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . .323
Coding the Modified Projected Sales Application . . . . . . . . . . . . . . . . .325
Counters and Accumulators . . . . . . . . . . . . . . . . . . . . . . . . . . .328
The Addition Application . . . . . . . . . . . . . . . . . . . . . . . . . . . .330
Arithmetic Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . 333
The For...Next Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . .335
A Different Version of the Projected Sales Application . . . . . . . . . . . . . .337
Comparing the For...Next and Do...Loop Statements . . . . . . . . . . . . . . .340
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .340

Copyright 2016 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.
xi
 

Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341


Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .342
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .345

LESSON B Creating the Monthly Payment Application . . . . . . . . . . . . . . . 350


Including a List Box in an Interface . . . . . . . . . . . . . . . . . . . . . . . .351
Adding Items to a List Box . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Clearing the Items from a List Box . . . . . . . . . . . . . . . . . . . . . . .353
The Sorted Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Coding the Monthly Payment Application . . . . . . . . . . . . . . . . . . . . .355
The SelectedItem and SelectedIndex Properties . . . . . . . . . . . . . . . . .356
The SelectedValueChanged and SelectedIndexChanged Events . . . . . . . . . .358
Coding the Calculate Button’s Click Event Procedure . . . . . . . . . . . . . . .358
The Financial.Pmt Method . . . . . . . . . . . . . . . . . . . . . . . . . . . .359
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .363
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .364
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .364
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365

LESSON C The Electric Bill Application . . . . . . . . . . . . . . . . . . . . . 371


Nested Repetition Structures . . . . . . . . . . . . . . . . . . . . . . . . . . 376
The Refresh and Sleep Methods . . . . . . . . . . . . . . . . . . . . . . . . .378
Trixie at the Diner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
The Savings Account Application . . . . . . . . . . . . . . . . . . . . . . . .380
A Caution About Real Numbers . . . . . . . . . . . . . . . . . . . . . . . . .382
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .385
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .385
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .385
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386

CHAPTER 7 Su b an d F u n ct ion Procedures . . . . . . . . . . . . . . . 389


L ESS ON A Sub Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
Passing Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Passing Variables by Value . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Passing Variables by Reference . . . . . . . . . . . . . . . . . . . . . . . . 397
Function Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .404
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .412
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .413
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .416

L ESSON B Including a Combo Box in an Inter face . . . . . . . . . . . . . . . . . 420


Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .424
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .425
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .425
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426

L ESSON C Creating the Cerruti Company Application . . . . . . . . . . . . . . . 428


Coding the FormClosing Event Procedure . . . . . . . . . . . . . . . . . . . . .429

Copyright 2016 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.
xii
Contents 

Coding the btnCalc_Click Procedure . . . . . . . . . . . . . . . . . . . . . . .431


Creating the GetFwt Function . . . . . . . . . . . . . . . . . . . . . . . . . 433
Completing the btnCalc_Click Procedure . . . . . . . . . . . . . . . . . . . . .437
Rounding Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .437
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .444
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .445
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .445
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445

C HAPTER 8 S t r in g M an ipu lat io n . . . . . . . . . . . . . . . . . . . 449


L ESS ON A Working with Strings . . . . . . . . . . . . . . . . . . . . . . . . . 452
Determining the Number of Characters in a String . . . . . . . . . . . . . . . . .452
Removing Characters from a String . . . . . . . . . . . . . . . . . . . . . . . 453
The Product ID Application . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Inserting Characters in a String . . . . . . . . . . . . . . . . . . . . . . . . .455
Aligning the Characters in a String . . . . . . . . . . . . . . . . . . . . . . .456
The Net Pay Application . . . . . . . . . . . . . . . . . . . . . . . . . . . .457
Searching a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .458
The City and State Application . . . . . . . . . . . . . . . . . . . . . . . . .460
Accessing the Characters in a String . . . . . . . . . . . . . . . . . . . . . . .461
The Rearrange Name Application . . . . . . . . . . . . . . . . . . . . . . . .462
Using Pattern Matching to Compare Strings . . . . . . . . . . . . . . . . . . . .464
Modifying the Product ID Application . . . . . . . . . . . . . . . . . . . . . . .466
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .468
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .469
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .472

LESSON B Adding a Menu to a Form . . . . . . . . . . . . . . . . . . . . . . . 475


Assigning Shortcut Keys to Menu Items . . . . . . . . . . . . . . . . . . . . .478
Coding the Exit Menu Item . . . . . . . . . . . . . . . . . . . . . . . . . . .480
Coding the txtLetter Control’s KeyPress Event . . . . . . . . . . . . . . . . . .480
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .481
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .481
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .481
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482

LESSON C Completing the Pizza Game Application . . . . . . . . . . . . . . . . 483


Coding the File Menu’s New Game Option . . . . . . . . . . . . . . . . . . . . .484
Completing the Check Button’s Click Event Procedure . . . . . . . . . . . . . .487
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .493
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .494
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .494
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495

CHAPTER 9 A rr ays . . . . . . . . . . . . . . . . . . . . . . . . . 499


L ESS ON A Ar rays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
One-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . .502
Declaring a One-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . .502

Copyright 2016 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.
xiii
 

Storing Data in a One-Dimensional Array . . . . . . . . . . . . . . . . . . . . 504


Determining the Number of Elements in a One-Dimensional Array . . . . . . . . .505
Determining the Highest Subscript in a One-Dimensional Array . . . . . . . . . . 505
Traversing a One-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . 506
The For Each...Next Statement . . . . . . . . . . . . . . . . . . . . . . . . . 507
Calculating the Average Stock Price . . . . . . . . . . . . . . . . . . . . . . .508
Finding the Highest Value . . . . . . . . . . . . . . . . . . . . . . . . . . . .511
Sorting a One-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . . . .515
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .517
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .518
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .521

LESS ON B Arrays and Collections . . . . . . . . . . . . . . . . . . . . . . . . 525


Accumulator and Counter Arrays . . . . . . . . . . . . . . . . . . . . . . . . .528
Parallel One-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . .532
The Die Tracker Application . . . . . . . . . . . . . . . . . . . . . . . . . . .536
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .540
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .540
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .541
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541

LESS ON C Two-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . 544


Traversing a Two-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . 547
Totaling the Values Stored in a Two-Dimensional Array . . . . . . . . . . . . . . .548
Searching a Two-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . . 550
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .553
Lesson C Key Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .554
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .554
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555

CHAPTER 10 St r u ct u res an d Sequenti al Access Fi l es . . . . . . . . . . . 559


L ESS ON A Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
Declaring and Using a Structure Variable . . . . . . . . . . . . . . . . . . . . .563
Passing a Structure Variable to a Procedure . . . . . . . . . . . . . . . . . . . 564
Creating an Array of Structure Variables . . . . . . . . . . . . . . . . . . . . .568
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .573
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .573
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .574

LESSON B Sequential Access Files . . . . . . . . . . . . . . . . . . . . . . . 578


Writing Data to a Sequential Access File . . . . . . . . . . . . . . . . . . . . .578
Closing an Output Sequential Access File . . . . . . . . . . . . . . . . . . . . .581
Reading Data from a Sequential Access File . . . . . . . . . . . . . . . . . . . 582
Closing an Input Sequential Access File . . . . . . . . . . . . . . . . . . . . . 586
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .589
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .589
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .590
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591

Copyright 2016 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.
xiv
Contents 

L ESS ON C Coding the eBook Collection Application . . . . . . . . . . . . . . . . 594


Coding the frmMain_Load Procedure . . . . . . . . . . . . . . . . . . . . . . .595
Coding the btnAdd_Click Procedure . . . . . . . . . . . . . . . . . . . . . . . 597
Aligning Columns of Information . . . . . . . . . . . . . . . . . . . . . . . . .598
Coding the btnRemove_Click Procedure . . . . . . . . . . . . . . . . . . . . . 600
Coding the frmMain_FormClosing Procedure . . . . . . . . . . . . . . . . . . . 601
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .605
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .605
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .606
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606

CHAPTER 11 C las s es an d Object s . . . . . . . . . . . . . . . . . . . 609


L ESS ON A Object-Oriented Programming Terminology . . . . . . . . . . . . . . . 612
Creating a Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .613
Example 1—A Class That Contains Public Variables Only . . . . . . . . . . . . . .614
Example 2—A Class That Contains Private Variables, Public Properties, and Methods . 618
Private Variables and Property Procedures . . . . . . . . . . . . . . . . . . . 620
Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .623
Methods Other than Constructors . . . . . . . . . . . . . . . . . . . . . . . 625
Coding the Sunnyside Decks Application . . . . . . . . . . . . . . . . . . . . 626
Example 3—A Class That Contains a Parameterized Constructor . . . . . . . . . .629
Example 4—Reusing a Class . . . . . . . . . . . . . . . . . . . . . . . . . . 633
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .636
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .638
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .639

LESSON B Example 5—A Class That Contains a ReadOnly Property . . . . . . . . . . . . . 644


Example 6—A Class That Contains Auto-Implemented Properties . . . . . . . . . .649
Example 7—A Class That Contains Overloaded Methods . . . . . . . . . . . . . .651
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .657
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .658
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .658
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658

LESSON C Example 8—Using a Base Class and a Derived Class . . . . . . . . . . . 662


Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .668
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .668
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .668
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669

CHAPTER 12 We b Applicat io n s . . . . . . . . . . . . . . . . . . . . 671


L ESS ON A Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . 673
Adding the Default.aspx Web Page to the Application . . . . . . . . . . . . . . . 677
Including a Title on a Web Page . . . . . . . . . . . . . . . . . . . . . . . . 679
Adding Static Text to a Web Page . . . . . . . . . . . . . . . . . . . . . . . 679
Adding Another Web Page to the Application . . . . . . . . . . . . . . . . . . . 681
Adding a Hyperlink Control to a Web Page . . . . . . . . . . . . . . . . . . . . 681

Copyright 2016 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.
xv
 

Starting a Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 683


Adding an Image to a Web Page . . . . . . . . . . . . . . . . . . . . . . . . .685
Closing and Opening an Existing Web Application . . . . . . . . . . . . . . . . .687
Repositioning a Control on a Web Page . . . . . . . . . . . . . . . . . . . . . .688
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .689
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .691
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .692

LESSON B Dynamic Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . 695


Coding the Submit Button’s Click Event Procedure . . . . . . . . . . . . . . . . .699
Validating User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .701
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .704
Lesson B Key Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .705
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .705
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705

LESS ON C Creating the Satellite Radio Application . . . . . . . . . . . . . . . . 709


Using the RadioButtonList Tool . . . . . . . . . . . . . . . . . . . . . . . . .710
Using the CheckBox Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . 711
Coding the Calculate Button’s Click Event Procedure . . . . . . . . . . . . . . . 712
Clearing the Previous Subscription Costs . . . . . . . . . . . . . . . . . . . . .715
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .717
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .718
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .718
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719

CHAPTER 13 Wo r k in g w it h Access Databases and LI NQ . . . . . . . . . . 723


L ESS ON A Database Terminology . . . . . . . . . . . . . . . . . . . . . . . . 726
Connecting an Application to a Microsoft Access Database . . . . . . . . . . . . .728
Previewing the Contents of a Dataset . . . . . . . . . . . . . . . . . . . . . .731
Binding the Objects in a Dataset . . . . . . . . . . . . . . . . . . . . . . . . .732
Having the Computer Create a Bound Control . . . . . . . . . . . . . . . . . .733
The DataGridView Control . . . . . . . . . . . . . . . . . . . . . . . . . . .736
Visual Basic Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739
Handling Errors in the Code . . . . . . . . . . . . . . . . . . . . . . . . . .740
The Copy to Output Directory Property . . . . . . . . . . . . . . . . . . . . . .743
Binding to an Existing Control . . . . . . . . . . . . . . . . . . . . . . . . . .744
Coding the Next Record and Previous Record Buttons . . . . . . . . . . . . . . .747
Formatting the Data Displayed in a Bound Label Control . . . . . . . . . . . . . .748
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .749
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .751
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .752

LESSON B Creating a Query . . . . . . . . . . . . . . . . . . . . . . . . . . 754


Customizing a BindingNavigator Control . . . . . . . . . . . . . . . . . . . . . 758
Using the LINQ Aggregate Operators . . . . . . . . . . . . . . . . . . . . . . .760
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .763
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .763

Copyright 2016 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.
xvi
Contents 

Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .764


Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765

LESSON C Completing the Games Galore Application . . . . . . . . . . . . . . . 767


Coding the Games Galore Application . . . . . . . . . . . . . . . . . . . . . . 769
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .771
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .771
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .771
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773

CHAPTER 14 A c ces s Dat abas es an d SQL . . . . . . . . . . . . . . . . 777


L ESS ON A Adding Records to a Dataset . . . . . . . . . . . . . . . . . . . . . 780
Sorting the Records in a Dataset . . . . . . . . . . . . . . . . . . . . . . . . 785
Deleting Records from a Dataset . . . . . . . . . . . . . . . . . . . . . . . . 786
Lesson A Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .790
Lesson A Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791
Lesson A Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .791
Lesson A Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .792

LESSON B Structured Query Language . . . . . . . . . . . . . . . . . . . . . . 794


The SELECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . .794
Creating a Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .796
Lesson B Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .801
Lesson B Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .801
Lesson B Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .802
Lesson B Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803

LESSON C Parameter Queries . . . . . . . . . . . . . . . . . . . . . . . . . 805


Saving a Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .807
Invoking a Query from Code . . . . . . . . . . . . . . . . . . . . . . . . . . .809
The INSERT and DELETE Statements . . . . . . . . . . . . . . . . . . . . . . .811
Lesson C Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .818
Lesson C Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .819
Lesson C Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . .819
Lesson C Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 820

Appendix A F in din g an d F ixin g Pro gram Errors . . . . . . . . . . . . . 821

A ppendix B GUI Des ig n Gu idelin es . . . . . . . . . . . . . . . . . . 839

APPENDIX C V is u al B as ic Co n ver s ion Functi ons . . . . . . . . . . . . . 845

APPENDIX D V i s u al B as ic 2012 Ch eat Sheet . . . . . . . . . . . . . . 847

APPENDIX E C as e Pro ject s . . . . . . . . . . . . . . . . . . . . . . 865

APPENDIX F M ult iple F o r m s an d Dial og Box es . . . . . . . . . . . . On l i ne

I n dex . . . . . . . . . . . . . . . . . . . . . . . . . . 869

Copyright 2016 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.
xvii

Preface

Programming with Microsoft Visual Basic 2015, Seventh Edition uses Visual Basic 2015, an
object-oriented language, to teach programming concepts. This book is designed for a beginning
programming course. However, it assumes students are familiar with basic Windows skills and
file management.

Organization and Coverage


Programming with Microsoft Visual Basic 2015, Seventh Edition contains an Overview and 14
chapters that present hands-on instruction; it also contains five appendices (A through E).
An additional appendix (Appendix F) covering multiple-form applications and the FontDialog,
ColorDialog, and TabControl tools is available online at CengageBrain.com.
In the chapters, students with no previous programming experience learn how to plan and create
their own interactive Windows applications. GUI design skills, OOP concepts, and planning
tools (such as TOE charts, pseudocode, and flowcharts) are emphasized throughout the book.
The chapters show students how to work with objects and write Visual Basic statements such as
If...Then...Else, Select Case, Do...Loop, For...Next, and For Each...Next. Students also learn how
to create and manipulate variables, constants, strings, sequential access files, structures, classes,
and arrays. Chapter 12 shows students how to create both static and dynamic Web applications.
In Chapter 13, students learn how to connect an application to a Microsoft Access database,
and then use Language-Integrated Query (LINQ) to query the database. Chapter 14 continues
the coverage of databases, introducing the student to more advanced concepts and Structured
Query Language (SQL).
Appendix A, which can be covered after Chapter 3, teaches students how to locate and correct
errors in their code. The appendix shows students how to step through their code and also how
to create breakpoints. Appendix B recaps the GUI design guidelines mentioned in the chapters,
and Appendix C lists the Visual Basic conversion functions. The Visual Basic 2015 Cheat Sheet
contained in Appendix D summarizes important concepts covered in the chapters, such as the
syntax of statements, methods, and so on. The Cheat Sheet provides a convenient place for
students to locate the information they need as they are creating and coding their applications.
Appendix E contains Case Projects that can be assigned after completing specific chapters in
the book.

Approach
Programming with Microsoft Visual Basic 2015, Seventh Edition teaches programming concepts
using a task-driven rather than a command-driven approach. By working through the chapters,
which are each motivated by a realistic case, students learn how to develop applications they
are likely to encounter in the workplace. This is much more effective than memorizing a list of
commands out of context. The book motivates students by demonstrating why they need to
learn the concepts and skills covered in each chapter.

Copyright 2016 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.
xviii
P r e fa c e Organization and Coverage

Features
Programming with Microsoft Visual Basic 2015, Seventh Edition is an exceptional textbook
because it also includes the following features:
READ THIS BEFORE YOU BEGIN This section is consistent with Cengage Learning’s
unequaled 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 instructors save time and eliminate unnecessary aggravation.
YOU DO IT! BOXES These boxes provide simple applications that allow students to
demonstrate their understanding of a concept before moving on to the next concept. The YOU
DO IT! boxes are located almost exclusively in Lesson A of each chapter.
VISUAL STUDIO 2015 METHODS The book focuses on Visual Studio 2015 methods rather
than on Visual Basic functions. Exceptions to this are the Val and Format functions, which are
introduced in Chapter 2. These functions are covered in the book simply because it is likely that
students will encounter them in existing Visual Basic programs. However, in Chapter 3, the
student is taught to use the TryParse method and the Convert class methods rather than the
Val function. Also in Chapter 3, the Format function is replaced with the ToString method.
OPTION STATEMENTS All programs include the Option Explicit, Option Strict, and Option
Infer statements.
START HERE ARROWS These arrows indicate the beginning of a tutorial steps section in
the book.
DATABASES, LINQ, AND SQL The book includes two chapters (Chapters 13 and 14) on
databases. LINQ is covered in Chapter 13. SQL is covered in Chapter 14.
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.
CHAPTER CASES Each chapter begins with a programming-related problem that students
could reasonably expect to encounter in business, followed by a demonstration of an application
that could be used to solve the problem. Showing the students the completed application before
they learn how to create it is motivational and instructionally sound. By allowing the students to
see the type of application they will be able to create after completing the chapter, the students
will be more motivated to learn because they can see how the programming concepts they are
about to learn can be used and, therefore, why the concepts are important.
LESSONS Each chapter is divided into three lessons—A, B, and C. Lesson A introduces
the programming concepts that will be used in the completed application. The concepts are
illustrated with code examples and sample applications. The user interface for each sample
application is provided to the student. Also provided are tutorial-style steps that guide the
student on coding, running, and testing the application. Each sample application allows the
student to observe how the current concept can be used before the next concept is introduced.
In Lessons B and/or C, the student creates the application required to solve the problem
specified in the Chapter Case.
APPENDICES Appendix A, which can be covered after Chapter 3, teaches students how to locate
and correct errors (syntax, logic, and run time) in their code. The appendix shows
students how to step through their code and also how to create breakpoints. Appendix B
summarizes the GUI design guidelines taught in the chapters, making it easier for the student to
follow the guidelines when designing an application’s interface. Appendix C lists the Visual Basic

Copyright 2016 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.
xix
Organization and Coverage 

conversion functions. Appendix D contains a Cheat Sheet that summarizes important concepts
covered in the chapters, such as the syntax of statements, methods, and so on. The Cheat Sheet
provides a convenient place for students to locate the information they need as they are creating and
coding their applications. Appendix E contains Case Projects that can be assigned after completing
specific chapters in the book. Appendix F, which is available online at CengageBrain.com, covers
multiple-form applications and the FontDialog, ColorDialog, and TabControl tools.
GUI DESIGN TIP BOXES The GUI DESIGN TIP boxes contain guidelines and
recommendations for designing applications that follow Windows standards. Appendix B
provides a summary of the GUI design guidelines covered in the chapters.
TIP These notes provide additional information about the current concept. Examples
include alternative ways of writing statements or performing tasks, as well as warnings
about common mistakes made when using a particular command and reminders of related
concepts learned in previous chapters.
SUMMARY Each lesson contains a Summary section that recaps the concepts covered in
the lesson.
KEY TERMS Following the Summary section in each lesson is a listing of the key terms
introduced throughout the lesson, along with their definitions.
REVIEW QUESTIONS Each lesson contains Review Questions designed to test a student’s
understanding of the lesson’s concepts.
EXERCISES The Review Questions in each lesson are followed by Exercises, which provide
students with additional practice of the skills and concepts they learned in the lesson. The
Exercises are designated as INTRODUCTORY, INTERMEDIATE, ADVANCED, DISCOVERY,
and SWAT THE BUGS. The DISCOVERY Exercises encourage students to challenge and
independently develop their own programming skills while exploring the capabilities of Visual
Basic 2015. The SWAT THE BUGS Exercises provide an opportunity for students to detect and
correct errors in an application’s code.

New to This Edition!


U PDATED 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. The videos have been revised from the previous edition and are
available via the optional MindTap for this text.
NEW CHAPTER CASES, EXAMPLES, APPLICATIONS, REVIEW QUESTIONS, AND
EXERCISES The chapters contain new Chapter Cases, code examples, sample applications,
Review Questions, and Exercises.
Chapters 2, 5, 6, and 12 The Visible property is now introduced in Chapter 2 rather than
in Chapter 5. Coverage of the priming and update reads was moved from Chapter 6’s Lesson A
to Chapter 6’s Lesson B. The topics covered in Chapter 6’s Lesson B are now covered in its
Lesson C and vice versa. The Financial.Pmt function is covered in Chapter 6’s Lesson B. Chapter 12,
which covers Web applications, has been revamped.

Copyright 2016 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.
xx
P r e fa c e MindTap

Steps and Figures


The tutorial-style steps in the book assume you are using Microsoft Visual Studio Ultimate 2015
and a system running Microsoft Windows 8. The figures in the book reflect how your screen will
look if you are using a Microsoft Windows 8 system. Your screen may appear slightly different in
some instances if you are using a different version of Microsoft Windows.

Instructor Resources
The following teaching tools are available for download at our Instructor Companion Site.
Simply search for this text at sso.cengage.com. An instructor login is required.
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.
TEST BANK Cengage Learning Testing Powered by Cognero is a flexible, online system that
allows you to:
•• author, edit, and manage test bank content from multiple Cengage Learning solutions
•• create multiple test versions in an instant
•• deliver tests from your LMS, your classroom or wherever you want

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.
SOLUTION FILES Solutions to the Lesson applications and the end-of-lesson Review
Questions and Exercises are provided.
DATA FILES Data Files are necessary for completing the computer activities in this book.
Data Files can also be downloaded by students at CengageBrain.com.

MindTap
MindTap is a personalized teaching experience with relevant assignments that guide students to
analyze, apply, and improve thinking, allowing you to measure skills and outcomes with ease.
•• Personalized Teaching: Becomes yours with a Learning Path that is built with key student
objectives. Control what students see and when they see it. Use it as-is or match to your
syllabus exactly–hide, rearrange, add and create your own content.
•• Guide Students: A unique learning path of relevant readings, multimedia and activities
that move students up the learning taxonomy from basic knowledge and comprehension to
analysis and application.
•• Promote Better Outcomes: Empower instructors and motivate students with analytics
and reports that provide a snapshot of class progress, time in course, engagement and
completion rates.

The MindTap for Programming with Microsoft Visual Basic 2015 includes videos, study tools,
and interactive quizzing, all integrated into a full eReader that contains the full content from
the printed text.

Copyright 2016 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.
xxi
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 Alyssa Pratt (Senior Content Developer), Heidi Aguiar
(Full Service Project Manager), Serge Palladino and John Freitas (Quality Assurance), Jennifer
Feltri-George (Senior Content Project Manager), and the compositors at GEX Publishing
Services. Thank you for your support, enthusiasm, patience, and hard work. Last, but certainly
not least, I want to thank the following reviewers for their invaluable ideas and comments: Cliff
Brozo, Monroe College; Anthony Cameron, Fayetteville Technical Community College, and
Tatyana Feofilaktova, ASA College. And a special thank you to Sally Douglas (College of Central
Florida) for suggesting the YOU DO IT! boxes several editions ago.
Diane Zak

Copyright 2016 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.
xxii

Read This Before


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 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 VB2015 folder. The files for Chapter 1 are stored in the VB2015\Chap01 folder.
Similarly, the files for Chapter 2 are stored in the VB2015\Chap02 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 steps 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:
•• 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 10.
•• Either Microsoft Visual Studio Ultimate 2015 or Visual Studio Community Edition
installed on your computer. This book was written and Quality Assurance tested using
Microsoft Visual Studio Ultimate 2015. At the time of this writing, you can download a
free copy of the Community Edition at https://www.visualstudio.com/en-us/downloads/
visual-studio-2015-downloads-vs.

To control the display of filename extensions in Windows 8:


1. Press and hold down the Windows logo key on your keyboard as you tap the letter x.
Click Control Panel, click Appearance and Personalization, click Folder Options, and
then click the View tab.
2. Deselect the Hide extensions for known file types check box to show the extensions; or,
select the check box to hide them. Click the OK button, and then close the Appearance
and Personalization window.

Copyright 2016 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.
xxiii
Technical Information 

To always display the underlined letters (called access keys)


in Windows 8:
1. Press and hold down the Windows logo key on your keyboard as you tap the letter x.
Click Control Panel, and then click Appearance and Personalization.
2. In the Ease of Access Center section, click Turn on easy access keys, and then select
the Underline keyboard shortcuts and access keys check box. Click the OK button, and
then close the Ease of Access Center window.

To start and configure Visual Studio to match the figures and tutorial
steps in this book:
1. Use the steps on Page 11 to start Visual Studio.
2. Use the steps on Pages 12 and 13 to configure Visual Studio.

To install Microsoft Visual Basic PowerPacks 12.0:


1. Locate the vb_vbpowerpacks.exe file, which is contained in the VB2015\PowerPacks
folder. Right-click the filename and then click Run as administrator. Click the Yes button.
2. Select the “I agree to the License Terms and Privacy Policy.” check box. Either select
or deselect the check box that asks if you want to join the Visual Studio Experience
Improvement program. Click Install.
3. When the “Setup Successful!” message appears, click the Close button.
4. Start Visual Studio. Open the Toolbox window (if necessary) by clicking View on the
menu bar and then clicking Toolbox. Right-click the Toolbox window and then click
Add Tab. Type Visual Basic PowerPacks and press Enter.
5. Right-click the Visual Basic PowerPacks tab, and then click Choose Items. If necessary,
click the .NET Framework Components tab in the Choose Toolbox Items dialog box.
6. In the Filter box, type PowerPacks. You may see one or more entries for the PrintForm
control. Select Version 12’s PrintForm control, as shown in Figure 1. (Although this
book uses only the PrintForm control, you can also select Version 12’s DataRepeater,
LineShape, OvalShape, and RectangleShape controls.)

Copyright 2016 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.
xxiv
Read This Technical Information

7. Click the OK button to close the Choose Toolbox Items dialog box. If the message “The
following controls were successfully added to the toolbox but are not enabled in the
active designer:” appears, click the OK button. The PrintForm control (as well as any
other PowerPacks controls you selected) will not appear in the Toolbox window until
you either create a new Visual Basic application or open an existing one. You will learn
how to perform both of those tasks in Chapter 1.

Figures
The figures in this book reflect how your screen will look if you are using Microsoft Visual
Studio Ultimate 2015 and a Microsoft Windows 8 system. Your screen may appear slightly
different in some instances if you are using another version of either Microsoft Visual Studio or
Microsoft Windows.

Visit Our Web Site


Additional materials designed for this textbook might be available at 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 on the Instructor Companion Site or at CengageBrain.com.
The material in this book was written using Microsoft Visual Studio Ultimate 2015 on a
Microsoft Windows 8 system. It was Quality Assurance tested using Microsoft Visual Studio
Ultimate 2015 on a Microsoft Windows 10 system.

Copyright 2016 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.
OVERVIEW

An Introduction to
Programming

After studying the Overview, you should be able to:

Define the terminology used in programming


Explain the tasks performed by a programmer
Understand the employment opportunities for programmers
and software engineers
Run a Visual Basic 2015 application
Understand how to use the chapters effectively

Copyright 2016 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.
2
OVERVIEW An Introduction to Programming

Programming a Computer
In essence, the word programming means giving a mechanism the directions to accomplish a
task. If you are like most people, you have already programmed several mechanisms, such as
your digital video recorder (DVR), cell phone, or coffee maker. Like these devices, a computer
also is a mechanism that can be programmed.
The directions (typically called instructions) given to a computer are called computer ­programs
or, more simply, programs. The people who write programs are called programmers.
Programmers use a variety of special languages, called programming languages, to
communicate with the computer. Some popular programming languages are Visual Basic, C#,
C++, and Java. In this book, you will use the Visual Basic programming language.

The Programmer’s Job


When a company has a problem that requires a computer solution, typically it is a programmer
who comes to the rescue. The programmer might be an employee of the company; or he or she
might be a freelance programmer, which is a programmer who works on temporary contracts
rather than for a long-term employer.
First the programmer meets with the user, who is the person (or people) responsible for
describing the problem. In many cases, this person will also eventually use the solution.
Depending on the complexity of the problem, multiple programmers may be involved, and
they may need to meet with the user several times. Programming teams often contain subject
matter experts, who may or may not be programmers. For example, an accountant might be
part of a team working on a program that requires accounting expertise. The purpose of the
initial meetings with the user is to determine the exact problem and to agree on a solution.
After the programmer and user agree on the solution, the programmer begins converting
the solution into a computer program. During the conversion phase, the programmer meets
periodically with the user to determine whether the program fulfills the user’s needs and to
Overview-Programmers refine any details of the solution. When the user is satisfied that the program does what he
or she wants it to do, the programmer rigorously tests the program with sample data before
releasing it to the user, who will test it further to verify that it correctly solves the problem. In
many cases, the programmer also provides the user with a manual that explains how to use the
program. As this process indicates, the creation of a good computer solution to a problem—in
other words, the creation of a good program—requires a great deal of interaction between the
programmer and the user.

Employment Opportunities
When searching for a job in computer programming, you will encounter ads for “computer
programmers” as well as for “computer software engineers.” Although job titles and
descriptions vary, computer software engineers typically are responsible for designing an
Overview-Programmer appropriate solution to a user’s problem, while computer programmers are responsible
Qualities for translating the solution into a language that the computer can understand—a process
called coding. Software engineering is a higher-level position that requires the ability to
envision solutions. Using a construction analogy, software engineers are the architects, while
programmers are the carpenters.
Keep in mind that depending on the employer as well as the size and complexity of the user’s
problem, the design and coding tasks may be performed by the same employee, no matter what
his or her job title is. In other words, it is not unusual for a software engineer to code his or her
solution or for a programmer to have designed the solution he or she is coding.

Copyright 2016 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.
3
Visual Basic 2015 

Programmers and software engineers need to have strong problem-solving and analytical skills,
as well as the ability to communicate effectively with team members, end users, and other
nontechnical personnel. Typically, computer software engineers are expected to have at least
a bachelor’s degree in software engineering, computer science, or mathematics, along with
practical work experience, especially in the industry in which they are employed. Computer
programmers usually need at least an associate’s degree in computer science, mathematics, or
information systems, as well as proficiency in one or more programming languages.
Computer programmers and software engineers are employed by companies in almost every
industry, such as telecommunications companies, software publishers, financial institutions,
insurance carriers, educational institutions, and government agencies. The U.S. Bureau of
Labor Statistics predicts that employment of computer software engineers will increase by
22% from 2012 to 2022. The employment of computer programmers, on the other hand,
will increase by 8% over the same period. In addition, consulting opportunities for freelance
programmers and software engineers are expected to increase as companies look for ways to
reduce their payroll expenses.
There is a great deal of competition for programming and software engineering jobs, so
jobseekers need to keep up to date with the latest programming languages and technologies.
A competitive edge may be gained by obtaining vendor-specific or language-specific
certifications, as well as knowledge of a prospective employer’s business. More information
about computer programmers and computer software engineers can be found on the U.S.
Bureau of Labor Statistics Web site at www.bls.gov.

Visual Basic 2015


In this book, you will learn how to create programs, called applications, using the Visual Basic
2015 programming language. Visual Basic 2015 is one of the languages built into Microsoft’s
newest integrated development environment: Visual Studio 2015. An integrated development
environment (IDE) is an environment that contains all of the tools and features you need to
create, run, and test your programs.
Visual Basic 2015 is an object-oriented programming language, which is a language that
allows the programmer to use objects to accomplish a program’s goal. An object is anything that
can be seen, touched, or used. In other words, an object is nearly any thing. The objects in an
object-oriented program can take on many different forms. Programs written for the Windows
environment typically use objects such as check boxes, list boxes, and buttons. A payroll
program, on the other hand, might utilize objects found in the real world, such as a time card
object, an employee object, and a check object.
Every object in an object-oriented program is created from a class, which is a pattern that the
computer uses to create the object. The class contains the instructions that tell the computer
how the object should look and behave. An object created from a class is called an instance of
the class and is said to be instantiated from the class. An analogy involving a cookie cutter and
cookies is often used to describe a class and its objects: The class is the cookie cutter, and the
objects instantiated from the class are the cookies. You will learn more about classes and objects
throughout this book.
You can use Visual Basic to create applications for the Windows environment or for the Web.
A Windows application has a Windows user interface and runs on a personal computer. A user
interface is what the user sees and interacts with while an application is running. Examples
of Windows applications include graphics programs, data-entry systems, and games. A Web
application, on the other hand, has a Web user interface and runs on a server. You access a Web

Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Exploring the Variety of Random
Documents with Different Content
“Oh, I’m on the cross.” He knew that she was “pattering the flash”
for being in thievery; but he answered solemnly:
“Your mother is on the Cross, too, Molly.”
“Poor old thing! I’m sorry for her, but it don’t do her no good for me
to hang there with her.”
He entreated her to go home, and promised that the judge would
free her at his request, but Molly was honest enough to say:
“It wouldn’t work, Mister RoBards. I ain’t built for that life. I’ve
outgrowed it.”
He spoke to the judge, who sent her to the Magdalen Home
instead of to Sing Sing.
But the odor of sanctity was as stifling to Molly’s quivering nostrils
as the smell of new-mown hay, and she broke loose from pious
restraint and returned to her chosen career. She joined destinies with
a young crossman. As she would have put it in her new language,
she became the file of a gonof who was caught by a nab while
frisking a fat of his fawney, his dummy, and his gold thimble. Molly
went on a bender when her chuck was jugged, and a star took her
back to the Magdalen Home.
And of this it seemed to RoBards better to leave Mrs. Lasher in
ignorance than to certify the ghastly truth. He had trouble enough in
store for him within his own precincts.
War, for one thing, shook the nation. President Polk called for men
and money to confirm the annexation of the Texas Republic and to
suppress the Mexican Republic.
With a wife and children to support and the heritage of bills from
his father-in-law to pay, RoBards felt that patriotism was a luxury
beyond his means. But Harry Chalender went out with the first
troops, and by various illegitimate devices managed to worm himself
into the very forefront of danger.
Other sons of important families bribed their way to the zone of
death and won glory or death or both at Cerro Gordo, Chapultepec
and Churubusco. New York had a good laugh over the capture of
General Santa Ana’s wooden leg and the return of the troops was a
glorious holiday.
Harry Chalender had been the second man to enter the gates of
Mexico City and he marched home with “Captain” in front of his
name and his arm in a graceful sling.
When he met Patty he said: “Thank the Lord the Greasers left me
one wing to throw round you.”
He hugged her hard and kissed her, and then wrung the hand of
RoBards, who could hardly attack a wounded hero, or deny him
some luxury after a hard campaign. RoBards saw with dread that his
wife had grown fifteen years younger under the magic of her old
lover’s salute; her cheek was stained with a blush of girlish
confusion.
That night as she dressed for a ball in honor of the soldiers, Patty
begged her husband once more to lend a hand at pulling her corset
laces. When he refused sulkily, she laughed and kissed him with that
long-lost pride in his long-dormant jealousy. But her amusement cost
him dear, and his youth was not restored by hers.
For months his heart seemed to be skewered and toasted like the
meat on the turning spit in the restaurant windows.
And then the word California assumed a vast importance, like a
trumpet call on a stilly afternoon. It advertised a neglected strip of
territory of which Uncle Sam had just relieved the prostrate Mexico.
People said that it was built upon a solid ledge of gold. Much as
RoBards would have liked to be rich, he could not shake off his
chains.
But Harry Chalender joined the Argonauts. His finances were in
need of some heaven-sent bonanza, and he had no scruples against
leaving his creditors in the lurch.
When he called to pay his farewells RoBards chanced to be at
home. He waited with smoldering wrath to resent any effort to salute
Patty’s cheek. The returned soldier had perhaps some license, but
the outbound gold-seeker could be knocked down or kicked on his
way if he presumed.
The always unexpectable Chalender stupefied him by fastening
his eyes not on Patty, but on Immy, and by daring to say:
“You’re just the age, Immy, just the image of your mother when I
first asked her to marry me. The first nugget of gold I find in
California I’ll bring back for our wedding ring.”
This frivolity wrought devastation in RoBards’ soul. It wakened him
for the first time to the fact that his little daughter had stealthily
become a woman. He blenched to see on her cheek the blush that
had returned of late to Patty’s, to see in her eyes a light of enamored
maturity. She was formed for love and ready for it, nubile, capable of
maternity, tempting, tempted.
The shock of discovery filled RoBards with disgust of himself. He
felt faint, and averting his gaze from his daughter, turned to her
mother to see how the blow struck her. Patty had not been so
unaware of Immy’s advance. But her shock was one of jealousy and
of terror at the realization that she was on the way to
grandmotherhood.
RoBards was so hurt for her in her dismay that he could have
sprung at Chalender and beaten him to the floor, crying, “How dare
you cease to flirt with my beautiful wife?”
But this was quite too impossible an impulse to retain for a
moment in his revolted soul. He stood inept and smirked with Patty
and murmured, “Good-by! Good luck!”
They were both pale and distraught when Chalender had gone.
But Immy was rosy and intent.
CHAPTER XXXI

SOMETHING more precious than gold came to light in 1846,


something of more moment to human history than a dozen Mexican
wars—a cure for pain.
It came divinely opportune to Patty’s need, for her next child was
about to tear its way into the world through her flesh suffering from
old lacerations, and she prophesied that she would die of agony and
take back with her into oblivion the boy or girl or both or whatever it
was or they were that she was helplessly manufacturing.
And just then there came to RoBards a letter from a Boston client
stating that a dentist named Morton had discovered a gas that
enabled him to extract a tooth without distress; another surgeon had
removed a tumor from a patient made indifferent with ether; and that
the long deferred godsend would make childbirth peaceable. Patty
sang hosannas to the new worker of miracles.
“1846 is a greater year than 1776—or 1492. That man Morton is a
bigger man than Columbus and there should be a holiday in his
honor. What did the discoverer of America, or the inventor of the
telegraph or anything else, do for the world to compare with the
angel of mercy who put a stop to pain? The Declaration of
Independence!—Independence from what?—taxes and things. But
pain—think of independence from pain! Nothing else counts when
something aches. And the only real happiness is to hurt and get over
it.”
She repeated her enthusiasm to Dr. Chirnside when he happened
in on his pastoral rounds. To her dismay the old clergyman was not
elated, but horrified.
Dr. Chirnside, who opposed everything new as an atheism,
everything amusing as a sin, declared that God decreed pain for his
own inscrutable purposes in his own infinite love. Since Holy Writ
had spoken of a woman crying aloud in travail it would be a sacrilege
to deny her that privilege. The kindly old soul would have crucified a
multitude for the sake of a metaphor. He had in his earlier days
preached a sermon against railroads because God would have
mentioned them to Moses or somebody if he had approved of having
his creatures hurled through space at the diabolic speed of twenty
miles an hour. He had denounced bowling alleys for the same
reason, and also because they were fashionable and more crowded
than his own pews.
RoBards having seen operations where the patient had to be
clamped to a board and gagged for the sake of the neighbors’ ears,
could not believe that this was a pleasant spectacle to any
respectable deity.
He almost came to a break with Dr. Chirnside, who seemed to see
nothing incongruous in calling that divine which men called inhuman.
All of the learned men called “doctors,” whether of divinity,
medicine, law, philosophy, or what-not, seemed to fight everything
new however helpful. Martyrdom awaited the reformer and the
discoverer whether in religion, astronomy, geography, chemistry,
geology, anything.
The names of well-meaning gentlemen like Darwin, Huxley,
Tyndall had recently been howled at with an irate disgust not shown
toward murderers and thieves.
For the next twenty years a war would be waged upon the pain-
killers, and the names of Morton, Jackson, and Wells would inspire
immediate quarrel. Each had his retainers in the contest for what
some called the “honor” of discovering the placid realm of
anæsthesia; and what some called the “sacrilege” of its discovery.
It was written in the sibylline books of history as yet undisclosed
that Wells should be finally humbled to insanity and suicide; and that
Morton, after years of vain effort to get recognition, should retire to a
farm, where he would die from the shock of reading a denial of his
“pretensions.” They would put on his tombstone the legend: “By
whom pain in surgery was averted and annulled; before whom, in all
time, surgery was agony since whom science has had control of
pain.” Yet one’s own epitaph is a little late, however flattering.
RoBards shared Patty’s reverence for the Prometheus who had
snatched from heaven the anodyne to the earth’s worst curse. He
made sure that she should have the advantage of the cloud of
merciful oblivion when she went down into the dark of her last
childbed.
Her final baby was born “still,” as they say; but Patty also was still
during the ordeal. That was no little blessing. RoBards was spared
the hell of listening in helplessness to such moans as Patty had
hitherto uttered when her hour had come upon her unawares.
But the high hopes from this discovery were doomed to sink, for
man seems never to get quite free from his primeval evils, and
RoBards was to find that the God or the devil of pain had not yet
been baffled by man’s puny inventions.
Longing for opportunities to exploit the suppressed braveries in his
soul, RoBards found nothing to do but run to fires. There were
enough of these and the flames fell alike upon the just and the
unjust. Christ Church in Ann Street went up in blazes; the Bowery
Theatre burned down for the fourth time; a sugar house in Duane
Street was next, two men being killed and RoBards badly bruised by
a tumbling wall. The stables of Kipp and Brown were consumed with
over a hundred screaming horses; the omnibus stables of the
Murphys roasted to death a hundred and fifty horses, and took with
them two churches, a parsonage, and a school. While this fire raged,
another broke out in Broome Street, another in Thirty-fifth Street and
another in Seventeenth. The Park Theatre was burned for only the
second time in its fifty years of life; but it stayed burned.
And then Patty succeeded in persuading her husband to resign
from the volunteers and remove his boots and helmet from the
basket under the bed.
This was the knell of his youth and he felt that he had been put out
to grass like an old fire horse, but his heart leaped for years after
when some old brazen-mouthed bell gave tongue. He left it to
others, however, to take out the engine and chase the sparks.
He had come to the port of slippered evenings, but monotony was
not yet his portion. For there were domestic fire bells now.
Patty and Immy were mutual combustibles. They had reached the
ages when the mother forgets her own rebellious youth as
completely as if she had drunk Lethe water; and when the daughter
demands liberty for herself and imposes fetters on her elders.
Patty developed the strictest standards for Immy and was amazed
at the girl’s indifference to her mother’s standards. All of Patty’s
quondam audacities in dress and deportment were remembered as
conformities to strict convention. Immy’s audacities were regarded
as downright indecencies.
Immy, for her part, was outraged at the slightest hint of
youthfulness in her mother. With her own shoulders gleaming and
her young breast brimming at the full beaker of her dress, Immy
would rebuke her mother for wearing what they called a “half-high.”
Both powdered and painted and were mutually horrified. Immy used
the perilous liquid rouge and Patty the cochineal leaves, and each
thought the other unpardonable—and what was worse, discoverable.
Breathless with her own wild gallopades in the polka and dizzy
from waltzing in the desperate clench of some young rake, Immy
would glare at her mother for twirling about the room with a gouty old
judge holding her elbow-tips; or for laughing too loudly at a joke that
her mother should never have understood.
Finally, Patty had recourse to authority and told her husband that
the city was too wicked for the child. She—even Patty—who had
once bidden New York good-by with tears, denounced it now in
terms borrowed from Dr. Chirnside’s tirades.
Immy was mutinous and sullen. She refused to leave and
threatened to run off with any one of a half dozen beaux, none of
whom her parents could endure.
This deadlock was ended by aid from a dreadful quarter. By a
strange repetition of events, the cholera, which had driven Patty into
RoBards’ arms and into the country with him—the cholera which had
never been seen again and for whose destruction the Croton Water
party had taken full glory—the cholera came again.
It began in the pus-pocket of the Points and drained them with
death; then swept the town. Once more there was a northward
hegira. Once more the schoolhouses were hospitals and a thousand
poor sufferers died in black agony on the benches where children
had conned their Webster’s spelling books. Five thousand lives the
cholera took before it went its mysterious way.
Coming of a little bolder generation, Immy was not so panic-
stricken as her mother had been. But since all her friends deserted
the town, she saw no reason for tarrying.
The country was not so dull as she had feared. The air was spicy
with romance; fauns danced in the glades and sat on the stone
fences to pipe their unspeakable tunes; nymphs laughed in the
brooks, and dryads commended the trees.
The railroads made it easy for young bucks to run out on a train
farther in an hour or two than they could have ridden in a day in the
good old horseback times. A fashion for building handsome country
places was encouraged by the cholera scare. White Plains began to
grow in elegance and Robbin’s Mills changed its homely name to
Kensico, after an old Indian chief.
Before many days Immy was busier than in town. Young men and
girls made the quiet yard resound with laughter. The tulip trees
learned to welcome and to shelter sentimental couples. Their great
branches accepted rope swings, and petticoats went foaming toward
the clouds while their wearers shrieked and fell back into the arms of
pushing young men.
Picnics filled the groves with mirth, dances called gay cliques to
lamplit parlors and to moonlit porches. Tuliptree Farm began to
resemble some much frequented roadside tavern. It was as gay as
Cato’s once had been outside New York.
Immy seemed to gather lovers as a bright candle summons foolish
moths. Patty and her husband were swiftly pushed back upon a shelf
of old age whence they watched, incredulous, and unremembering,
the very same activities with which they had amazed their own
parents.
Two lovers gradually crowded the rest aside. The more attractive
to Immy’s parents was a big brave youth named Halleck. He had
joined the old Twenty-seventh Regiment, recently reorganized as the
Seventh, just in time to be called out in the Astor Place riots.
The citizens had lain fairly quiet for a long while and had not
attacked a church or a minister or a theatre for nearly fifteen years.
But the arrival of the English actor Macready incensed the idolators
of Edwin Forrest and developed a civil war.
Young Halleck was with the Seventh when it marched down to
check the vast mob that overwhelmed the police, and drove back a
troop of cavalry whose horses were maddened by the cries and the
confinement. The populace roared down upon the old Seventh and
received three volleys before it returned to civil life.
This exploit in dramatic criticism cost the public thirty-four deaths
and an unknown number of wounds. The Seventh had a hundred
and forty-one casualties. Halleck had been shot with a pistol and
battered with paving stones. To RoBards the lawyer he was a civic
hero of the finest sort. The only thing Immy had against him was that
her parents recommended him so highly.
Love that will not be coerced turned in protest toward the youth
whom her parents most cordially detested, Dr. Chirnside’s son,
Ernest, a pallid young bigot, more pious than his father, and as cruel
as Cotton Mather. Patty wondered how any daughter of hers could
endure the milk-sop. But Immy cultivated him because of his very
contrast with her own hilarity.
His young pedantries, his fierce denunciations of the wickedness
of his companions, his solemn convictions that man was born lost in
Adam’s sin and could only be redeemed from eternal torment by
certain dogmas, fascinated Immy, who had overfed on dances and
flippancies.
RoBards could not help witnessing from his library window the
development of this curious religious romance. Even when he
withdrew to his long writing table and made an honest effort to
escape the temptation to eavesdropping, he would be pursued by
the twangy sententiousness of Ernest and the silvery answers of
Immy. There was an old iron settee under his window and a
rosebush thereby and the young fanatics would sit there to debate
their souls.
It was a godlike privilege and distress to overhear such a
courtship. His daughter bewildered him. At times Immy was as wild
as a mænad. She danced, lied, decoyed, teased, accepted
caresses, deliberately invited wrestling matches for her kisses. She
rode wild horses and goaded them wilder. She would come home
with a shrieking cavalcade and set her foam-flecked steed at the
front fence, rather than wait for the gate to be opened.
Seeing Immy in amorous frenzies RoBards would be stricken with
fear of her and for her. He would wonder if Jud Lasher had not
somehow destroyed her innocence; if his invasion of her integrity
had not prepared her for corruption. How much of that tragedy did
she remember? Or had she forgotten it altogether?
He would shudder with the dread that Jud Lasher, who was lying
beneath his feet, might be wreaking a posthumous revenge,
completing his crime with macaberesque delight.
Then Immy’s mood would change utterly. She would repent her
youth as a curse, and meditate a religious career. There was a new
fashion for sending missionaries to Africa and she was tempted to
proselytize the jungle. Ernest rescued her at least from this. He told
her that she must make sure her own soul was saved before she
went out to save Zulus.
Sometimes RoBards, listening with his pen poised above an
unfinished word, would seem to understand her devotion to young
Chirnside, her acceptance of his intolerant tyranny and the insults he
heaped upon her as a wretch whom his God might have foredoomed
from past eternity to future eternity. He would talk of election and the
conviction of sin and of salvation.
And Immy would drink it down.
At last there came an evening when young Chirnside called in
manifest exaltation. He led Immy to the settee beneath the library
window, and RoBards could not resist the opportunity to overhear
the business that was so important.
He went into his library and softly closed the door. He tiptoed to a
vantage point and listened.
Young Chirnside coughed and stammered and beat about the
bush for a maddening while before he came to his thesis, which was
that the Lord had told him to make Immy his wife. He had come to
beg her to listen to him and heaven. He had brought a little ring
along for the betrothal and—and—how about it? His combination of
sermon and proposal ended in a homeliness that proved his
sincerity. After all that exordium, the point was, How about it?
That was what RoBards wanted to know. He waited as
breathlessly as his prospective son-in-law. Immy did not speak for a
terrible while. And then she sighed deeply, and rather moaned than
said:
“Ernest, I am honored beyond my dreams by what you have said.
To be the wife of so good a man as you would be heaven. But am I
good enough for you?”
“Immy!” Chirnside gasped, “you’re not going to tell me you’ve been
wicked!”
“I’ve been wicked enough, but not very wicked—considering. The
thing I must tell you about is—it’s terribly hard to tell you, dear. But
you ought to know, you have a right to know. And when you know,
you may not think—you may not think—you may feel that you
wouldn’t care to marry me. I wouldn’t blame you—I’d understand,
dear—but——”
“Tell me! In heaven’s name, tell me!”
RoBards was stabbed with a sudden knowledge of what tortured
her thought. He wanted to cry out to her, “Don’t tell! Don’t speak! I
forbid you!”
But that would have betrayed his contemptible position as
eavesdropper. And, after all, what right had he to rebuke such
honesty? She knew her soul. She was inspired perhaps with the
uncanny wisdom of young lovers.
The wish to confess—though “confess” was not the word for her
guiltless martyrdom—was a proof of her nobility. It would be a test of
this young saint’s mettle. If he shrank from her, it would rescue her
from a pigeon-hearted recreant. If he loved her all the more for her
mischance, he would prove himself better than he seemed, more
Christlike than he looked.
And so RoBards, guessing what blighting knowledge Immy was
about to unfold, stood in the dark and listened. Tears of pity for her
scalded his clenched eyelids and dripped bitter into his quivering
mouth.
Unseeing and unseen, he heard his child murmuring her little
tragedy to the awesmitten boy at her side. She seemed as pitifully
beautiful as some white young leper whispering through a rag,
“Unclean!”
What would this pious youth think now of the God that put his love
and this girl to such a test? Would he howl blasphemies at heaven?
Would he cower away from the accursed woman or would he fling
his arms about her and mystically heal her by the very divinity of his
yearning?
RoBards could almost believe that Jud Lasher down there in the
walls was also quickened with suspense. His term in hell might
depend on this far-off consequence of his deed.
CHAPTER XXXII

A STRANGE thing, a word: and stranger, the terror of it. Stranger


still, the things everybody knows that must never be named.
Strangest of all, that the mind sees most vividly what is not
mentioned, what cannot be told.
Immy, for all her rebellious modernness and impatience of old-
fashioned pruderies, was a slave of the word.
And now she must make clear to a young man of even greater
nicety than she, an adventure it would have sobered a physician to
describe to another. She gasped and groped and filled her story with
the pervividness of eloquent silences:
“It was when I was a little girl—a very little girl. There was a big
terrible boy—a young man, rather—who lived down the road—ugly
and horrible as a hyena. And one day—when Papa was gone—and I
was playing—he came along and he spoke to me with a grin and a—
a funny look in his eyes. And he took hold of me—it was like a
snake! and I tried to break loose—and my little brother fought him.
But he knocked and kicked Keith down—and took me up and carried
me away. I fought and screamed but he put his hand over my mouth
and almost smothered me—and kept on running—then—then——”
Then there was a hush so deep that RoBards felt he could hear
his tears where they struck the carpet under his feet. His eyelids
were locked in woe, but he seemed to see what she thought of; he
seemed to see the frightened eyes of Ernest Chirnside trying not to
understand.
Immy went on:
“Then Jud Lasher heard Papa coming and he ran. Papa caught
him and beat him almost to death—but it was too late to save me. I
didn’t understand much, then. But now—! Papa made me promise
never to speak of it; but you have a higher right than anybody, Ernest
—that is, if you still—unless you—oh, tell me!—speak!—say
something!”
The boy spoke with an unimaginable wolfishness in his throat:
“Where is the man?—where is that man?”
“I don’t know. I never saw him after that—oh, yes, he came back
again once. But Papa was watching and saved me from him—and
after that I never heard of him. Yes, I did hear someone say he went
to sea.”
Another hush and then Ernest’s voice, pinched with emotion:
“I believe if I could find that villain I could almost kill him. My soul is
full of murder. God forgive me!”
He thought of his own soul first.
Poor Immy suffered the desolation of a girl who finds her hero
common clay; her saint a prig. But with apology she said:
“I ought never to have told you.”
He dazed her by his reply:
“Oh, I won’t tell anybody; never fear! But don’t tell me any more
just now. I must think it out.”
He wanted to think!—at a time when thinking was poltroon; when
only feeling and impulsive action were decent! Immy waited while he
thought. At length he said:
“If that man still lives he’ll come back again!”
“No! no!”
“He’ll come back and get you.”
“You wouldn’t let him, would you?”
“You belong to him, in a way. It is the Lord’s will.”
He could say that and believe it! The young zealot could worship a
god who could doom, ten thousand years before its birth, a child to a
thousand, thousand years of fiery torment because of an Adam
likewise doomed to his disobedience.
The young man’s own agony had benumbed him perhaps, but
RoBards could have leapt from the window and strangled him as a
more loathsome, a clammier reptile than Jud Lasher. But he, too,
was numb with astonishment.
Then the boy went human all at once and began to sob, to wail,
“Oh, Immy, Immy! my poor Immy!”
RoBards stepped forward to the window in a rush of happiness,
and saw Immy put out her hands to her lover. He pushed them away
and rose and moved blindly across the grass. But there was a heavy
dew and he stepped back to the walk to keep his feet from getting
wet.
He stumbled along the path to the gate and leaned there a
moment, sobbing. Then he swung it wide as he ran out to where his
horse was tied. And the gate beat back and forth, creaking, like a
rusty heart.
RoBards stood gazing down at his daughter, eerily beautiful in the
moonlight through the rose leaves. He saw her dim hands twitching
each at the other. Then they fell still in her lap and she sat as a worn-
out farm-wife sits whose back is broken with overlong grubbing in the
soil and with too heavy a load home.
For a long time he sorrowed over her, then he went stealthily
across his library into the hall, and out to the porch where he looked
at the night a moment. He discovered Immy as if by accident, and
exclaimed, “Who’s that?”
“It’s only me, Papa, only me!”
“Only you? Why you’re all there is. You’re the most precious thing
on earth.”
He put his arm about her, but she sprang to her feet and snapped
at him:
“Don’t! If you please, Papa, don’t touch me. I—I’m not fit to be
touched.”
She stood away from him, bracing herself with a kind of pride.
Then she broke into a maudlin giggle, such as RoBards had heard
from the besotted girls in the Five Points. And she walked into the
house.
He followed her, and knocked on her door. But she would not
answer, and when he tried it, it was locked.
CHAPTER XXXIII

THE next morning RoBards heard her voice again. It was loud and
rough, drowning the angry voice of her brother, Keith. She was
saying:
“I was a fool to tell him! And I was a fool to tell you I told him!”
“I’ll beat him to death when I find him, that’s all I’ll do!” Keith
roared, with his new bass voice.
“If you ever touch him or mention my name to him—or his name to
me,” Immy stormed, “I’ll—I’ll kill—I’ll kill myself. Do you understand?”
“Aw, Immy, Immy!” Keith pleaded with wonderful pity in his voice.
Then she wept, long, piteously, in stabbing sobs that tore the heart of
her father.
He knew that she was in her brother’s arms, for he could hear his
voice deep with sympathy. But RoBards dared not make a third
there. It was no place for a father.
He went to his library and stood staring at the marble hearthstone.
Somewhere down there was what was left of Jud Lasher. He had not
been destroyed utterly, for he was still abroad like a fiend, wreaking
cruel harm.
Immy spoke and RoBards was startled, for he had not heard her
come in:
“Papa.”
“Yes, my darling!”
“Do you think Jud Lasher will ever come back?”
“I know he won’t.”
“How do you know?”
“Oh, I just feel sure. He’d never dare come back.”
“If he did would I belong to him?”
“Would a lamb belong to a sheep-killing dog that mangled it?”
“That’s so. Thank you, Papa.” And she was gone.
A boy on a horse brought her a note that afternoon. She told no
one its contents and when Patty asked who sent it, Immy did not
answer. RoBards was sure it came from Ernest Chirnside, for the
youth never appeared. But RoBards felt no right to ask.
Somehow he felt that there was no place for him as a father in
Immy’s after-conduct. She returned to her wildness, like a deer that
has broken back to the woods and will not be coaxed in again.
How could he blame her? What solemn monition could he parrot
to a soul that had had such an experience with honesty, such a
contact with virtue?
Young Chirnside never came to the house. But he was the only
youth in the countryside, it seemed, that kept away. Patty tried to
curb Immy’s frantic hilarities, but she had such insolence for her
pains that she was stricken helpless.
Then Immy decided that the country was dull. The young men
went back to town, or to their various colleges. Keith went to
Columbia College, which was still in Park Place, though plans were
afoot for moving it out into the more salubrious rural district of Fiftieth
Street and Madison Avenue.
Keith met Chirnside on the campus, but he could not force a
quarrel without dragging Immy’s name into it. So he let slip the
opportunity for punishment, as his father had let slip the occasion for
punishing Chalender. Father and son were curiously alike in their
passion for secrets.
Keith had little interest in the classic studies that made up most of
the curriculum. He could not endure Latin and the only thing he
found tolerable in Cæsar was the description of the bridge that
baffled the other students with its difficulties.
He was an engineer by nature. He had never recovered from his
ambition to be an hydraulic savior of the city. And it looked as if the
town would soon need another redemption.
The citizens had treated the Croton as a toy at first. The hydrants
were free and the waste was ruinous. This blessing, like the
heavenly manna, became contemptible with familiarity. Children
made a pastime of sprinkling the yards and the streets. The habit of
bathing grew until many were soaking their hides every day. During
the winter the householders let the water run all day and all night
through the open faucets, to prevent the pipes from freezing. There
were twelve thousand people, too, who had water in their houses!
Already in 1846 the Commissioners had begun to talk of a costly
new reservoir as a necessity. For thirteen days that year the supply
had to be shut off while the aqueduct was inspected and leaks
repaired. What if another great fire had started?
In 1849 the Water Commissioners were dismissed and the Croton
Aqueduct Department entrusted with the priesthood of the river god
and his elongated temple.
So Keith looked forward to the time when he should be needed by
New York and by other cities. And he studied hard. But he played
hard, too. The students were a lawless set, and drunkenness and
religious infidelity were rival methods for distressing their teachers.
Up at New Haven the Yale boys in a certain class, feeling
themselves wronged by a certain professor, had disguised
themselves as Indians and with long knives whittled all the study
benches into shavings while the terrified instructor cowered on his
throne and watched.
Vice of every sort seemed to be the chief study of such of the
students as were not aiming at the ministry. As one of the college
graduates wrote:
“Hot suppers, midnight carousals were too frequent with us and
sowed the seed of a vice that in a few years carried off a fearful
proportion of our members to an untimely grave.”
There was grave anxiety for the morals of the whole nation. The
city was growing too fast. By 1850 it had passed the half-million
mark! The churches were not numerous enough to hold a quarter of
the population, yet most of them were sparsely attended.
The American home was collapsing. Dr. Chirnside preached on
the exalted cost of living, and stated that church weddings were on
the decrease. The hotel was ruining the family. Rents were so
exorbitant, servants so scarce and incompetent, that people were
giving up the domesticity of the good old days.
Business detained the husband downtown, and he took his
midday dinner at Sweeny’s or Delmonico’s, where he could have
poultry or sirloin steak for a shilling and sixpence. And his wife and
daughters, unwilling to eat alone, went to Weller’s or Taylor’s and
had a fricandeau, an ice, or a meringue. Ladies’ saloons were
numerous and magnificent and wives could buy ready-made meals
there; so they forgot how to cook. The care of children no longer
concerned them. Women were losing all the retiring charm that had
hitherto given them their divine power over men.
The clergy bewailed the approaching collapse of a nation that had
forgotten God—or had never remembered him. There was a
movement afoot to amend the Constitution with an acknowledgment
of the Deity and “take the stain of atheism from that all-important
document.”
These were the Sunday thoughts.
In contrast were the Fourth of July thoughts, when the country
sang its own hallelujahs and, like another deity, contentedly
meditated its own perfections. On these occasions every American
man was better than any foreigner, and American women were all
saints.
And there were the Election Day moods, when the country split up
into parties for a few weeks, and played tennis with mutual charges
of corruption, thievery, treason. Then there was Christmas, when
everybody loved everybody; and New Year’s Day, when everybody
called on everybody and got a little drunk on good wishes and the
toasts that went with them.
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!

textbookfull.com

You might also like