ebook img

Starting Out With Visual Basic 2008 Update PDF

889 Pages·2009·18.878 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Starting Out With Visual Basic 2008 Update

STARTING OUT WITH Visual Basic® 2008 UPDATE Fourth Edition Tony Gaddis Haywood Community College Kip Irvine Florida International University Addison-Wesley Boston San Francisco New York London Toronto Sydney Tokyo Singapore Madrid Mexico City Munich Paris Cape Town Hong Kong Montreal Editor in Chief: Michael Hirsch Acquisition Editor: Matt Goldstein Editorial Assistant: Sarah Milmore Senior Production Supervisor: Marilyn Lloyd Text Designer: Joyce Cosentino Wells Cover Designer: Elena Sidorova Online Product Manager: Bethany Tidd Senior Media Buyer: Ginny Michaud Marketing Manager: Erin Davis Senior Manufacturing Buyer: Carol Melville Production Services: Gillian Hall, The Aardvark Group Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Addison- Wesley was aware of a trademark claim, the designations have been printed in initial caps or all caps. The programs and applications presented in this book have been included for their instructional value. They have been tested with care but are not guaranteed for any particular purpose. The publisher does not offer any warranty or representation, nor does it accept any liabilities with respect to the programs or applications. The interior of this book was composed in QuarkXPress 6.52. The main type face used in the text is Sabon. The display font is Stone Sans. Library of Congress Cataloging-in-Publication Data Gaddis, Tony. Starting out with Visual Basic 2008 / Tony Gaddis, Kip Irvine. -- Updated 4th ed. p. cm. ISBN 978-0-13-607695-7 1. Microsoft Visual BASIC. 2. BASIC (Computer program language) I. Irvine, Kip R., 1951- II. Title. QA76.73.B3G327 2010 005.2'762--dc22 2008055546 Copyright © 2010 Pearson Education, Inc. All rights reserved. No part of this publica- tion may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. For information on obtaining permission for use of material in this work, please submit a written request to Pearson Education, Inc., Rights and Contracts Department, 501 Addison-Wesley Boylston Street, Suite 900, Boston, MA 02116, fax your request to 617-671-3447, is an imprint of or e-mail at http://www.pearsoned.com/legal/permissions.htm. ISBN 13: 9780136076957 ISBN 10: 0136076955 www.pearsonhighered.com 2 3 4 5 6 7 8 9 10—EB—12 11 10 09 Locations of VideoNotes Chapter 1 Forms, Controls, and Properties . . . . . . . . . . . . . . . . . . . . . . . . . 8 Event-Driven Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Solving the Sales Tax Problem . . . . . . . . . . . . . . . . . . . . . . . . . 39 Chapter 2 Starting a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Using Label Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Responding to Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 The Name Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 The Name and Address Problem . . . . . . . . . . . . . . . . . . . . . . . 96 Chapter 3 Introduction to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Problem Solving with Variables . . . . . . . . . . . . . . . . . . . . . . . 123 The Miles per Gallon Calculator Problem . . . . . . . . . . . . . . . . 185 Chapter 4 The If...Then Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 The If...Then...Else Statement . . . . . . . . . . . . . . . . . . . . 201 The Roman Numeral Converter Problem . . . . . . . . . . . . . . . . 267 Chapter 5 The Do While Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 The For Next Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 The Sum of Numbers Problem . . . . . . . . . . . . . . . . . . . . . . . . 347 Chapter 6 Passing Arguments to Procedures . . . . . . . . . . . . . . . . . . . . . . 367 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374 The Retail Price Calculator Problem . . . . . . . . . . . . . . . . . . . . 404 Chapter 7 Creating and Displaying a Second Form . . . . . . . . . . . . . . . . 413 Creating a Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 The Astronomy Helper Problem . . . . . . . . . . . . . . . . . . . . . . . 486 Chapter 8 Accessing Array Elements with a Loop . . . . . . . . . . . . . . . . . . 493 Calculating the Sum of an Array's Elements . . . . . . . . . . . . . . 495 The Lottery Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557 Chapter 9 Writing Data to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563 Reading Data from a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569 The Random Number File Generator Problem . . . . . . . . . . . . 622 Chapter 10 The DataGridView Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 630 Data-Bound Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641 The Karate Members Grid Problem . . . . . . . . . . . . . . . . . . . . 690 Chapter 11 Creating a Simple Web Application . . . . . . . . . . . . . . . . . . . . 700 The Stadium Seating Problem . . . . . . . . . . . . . . . . . . . . . . . . 746 Chapter 12 Creating a Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753 Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770 The Scrollable Tax Calculator Problem . . . . . . . . . . . . . . . . . . 813 iii Contents in Brief Preface xii Chapter 1 Introduction to Programming and Visual Basic 1 Chapter 2 Creating Applications with Visual Basic 41 Chapter 3 Variables and Calculations 99 Chapter 4 Making Decisions and Working with Strings 193 Chapter 5 Lists, Loops, Validation, and More 275 Chapter 6 Procedures and Functions 355 Chapter 7 Multiple Forms, Standard Modules, and Menus 411 Chapter 8 Arrays, Timers, and More 489 Chapter 9 Files, Printing, and Structures 561 Chapter 10 Working with Databases 625 Chapter 11 Developing Web Applications 695 Chapter 12 Classes, Collections, and Scrollable Controls 749 Appendix A User Interface Design Guidelines 817 Appendix B Converting Mathematical Expressions to Programming Statements 820 Appendix C Answers to Checkpoints 822 Appendix D Glossary 840 Appendix E Visual Basic 2008 Function and Method Reference (located on the Student CD-ROM) Appendix F Binary and Random-Access Files (located on the Student CD-ROM) Appendix G Answers to Odd-Numbered Review Questions (located on the Companion Website at http://www.aw.com/gaddisvb) Index 851 iv Contents Preface xii Chapter 1 Introduction to Programming and Visual Basic 1 1.1 Computer Systems: Hardware and Software . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Programs and Programming Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 TUTORIAL 1-1: Running the Wage Calculator application . . . . . . . . . . . . . . . . . . . . . 8 TUTORIAL 1-2: Running an application that demonstrates event procedures . . . . . . . 9 1.3 More about Controls and Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 TUTORIAL 1-3: Running an application that demonstrates various controls . . . . . . 11 1.4 The Programming Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.5 Visual Studio and Visual Basic Express (the Visual Basic Environment) . . . . . 21 TUTORIAL 1-4: Starting Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 TUTORIAL 1-5: Opening the Design, Solution Explorer, Dynamic Help, and Properties windows in Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 TUTORIAL 1-6: Getting familiar with Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . 32 Summary 34 • Key Terms 34 • Review Questions and Exercises 35 • Programming Challenges 39 Chapter 2 Creating Applications with Visual Basic 41 2.1 Focus on Problem Solving: Building the Directions Application . . . . . . . . . . 41 TUTORIAL 2-1: Beginning the Directions application . . . . . . . . . . . . . . . . . . . . . . . . 44 TUTORIAL 2-2: Adding a Label control to the Directions application . . . . . . . . . . . 46 TUTORIAL 2-3: Setting the Label’s TextAlign property . . . . . . . . . . . . . . . . . . . . . . . 48 TUTORIAL 2-4: Changing the Label’s font size and style . . . . . . . . . . . . . . . . . . . . . 49 TUTORIAL 2-5: Deleting a control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 TUTORIAL 2-6: Inserting a PictureBox control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 TUTORIAL 2-7: Saving and running the application . . . . . . . . . . . . . . . . . . . . . . . . . 52 TUTORIAL 2-8: Closing a Visual Basic project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 TUTORIAL 2-9: Opening an existing project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 TUTORIAL 2-10: Using the Object box, Alphabetical button, and Categorized button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 2.2 Focus on Problem Solving: Responding to Events . . . . . . . . . . . . . . . . . . . . 59 TUTORIAL 2-11: Placing the lblDirections, btnDisplayDirections, and btnExit controls in the Directions application . . . . . . . . . . . . . . . . . . . 64 TUTORIAL 2-12: Writing event procedures for the Directions application . . . . . . . . 68 TUTORIAL 2-13: Changing the text colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 TUTORIAL 2-14: Setting the FormBorderStyle property and locking the controls in the Directions application . . . . . . . . . . . . . . . . . 75 2.3 Modifying the Text Property with Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 TUTORIAL 2-15: Examining an application that displays messages . . . . . . . . . . . . . 76 v vi Contents 2.4 The AutoSize, BorderStyle, and TextAlign Properties . . . . . . . . . . . . . . . . . . 78 2.5 Clickable Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 TUTORIAL 2-16: Writing Click event procedures for PictureBox controls . . . . . . . . 80 2.6 Using Visual Studio Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 TUTORIAL 2-17: Using Dynamic Help in Visual Studio . . . . . . . . . . . . . . . . . . . . . 85 2.7 Debugging Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 TUTORIAL 2-18: Locating a compile error in Design mode . . . . . . . . . . . . . . . . . . . 89 Summary 91 • Key Terms 92 • Review Questions and Exercises 92 • Programming Challenges 95 Chapter 3 Variables and Calculations 99 3.1 Gathering Text Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 TUTORIAL 3-1: Using a TextBox control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 TUTORIAL 3-2: Building the Date String application . . . . . . . . . . . . . . . . . . . . . . . 103 TUTORIAL 3-3: Using the Focus method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 TUTORIAL 3-4: Changing the tab order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 TUTORIAL 3-5: Setting access keys, accept, and cancel buttons . . . . . . . . . . . . . . . 111 3.2 Variables and Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 TUTORIAL 3-6: Assigning text to a variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 3.3 Performing Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 3.4 Mixing Different Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 TUTORIAL 3-7: Examining a Simple Calculator application . . . . . . . . . . . . . . . . . . 140 3.5 Formatting Numbers and Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 TUTORIAL 3-8: Examining the Format Demo application . . . . . . . . . . . . . . . . . . . 146 3.6 Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 TUTORIAL 3-9: Salary Calculation application with exception handling . . . . . . . . 153 3.7 Group Boxes and the Load Event Procedure . . . . . . . . . . . . . . . . . . . . . . . 155 3.8 Focus on Program Design and Problem Solving: Building the Room Charge Calculator Application . . . . . . . . . . . . . . . . . . . . 158 TUTORIAL 3-10: Beginning the Room Charge Calculator application . . . . . . . . . . 162 TUTORIAL 3-11: Changing a label’s colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 3.9 More about Debugging: Locating Logic Errors . . . . . . . . . . . . . . . . . . . . . 168 TUTORIAL 3-12: Single-stepping through an application’s code at runtime . . . . . . 169 Summary 175 • Key Terms 178 • Review Questions and Exercises 179 • Programming Challenges 185 Chapter 4 Making Decisions and Working with Strings 193 4.1 The Decision Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 4.2 The If...Then Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 TUTORIAL 4-1: Examining an application that uses the If...Then statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 4.3 The If...Then...Else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 TUTORIAL 4-2: Completing an application that uses the If...Then...Else statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 4.4 The If...Then...ElseIf Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 TUTORIAL 4-3: Completing an application that uses the If...Then...ElseIf statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 Contents vii TUTORIAL 4-4: Comparing an If...Then...ElseIf statement to a series of If...Then statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 4.5 Nested If Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 TUTORIAL 4-5: Completing an application with a nested If statement . . . . . . . . . 212 4.6 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 4.7 Comparing, Testing, and Working with Strings . . . . . . . . . . . . . . . . . . . . . 220 TUTORIAL 4-6: Examining an application that performs string comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 TUTORIAL 4-7: Completing a string searching application . . . . . . . . . . . . . . . . . . . 228 4.8 Focus on GUI Design: The Message Box . . . . . . . . . . . . . . . . . . . . . . . . . . 231 4.9 The Select Case Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 TUTORIAL 4-8: Examining Crazy Al’s Sales Commission Calculator application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 4.10 Introduction to Input Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 4.11 Focus on GUI Design: Radio Buttons and Check Boxes . . . . . . . . . . . . . . . 244 TUTORIAL 4-9: Completing an application with radio buttons and check boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 4.12 Class-Level Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 4.13 Focus on Program Design and Problem Solving: Building the Health Club Membership Fee Calculator Application . . . . . . . . . . . . . . . . . . 249 TUTORIAL 4-10: Building the Health Club Membership Fee Calculator application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Summary 259 • Key Terms 260 • Review Questions and Exercises 261 • Programming Challenges 266 Chapter 5 Lists, Loops, Validation, and More 275 5.1 Input Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 5.2 List Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 TUTORIAL 5-1: Creating list boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 5.3 Introduction to Loops: The Do While Loop . . . . . . . . . . . . . . . . . . . . . . . . 287 TUTORIAL 5-2: Completing an application that uses the Do While loop . . . . . . . . 288 TUTORIAL 5-3: Modifying the Do While Demo application to use a posttest loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 TUTORIAL 5-4: Using a loop to keep a running total . . . . . . . . . . . . . . . . . . . . . . . 293 TUTORIAL 5-5: Examining an application that uses a user-controlled loop . . . . . . 297 5.4 The Do Until and For...Next Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 TUTORIAL 5-6: Examining an application that uses the Do Until loop . . . . . . . . 300 TUTORIAL 5-7: Examining an application that uses the For...Next loop . . . . . . 302 TUTORIAL 5-8: Completing an application that uses the For...Next loop . . . . . . 304 5.5 Nested Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 5.6 Multicolumn List Boxes, Checked List Boxes, and Combo Boxes . . . . . . . 309 TUTORIAL 5-9: Creating combo boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 5.7 Input Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 TUTORIAL 5-10: Completing an application that demonstrates input validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 TUTORIAL 5-11: An example of inconvenient data input correction . . . . . . . . . . . 320 TUTORIAL 5-12: Modifying the Validation Demo project to use the SelectAll method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 viii Contents 5.8 ToolTips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 TUTORIAL 5-13: Adding ToolTips to an application . . . . . . . . . . . . . . . . . . . . . . . 324 5.9 Focus on Program Design and Problem Solving: Building the Vehicle Loan Calculator Application . . . . . . . . . . . . . . . . . . . . 325 TUTORIAL 5-14: Building the Vehicle Loan Calculator application . . . . . . . . . . . . 334 Summary 339 • Key Terms 340 • Review Questions and Exercises 340 • Programming Challenges 347 Chapter 6 Procedures and Functions 355 6.1 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 TUTORIAL 6-1: Examining an application with a procedure . . . . . . . . . . . . . . . . . 356 TUTORIAL 6-2: Creating a procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 6.2 Passing Arguments to Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 TUTORIAL 6-3: Examining an application that demonstrates passing an argument to a procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368 TUTORIAL 6-4: Working with ByVal and ByRef . . . . . . . . . . . . . . . . . . . . . . . . . . 371 6.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374 TUTORIAL 6-5: Examining the GPA Calculator application . . . . . . . . . . . . . . . . . . 376 6.4 More about Debugging: Stepping Into, Over, and Out of Procedures and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382 TUTORIAL 6-6: Practicing the Step Into, Step Over, and Step Out commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 6.5 Focus on Program Design and Problem Solving: Building the Bagel and Coffee Price Calculator Application . . . . . . . . . . . . . 385 TUTORIAL 6-7: Building the Bagel House application . . . . . . . . . . . . . . . . . . . . . . 395 Summary 399 • Key Terms 400 • Review Questions and Exercises 400 • Programming Challenges 404 Chapter 7 Multiple Forms, Standard Modules, and Menus 411 7.1 Multiple Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411 TUTORIAL 7-1: Completing an application that displays modal and modeless forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 TUTORIAL 7-2: Completing an application with multiple forms . . . . . . . . . . . . . . 426 7.2 Standard Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432 TUTORIAL 7-3: Examining an application that uses a standard module . . . . . . . . . 435 7.3 Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 TUTORIAL 7-4: Building a menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 7.4 Focus on Problem Solving: Building the High Adventure Travel Agency Price Quote Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 TUTORIAL 7-5: Building the High Adventure Travel Agency Price Quote application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 Summary 473 • Key Terms 474 • Review Questions and Exercises 474 • Programming Challenges 479 Chapter 8 Arrays, Timers, and More 489 8.1 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489 TUTORIAL 8-1: Completing an application that uses an array . . . . . . . . . . . . . . . . 498 Contents ix 8.2 More about Array Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 TUTORIAL 8-2: Examining an application that uses parallel arrays . . . . . . . . . . . . 505 8.3 Procedures and Functions That Work with Arrays . . . . . . . . . . . . . . . . . . . 512 TUTORIAL 8-3: Examining an application with functions and with arrays . . . . . . . 514 8.4 Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518 TUTORIAL 8-4: Completing an application that sums the rows of a two-dimensional array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520 8.5 Focus on GUI Design: The Enabled Property, Timer Control, and Splash Screens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 TUTORIAL 8-5: The Timer Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 TUTORIAL 8-6: Creating a splash screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529 8.6 Focus on GUI Design: Anchoring and Docking Controls . . . . . . . . . . . . . . 531 8.7 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534 TUTORIAL 8-7: Examining the CatchMe application . . . . . . . . . . . . . . . . . . . . . . . 535 8.8 Focus on Problem Solving: Building the Demetris Leadership Center Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 TUTORIAL 8-8: Building the Demetris Leadership Center Sales Reporting application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541 Summary 546 • Key Terms 547 • Review Questions and Exercises 548 • Programming Challenges 553 Chapter 9 Files, Printing, and Structures 561 9.1 Using Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561 TUTORIAL 9-1: Completing an application that writes data to a file . . . . . . . . . . . 566 TUTORIAL 9-2: Completing an application that reads a file . . . . . . . . . . . . . . . . . . 571 TUTORIAL 9-3: Examining an application that detects the end of a file . . . . . . . . . 576 9.2 The OpenFileDialog, SaveFileDialog, FontDialog, and ColorDialog Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580 TUTORIAL 9-4: Creating a simple text editor application . . . . . . . . . . . . . . . . . . . . 584 9.3 The PrintDocument Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 TUTORIAL 9-5: Adding printing capabilities to the Simple Text Editor application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594 9.4 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 TUTORIAL 9-6: Examining an application with a structure . . . . . . . . . . . . . . . . . . 602 9.5 Focus on Problem Solving: Modifying the Demetris Leadership Center Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604 TUTORIAL 9-7: Modifying the Demetris Leadership Center Sales Reporting application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605 Summary 613 • Key Terms 614 • Review Questions and Exercises 614 • Programming Challenges 620 Chapter 10 Working with Databases 625 10.1 Database Management Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625 10.2 Database Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626 10.3 DataGridView Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630 TUTORIAL 10-1: Showing a database table in a DataGridView control . . . . . . . . . 631 TUTORIAL 10-2: Sorting and updating the SalesStaff table . . . . . . . . . . . . . . . . . . . 638

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.