Register your product to gain access to bonus material or receive a coupon.
8292J-8
Includes the Number 1 Visual Basic 6 Training CD-ROM: Visual Basic 6 Multimedia Cyber Classroom.
Includes the best-selling Visual Basic 6 Book: Visual Basic 6 How to Program.
Master ActiveX, objects, TCP/IP networking, VBScript, multimedia, GUIs, data structures, control creation and much more!
6+ hours of audio, hundreds of BV6 programs with thousands of lines of fully tested code, hundreds of interactive and programming exercises and more!
Ideal for experienced VB5, C/C++, and Java programmers, as well as new programmers interested in VB6's latest features.
FREE BONUS! Official Microsoft Visual Basic 6 Working Model Software - Everything you need to begin programming today!
THE WORLD'S #1 VISUAL BASIC 6 TRAINING CD-ROM
You get the world's #1 VB6 training CD-ROM plus a worldwide best-selling VB6 book and Microsoft's VB6 Working Model Software - together, they make you a VB6 expert faster than you ever imagined.
THE WORLD'S #1 VISUAL BASIC 6 TEXTBOOK
Start-to-finish, 1200-page guide to Visual Basic 6
Friendly, practical tutorials with tips and tricks for troubleshooting and optimization.
Total coverage of Visual Basic 6, from the basics to the leading edge.
Master all this and more: Active X, objects, control structures, procedures, functions, arrays, strings, multimedia, GUI development, error handling, debugging, file processing -- even database, Internet and Web integration.
Specially Designed For:
RAVES FOR OTHER DEITEL TRAINING COURSES
"In just the few short hours I have spent with it, I have learned more than in two entire weeks of class recitation sessions at school! I just had to write you guys and say what a wonderful job you've done...."—Brian Fertig, university student
"The Java Ultimate Cyber Classroom Training Course is great. Paul Deitel does a good job teaching the fundamentals of Java using audio clips with each example. Highly recommend learning Java, or any programming language, with the Deitel Cyber Classroom training advantage!"—Joseph Casale, Principal Chemist, Connecticut Department of Health
FREE BONUS! Official Microsoft Visual Basic 6 Working Model Software - Master the VB6 Integrated Development Environment NOW!
Run the hundreds of sample VB6 programs from the Cyber Classroom - or any VB6 code you write! A powerful Visual Basic 6 Integrated Development Environment - the perfect tool for learning VB6 programming - and it's yours, free!
The authors can be contacted at deitel@deitel.com -- For information on public and corporate on-site seminars offered by Deitel & Associates, Inc. worldwide, visit http://www.deitel.com.
SYSTEM REQUIREMENTS
Windows 95/98, Windows NT 4.x
20 MB disk space
16 MB RAM (32 MB for Windows NT)
4x CD-ROM drive or higher
Sound card support
Prentice Hall PTR Interactive
Upper Saddle River, NJ 07458
Click here for a sample chapter for this book: 0130829293.pdf
1. Computing Concepts.
2. Integrated Development Environment.
3. Introduction to Visual Basic Programming.
4. Control Structures: Part I.
5. Control Structures: Part II.
6. Sub Procedures and Function Procedures.
7. Arrays.
8. Strings, Dates and Times.
9. Graphics.
10. Basic Graphical User Interface Concepts.
11. Advanced Graphical User Interface Concepts.
12. Mouse and Keyboard.
13. Error Handling and Debugging.
14. Sequential File Processing.
15. Records and Random-Access Files.
16. Object-Oriented Programming.
17. ActiveX.
18. Database Management.
19. Networking, the Internet and the World Wide Web.
20. Multimedia: Images, Animation, Audio.
21. Data Structures, Collections and Dictionaries.
Appendix A: Operator Precedence Chart.
Appendix B: ANSI Character Set.
Appendix C: Visual Basic Internet and World Wide Web Resources.
Appendix D: Number Systems.
Index.
Live in fragments no longer. Only connect. - Edward Morgan Forster
Welcome to Visual Basic 6 and the exciting world of Internet and World Wide Web programming! This book is by an old guy and two young guys. The old guy HMD; Massachusetts Institute of Technology (MIT) 1967 has been programming and/or teaching programming for 37 years. The two young guys PJD; MIT 1991 and TRN; MIT 1992 have each been programming for 15 years and have caught the teaching and writing "bug." The old guy programs and teaches from experience; the young guys do so from an inexhaustible reserve of energy. The old guy wants clarity; the young guys want performance. The old guy seeks elegance and beauty; the young guys want results. We got together to produce a book we hope you will find informative, interesting, challenging and entertaining.
Why We Wrote Visual Basic 6 How to Program
Dr. Harvey M. Deitel taught introductory programming courses in universities for 20 years with an emphasis on developing clearly written, well-structured programs. Much of what is taught in these courses is the basic principles of programming with an emphasis on the effective use of control structures, primitive data types, arrays, functions and the program development process.
We present these topics in Visual Basic 6 How to Program exactly the way HMD has done in his university courses. Our experience has been that students handle the material in the early chapters on primitive data types, control structures, procedures and arrays in about the same manner as they handle introductory Pascal or C courses. There is one noticeable difference though: students are highly motivated by the fact that they are learning a leading-edge language (Visual Basic 6) and leading-edge programming paradigms (event-driven programming and object-oriented programming) that will be immediately useful to them as they leave the university environment. This increases their enthusiasm for the material. Students quickly discover that they can do great things with Visual Basic 6, so they are willing to put incredible effort into their courses.
Our goal was clear: produce a Visual Basic 6 textbook for introductory university-level courses in computer programming for students with little or no programming experience, yet offer the depth and the rigorous treatment of theory and practice demanded by traditional, upper-level C and C++ courses and that satisfies professionals' needs. To meet these goals, we produced a comprehensive book because our text also patiently teaches the principles of control structures, event-driven programming, object-oriented programming and the Visual Basic 6 language.
Visual Basic 6 How to Program was written fresh on the heels of C How to Program: Second Edition, C++ How to Program: Second Edition and Java How to Program: Second Edition, each of which has become the world's leading introductory textbook in its respective field. Hundreds of thousands of students and professional people worldwide have learned C, C++ and Java from these texts. Upon publication in November, 1998 Visual Basic 6 How to Program will be used in universities, professional schools and corporate training programs worldwide.
We have prepared an interactive multimedia CD-ROM edition of this book - the Visual Basic 6 Multimedia Cyber Classroom. Prentice Hall offers a "value pack" edition of both Visual Basic 6 How to Program and the Visual Basic 6 Multimedia Cyber Classroom called The Complete Visual Basic 6 Training Course at a discount for people who want to use both the book and the multimedia CD. Please see the last few pages of this book for ordering instructions. The Complete Visual Basic 6 Training Course is discussed in more detail later in this Preface.
We believe in Visual Basic 6. Its conceptualization by Microsoft, the creators of Visual Basic 6, is brilliant: Base a language on one of the world's most widely known languages, Basic. Endow the language with the ability to conveniently build applications for Microsoft Windows - the world's most widely used platform. Provide the kinds of heavy duty, high-performance capabilities needed for enterprise systems development. Make the language appropriate for implementing Internet-based and World-Wide-Web-based applications, and build in the features people really need such as Strings, graphics, graphical user interface components, error handling, multimedia (audio, images, animation and video), file processing, database processing, Internet-based client/server networking, World Wide Web browsing, World Wide Web document enhancement with Visual Basic Script (VBScript), and prepackaged components. Make the language extensible so that independent software vendors (ISVs) can provide componentry for a vast array of application arenas. These features are precisely what businesses and organizations need to meet today's information processing requirements.
Visual Basic 6 empowers programmers to unleash their creativity. Once Visual Basic 6 students enter lab, instructors will not be able to hold the students back. They will be eager to experiment and explore. They will quickly produce applications that go well beyond anything they would have produced in introductory programming courses in procedural languages like C, Pascal and non-visual versions of Basic.
The computer field has never seen anything like the Internet/World Wide Web "explosion" occurring today. People want to communicate. People need to communicate. Sure they have been doing that since the dawn of civilization, but computer communications have been mostly limited to digits, alphabetic characters and special characters passing back and forth. The next major wave is surely multimedia. People want to transmit pictures and they want those pictures to be in color. They want to transmit voices, sounds and audio clips. They want to transmit full-motion color video. And at some point, they will insist on three-dimensional, moving-image transmission. Our current flat, two-dimensional televisions will eventually be replaced with three-dimensional versions that turn our living rooms into "theaters in the round." Actors will perform their roles as if we were watching live theater. Our living rooms will be turned into miniature sports stadiums. Our business offices will enable video conferencing among colleagues half a world apart as if they were sitting around one conference table. The possibilities are intriguing and Visual Basic 6 is sure to play a key role in making many of these possibilities become reality.
There have been predictions that the Internet will eventually replace the telephone system. Well, why stop there? It could also replace radio and television as we know them today. It's not hard to imagine the Internet replacing the newspaper with completely electronic news media. This textbook you are reading may someday appear in a museum alongside radios, TVs and newspapers in an "early media of ancient civilization" exhibit.
Teaching Approach
Visual Basic 6 How to Program contains a rich collection of examples, exercises, and projects drawn from many fields to provide the student with a chance to solve interesting real-world problems. The book concentrates on the principles of good software engineering and stresses program clarity. We avoid arcane terminology and syntax specifications in favor of teaching by example. Each of our code examples has been carefully tested.
This book is written by three educators who spend most of their time teaching edge-of-the-practice topics in industry classrooms worldwide. The text emphasizes pedagogy.
Live-Code Teaching Approach
The book is loaded with live-code examples. This is the focus of the way we teach and write about programming, and the focus of each of our multimedia Cyber Classrooms as well. Virtually every new concept is presented in the context of a complete, working Visual Basic 6 program immediately followed by one or more windows showing the program's output. We call this style of teaching and writing our live-code approach. We use the language to teach the language. Reading these programs is much like entering and running them on a computer.
World Wide Web Access
All of the code for Visual Basic 6 How to Program is on the Internet at the Prentice Hall Web site http://www.prenhall.com/deitel and at the Deitel & Associates, Inc. Web site http://www.deitel.com.
Please download all the code then run each program as you read the text. Make changes to the code examples and see what happens. See how the Visual Basic 6 compiler "complains" when you make various kinds of errors. Immediately see the effects of making changes to the code. It's a great way to learn programming by doing programming. You must respect the fact that this is copyrighted material. Feel free to use it as you study Visual Basic 6, but you may not republish any portion of it without explicit permission from the authors and Prentice Hall.
Objectives
Each chapter begins with a statement of Objectives. This tells the student what to expect and gives the student an opportunity, after reading the chapter, to determine if he or she has met these objectives. It is a confidence builder and a source of positive reinforcement.
Quotations
The learning objectives are followed by quotations. Some are humorous, some are philosophical and some offer interesting insights. Our students enjoy relating the quotations to the chapter material. The quotations are worth a "second look" after you read each chapter.
Outline
The chapter Outline helps the student approach the material in top-down fashion. This, too, helps students anticipate what is to come and set a comfortable and effective learning pace.
7806 lines of code in 178 Example Programs (with Program Outputs)
We present Visual Basic 6 features in the context of complete, working Visual Basic 6 programs. This is the focus of our teaching and our writing. We call it our "live-code" approach. Each program is followed by a window with the output produced when the program runs. This enables the student to confirm that the programs run as expected. Reading the book carefully is much like entering and running these programs on a computer. The programs range from just a few lines of code to substantial examples with several hundred lines of code. Students should download all the code for the book from our Web sites and run each program while studying that program in the text. The programs are available at both http://www.deitel.com and http://www.prenhall.com/deitel.
558 Illustrations/Figures
An abundance of charts, line drawings and program outputs is included. The discussion of control structures, for example, features carefully drawn flowcharts. Note: We do not teach the use of flowcharting as a program development tool, but we do use a brief, flowchart-oriented presentation to specify the precise operation of Visual Basic 6's control structures.
412 Programming Tips
We include programming tips to help students focus on important aspects of program development. We highlight hundreds of these tips in the form of Good Programming Practices, Common Programming Errors, Look-and-Feel Observations, Testing and Debugging Tips, Performance Tips, Portability Tips, and Software Engineering Observations. These tips and practices represent the best we have gleaned from a combined six decades of programming and teaching experience. One of our students - a mathematics major - told us recently that she feels this approach is like the highlighting of axioms, theorems and corollaries in mathematics books; it provides a basis on which to build good software.
78 Good Programming Practices
When we teach introductory courses, we state that the "buzzword" of each course is "clarity," and we highlight as Good Programming Practices techniques for writing programs that are clearer, more understandable, more debuggable and more maintainable.
155 Common Programming Errors
Students learning a language tend to make certain errors frequently. Focusing the students' attention on these Common Programming Errors helps students avoid making the same errors. It also helps reduce the long lines outside instructors' offices during office hours!
14 Look-and-Feel Observations
We provide Look-and-Feel Observations to highlight Windows graphical user interface conventions. These observations help students design their applications to "look" and "feel" like typical Windows programs.
39 Performance Tips
In our experience, teaching students to write clear and understandable programs is by far the most important goal for a first programming course. But students want to write the programs that run the fastest, use the least memory, require the smallest number of keystrokes, or dazzle in other nifty ways. Students really care about performance. They want to know what they can do to "turbo charge" their programs, so we have included extensive Performance Tips.
15 Portability Tips
We include Portability Tips to help students write portable code, i.e., code that is designed to run on a variety of platforms. These tips highlight issues that may affect how Visual Basic 6 programs run on Windows systems with different hardware devices. We also consider internationalization issues.
76 Software Engineering Observations
Event-driven programming and object-oriented programming require a complete rethinking about the way we build software systems. Visual Basic 6 is an effective language for performing good software engineering. The Software Engineering Observations highlight architectural and design issues that affect the construction of software systems, especially large-scale systems. Much of what the student learns here will be useful in upper-level courses and in industry as the student begins to work with large, complex real-world systems.
40 Testing and Debugging Tips
When we first designed this "tip type," we thought we would use it strictly to tell people how to test and debug Visual Basic 6 programs. In fact, many of the tips describe aspects of Visual Basic 6 that reduce the likelihood of "bugs" and thus simplify the testing and debugging process for Visual Basic 6 programs.
Summary
Each chapter ends with additional pedagogical devices. We present a thorough, bullet-list-style Summary of the chapter. On average, there are 38 summary bullets per chapter. This helps the students review and reinforce key concepts.
Terminology
We include in a Terminology section an alphabetized list of the important terms defined in the chapter - again, further reinforcement. On average, there are 94 terms per chapter.
Summary of Tips, Practices, and Errors
For ease of reference, we collect and reiterate the Good Programming Practices, Common Programming Errors, Look-and-Feel Observations, Testing-and-Debugging Tips, Performance Tips, Portability Tips, and Software Engineering Observations.
406 Self-Review Exercises and Answers (Count Includes Separate Parts)
Extensive self-review exercises and answers are included for self study. This gives the student a chance to build confidence with the material and prepare for the regular exercises. Students should be encouraged to do all the self-review exercises and to check their answers.
819 Exercises (Solutions in Instructor's Manual; Count Includes Separate Parts)
Each chapter concludes with a substantial set of exercises including simple recall of important terminology and concepts; writing individual Visual Basic 6 statements; writing small portions of Visual Basic 6 procedures and modules; writing complete Visual Basic 6 procedures, classes, applications; and writing major term projects. The large number of exercises across a wide variety of areas enables instructors to tailor their courses to the unique needs of their audiences and to vary course assignments each semester. Instructors can use these exercises to form homework assignments, short quizzes, and major examinations. The solutions for the exercises are included in the Instructor's Manual and on the disks available only to instructors through their Prentice-Hall representatives. NOTE: Please do not write to us requesting the instructor's manual. Distribution of this publication is strictly limited to college professors teaching from the book. Instructors may obtain the solutions manual only from their regular Prentice Hall representatives. Solutions to many of the exercises are included on the Visual Basic 6 Multimedia Cyber Classroom CD; please see the last few pages of this book for ordering instructions or call 1-800-811-0912 and ask for ISBN# 0-13-083116-6.
Approximately 5150 Index Entries (with approximately 7400 Page References)
We have included an extensive Index at the back of the book. This helps the student find any term or concept by keyword. The Index is useful to people reading the book for the first time and is especially useful to practicing programmers who use the book as a reference. Most of the 2078 terms in the Terminology sections appear in the Index (along with many more index items from each chapter). Students can use the Index in conjunction with the Terminology sections to be sure they have covered the key material of each chapter.
Bibliography
A bibliography is included to encourage further reading. Excellent additional bibliographic information on Visual Basic 6 is available on the World Wide Web. The bibliography includes a summary of the Visual Basic 6 on-line documentation that comes with the Standard, Professional and Enterprise editions of Visual Basic 6 (but which, unfortunately, does not come with the Working Model Edition software included with this book).
Additional Resources for Instructors and Students
We have prepared an Adobe Acrobat PDF-format slide show including all the illustrations, tables, program listings and program output windows in Visual Basic 6 How to Program. We will post regular announcements on our web sites
http://www.deitel.com
http://www.prenhall.com/deitel
about additional instructor and student resources, including errata, FAQs, test banks, syllabi and other forthcoming resources.
A Tour of the Book
Chapter 1: Computers Concepts - discusses what computers are, how they work and how they are programmed. It introduces the notion of structured programming and explains why this set of techniques has fostered a revolution in the way programs are written. The chapter gives a brief history of the development of programming languages from machine languages to assembly languages to high-level languages. The origin of the Visual Basic 6 programming language is discussed.
Chapter 2: Integrated Development Environment - overviews the Visual Basic 6 Integrated Development Environment (IDE) which is used to create Windows programs. The IDE is a graphical environment containing an editor for writing Visual Basic 6 code, a compiler, and a debugger. The Toolbox, Properties window, Project window, form window, tool bars and menus are discussed. This chapter familiarizes students with the IDE. Students are also introduced to the concept of visual programming - the ability to create programs by writing little code and sometimes no code at all.
Chapter 3: Introduction to Visual Basic Programming - gives a concise introduction to writing Visual Basic 6 programs. Detailed discussions of event-driven programming, decision making, arithmetic operations and operator precedence are presented. After studying this chapter, the student will understand how to write simple, but complete, Visual Basic 6 programs.
Chapter 4: Control Structures: Part I - focuses on the program development process. The chapter discusses how to take a problem statement (i.e., a requirements document) and from it develop a working Visual Basic 6 program, including performing intermediate steps in pseudocode. The chapter introduces some fundamental data types and simple control structures used for decision making (If/Then and If/Then/Else) and repetition (While, Do While and Do Until). The chapter uses simple flowcharts to show the flow of control through each of the control structures. We examine counter-controlled repetition and sentinel-controlled repetition. We have had a positive experience assigning problems 4.16 through 4.19 in our introductory courses. Since these four problems have similar structure, doing all four is a nice way for students to "get the hang of" the program development process. Students will enjoy the challenges of the "mystery programs." The more mathematically inclined students will enjoy problems on encryption and decryption and determining how many digits in a five-digit number are 7s.
Chapter 5: Control Structures: Part II - continues the discussion of Visual Basic 6's sequence, selection (Select Case) and repetition (For/Next, Do/Loop While and Do/Loop Until) control structures. This chapter also uses simple flowcharts to show the flow of control through each of the control structures. The techniques discussed in Chapter 4 and Chapter 5 constitute a large part of what has been traditionally taught in the universities under the topic of structured programming. Chapter 5 examines repetition in detail and compares the alternatives of counter-controlled loops and sentinel-controlled loops. This chapter helps the student develop good programming habits in preparation for dealing with the more substantial programming tasks in the remainder of the text. The chapter also introduces logical operators- And (logical AND), Or (logical OR), and Not (logical NOT), constants, and Visual Basic 6 data types. There is a substantial exercise set including mathematical and graphical applications. The more mathematically inclined students will enjoy problems on calculating the trigonometric sine of a number with an infinite series, Pythagorean triples and De Morgan's Laws. Our students particularly enjoy the challenges of triangle-printing and diamond-printing in Exercises 5.16, 5.17 and 5.21; these problems really help students learn to program nested repetition structures - a complex topic to master in introductory courses.
Chapter 6: Sub Procedures and Function Procedures - takes a deeper look at procedures. We explore procedures in depth and include a discussion of procedures that "call themselves," so-called recursive procedures. We discuss Visual Basic 6 procedures, programmer-defined procedures and recursion. The techniques presented in Chapter 6 are essential to the production of properly structured programs, especially the kinds of larger programs and software that application programmers are likely to develop in real-world applications. The "divide and conquer" strategy is presented as an effective means for solving complex problems by dividing them into simpler interacting components. Students enjoy the treatment of random numbers and simulation, and they appreciate the discussion of the dice game of craps that makes elegant use of control structures (this is one of our most successful lectures in our introductory courses). The chapter offers a solid introduction to recursion. Some texts leave recursion for a chapter late in the book; we feel this topic is best covered gradually throughout the text. The extensive collection of exercises at the end of the chapter includes several classical recursion problems such as the Towers of Hanoi; the reader may want to revisit this problem later in the text and employ graphics, animation and sound to make the problem "come alive." There are many mathematical and graphical examples. Our students particularly enjoy the development of a "Computer-Assisted Instruction" system in Exercises 6.19 through 6.21.
Chapter 7: Arrays - explores the processing of data in lists and tables of values. We discuss the structuring of data into arrays, or groups, of related data items of the same type. The chapter presents numerous examples of both one-dimensional arrays and two-dimensional arrays. It is widely recognized that structuring data properly is just as important as using control structures effectively in the development of properly structured programs. Examples in the chapter investigate various common array manipulations, printing histograms, sorting data, passing arrays to procedures and an introduction to the field of survey data analysis (with simple statistics). A feature of this chapter is the discussion of elementary sorting and searching techniques and the presentation of binary searching as a dramatic improvement over linear searching. The 32 end-of-chapter exercises include a variety of interesting and challenging problems such as improved sorting techniques, the design of an airline reservations system, an introduction to the concept of turtle graphics (made famous in the LOGO programming language) and the Knight's Tour and Eight Queens problems that introduce the notions of heuristic programming so widely employed in the field of artificial intelligence. The exercises contain a series of recursion problems including the selection sort, linear search, binary search and quick sort.
Chapter 8: Strings, Dates, and Times - deals with processing words, sentences, characters, groups of characters, dates and times. For each example we provide extensive live-code examples demonstrating appropriate Visual Basic 6 functions "in action." We show output windows so the reader can see the precise effects of each of the string and character manipulations we discuss. Students will enjoy the card shuffling and dealing example (which they will enhance in the exercises). A key feature of the chapter is an extensive collection of challenging string-manipulation exercises related to limericks, text analysis, word processing, printing dates in various formats, check protection, writing the word equivalent of a check amount, Morse Code, card shuffling and dealing, encryption, hangman, cryptograms and metric-to-English conversions. Students will enjoy the challenges of developing their own spell checker and crossword puzzle generator.
ADVANCED TOPICS
Chapter 9: Graphics - begins a run of chapters that present the multimedia "sizzle" of Visual Basic 6. We consider Chapters 9 through 21 to be the book's advanced material. Professors who have been teaching C and/or C++ at the introductory level will find that the Visual Basic 6 topics open all kinds of opportunities to explore new areas. This is "fun stuff." We discuss drawing graphical shapes (e.g., lines, circles, etc.), manipulating colors, images, and printing. The chapter illustrates each of these graphics capabilities with live-code examples, appealing screen outputs, detailed features tables and detailed line art. The exercises challenge students to draw various geometric shapes, manipulate images and create a graphical version of the game of hangman.
Chapter 10: Basic Graphical User Interface Concepts - introduces the creation of applications with user-friendly graphical user interfaces (GUIs). GUI development is a huge topic, so we divided it into two chapters. These chapters cover the material in depth to enable you to build "industrial-strength" GUI interfaces. Through its programs, tables and line drawings, the chapter illustrates GUI design principles, ListBoxes, TextBoxes, ComboBoxes, MaskedEdit controls, scrollbars, Sliders, menus, pop-up menus, and MsgBoxes. Some of the exercises challenge the student to use various controls to format inputs, create GUIs and sort stored strings to facilitate searching. The chapter exercises include a delightful simulation of the classic race between the tortoise and the hare.
A special section entitled "Building Your Own Computer" explains machine-language programming and proceeds with the design and implementation of a computer simulator that allows the reader to write and run machine-language programs. This unique feature of the text will be especially useful to the reader who wants to understand how computers really work. Our students enjoy this project and often implement substantial enhancements; several enhancements are suggested in the exercises.
Chapter 11: Advanced Graphical User Interface Concepts - continues the detailed walkthrough of Visual Basic 6's GUI capabilities. The examples walk the reader through the manipulation of more advanced GUI controls including RichTextBox, UpDown, ImageList, ImageCombo, and FlatScrollBar. Single document interface (SDI) and multiple document interfaces (MDI) are discussed. The chapter concludes with a discussion of native-code compilation. The exercises encourage the reader to develop more substantial GUIs with the advanced components presented in the chapter.
Chapter 12: Mouse and Keyboard - discusses handling mouse and keyboard events. Topics discussed include drag-and-drop, changing the mouse-pointer shape, distinguishing which mouse button was pressed, intercepting key events (from the keyboard) and distinguishing which keyboard key was pressed. The chapter provides several nice examples - including a drag-and-drop example that allows the user to move a Knight chess piece around a chess board.
Chapter 13: Error Handling and Debugging - is one of the most important chapters in the book from the standpoint of building so-called "mission-critical" or "business-critical" applications that require high degrees of robustness and fault tolerance. Things do go wrong, and at today's computer speeds - commonly hundreds of millions of operations per second - if they can go wrong they will, and rather quickly at that. Programmers are often a bit naive about using components. They ask, "How do I request that a component do something for me?" They also ask "What value(s) does that component return to me to indicate it has performed the job I asked it to do?" But programmers also need to be concerned with, "What happens when the component I call on to do a job experiences difficulty? How will that component signal that it has a problem?" In Visual Basic 6, when a component (i.e., a procedure) encounters difficulty, it can "raise an error." The environment of that component is programmed to "handle" that error and deal with it. To use a Visual Basic 6 component, you need to know not only how that component behaves when "things go well," but also what errors that component raises when "things go poorly." The chapter discusses the vocabulary of error handling. The On Error block executes program code that may execute properly or may raise an error if something goes wrong. Associated with an On Error block are one or more handlers that process raised errors and attempt to restore order and keep systems "up and running" rather than letting them "crash." Even if order can not be fully restored, the handlers may perform operations that enable a system to continue executing, albeit at reduced levels of performance - such activity is often referred to as "graceful degradation."
The chapter also introduces the reader to the Visual Basic 6 debugger. We discuss the Debug menu and debug tool bar commands (used to control the debugging session), the Locals window (used to display local variable values), the Watch window (used to view both local and module variables) and the Call Stack window (used to view a list of all the procedures that were called in order to reach the selected line).
Chapter 14: Sequential File Processing - deals with input/output that is accomplished through streams of data directed to and from files. This is one of the most important chapters for programmers who will be developing commercial applications. The chapter introduces the data hierarchy from bits, to bytes, to fields, to records, to files. Next, Visual Basic 6's simple view of files and streams is presented. We show how programs pass data to secondary storage devices like disks and how programs retrieve data already stored on those devices. Sequential-access files are discussed using a series of programs that show how to open and close files, how to store data sequentially in a file and how to read data sequentially from a file. This chapter uses the new FileSystem object model of Visual Basic 6 which allows files, directories and drives to be conveniently manipulated. We also discuss controls for graphically manipulating files, directories and drives.
Chapter 15: Records and Random-Access Files - Random-access files are discussed using a series of programs that show how to sequentially create a file for random access, how to read and write data to a file with random access, and how to read data sequentially from a randomly accessed file. The last random-access program combines many of the techniques of accessing files both sequentially and randomly into a complete transaction-processing program. We discuss the notion of User-Defined Types (UDTs) - Visual Basic's equivalent of records. We explain how these records can be output to, and input from, secondary storage devices. Students in our industry seminars have told us that after studying the material on file processing, they were able to produce substantial file-processing programs that were immediately useful to their organizations. The exercises ask the student to implement a variety of programs that build and process random-access files.
Chapter 16: Object-Oriented Programming - begins our discussion of class modules. The chapter represents a wonderful opportunity for teaching data abstraction the "right way." The chapter focuses on the essence and terminology of classes and objects. What is an object? What is a class of objects? What does the inside of an object look like? How are objects created? How are they destroyed? How do objects communicate with one another? Why are classes such a natural mechanism for packaging software as reusable componentry? The chapter discusses implementing abstract data types (ADTs) as Visual Basic 6 classes, accessing class members, enforcing information hiding with Private instance variables, separating interface from implementation, using access methods and utility methods, and initializing objects. The chapter discusses composition - the process of building classes that have references to objects as members, dynamic memory allocation, interface inheritance, and delegation. The chapter compares inheritance ("is a" relationships) with composition ("has a" relationships). A feature of the chapter is its several substantial case studies. In particular, a lengthy case study implements a point, circle and cylinder class hierarchy. Another lengthy case study implements an employee, boss, commission worker, piece worker and hourly worker class hierarchy.
The chapter explains polymorphic behavior. In object-oriented languages in general, when many subclasses are related through inheritance to a common superclass, each subclass object may be treated as a superclass object. This enables programs to be written in a general manner independent of the specific types of the subclass objects. New kinds of objects can be handled by the same program, thus making systems more extensible. Polymorphism enables programs to eliminate complex Select Case logic in favor of simpler "straight-line" logic. A screen manager of a video game, for example, can simply send a "draw" message to every object in a linked list of objects to be drawn. Each object knows how to draw itself. A new type of object can be added to the program without modifying that program as long as that new object also knows how to draw itself. This style of programming is typically used to implement today's popular GUIs. Visual Basic 6 does not support conventional implementation inheritance (as Java and C++ do, for example), but does allow polymorphism through interface inheritance. The chapter introduces interfaces - sets of methods that must be defined by any class that Implements the interfaces. Interfaces are useful for providing a basic set of methods to classes throughout the hierarchy. A feature of the chapter is its major polymorphism case studies.
The chapter exercises ask the student to discuss several conceptual issues and approaches, work with interfaces, modify the chapter's employee class - and pursue all these projects with polymorphic programming. The exercises also ask the student to compare the creation of new classes by inheritance vs. composition; to extend the inheritance hierarchies discussed in the chapter; to write an inheritance hierarchy for quadrilaterals, trapezoids, parallelograms, rectangles and squares; and to create an automobile hierarchy. Additional exercises challenge the student to develop classes for complex numbers, rational numbers, times, dates, Tic-Tac-Toe, a savings account and sets of integers.
Chapter 17: ActiveX - introduces the student to Microsoft's broad range of distributed computing technologies called ActiveX. The chapter discusses the foundations of ActiveX - Microsoft's component object model (COM), Microsoft's distributed component model (DCOM), and object linking and embedding (OLE).
In previous chapters, the student becomes familiar with using ActiveX controls to create GUIs and to perform other tasks. This chapter carefully demonstrates how to create ActiveX controls. We discuss the types of ActiveX controls that can be created using Visual Basic 6. We also discuss the key events in the lifetime of an ActiveX control.
Two key examples in the chapter create a LabelScrollbar control and digital Clock control. The LabelScrollbar combines a Label control and a scrollbar control. The digital Clock control draws the time on the control every second with the assistance of a Timer control. Each of these controls is written from "scratch."
We also introduce the ActiveX Control Interface Wizard for rapidly creating simple controls and for creating the foundation of more complex controls. We provide a step-by-step example that uses the ActiveX Control Interface Wizard to aid in the creation of the same LabelScrollbar created earlier in the chapter. Special windows, called property pages, that contain a list of properties are also discussed. Many ActiveX controls provide property pages to allow the developer to conveniently set groups of properties. We demonstrate how to create property pages for the LabelScrollbar control using the Property Page Wizard. The chapter also demonstrates how a Visual Basic 6 program can control Microsoft Word through a process called automation. In one example, we create a Word document without explicitly opening Word. In another example we use Word's spelling checker to determine if a word is spelled correctly.
The exercises also ask the reader to create several controls as well as to enhance both the LabelScrollbar and Clock controls.
Chapter 18: Database Management - discusses how Visual Basic 6 can be used to access relational databases. Visual Basic 6 provides a variety of database-aware controls for displaying and manipulating database data. In this chapter we primarily focus on the Microsoft ADO Data control and the Microsoft DataGrid control. The examples in the chapter use the Biblio.mdb sample database provided with Visual Basic 6. For accessing the Biblio.mdb database, we provide an overview of Structured Query Language (SQL). We discuss the Hierarchical FlexGrid control, DataList control and DataCombo controls. We also discuss the Data Environment Designer for rapidly designing and implementing data-driven Visual Basic 6 applications.
Chapter 19: Networking, the Internet and the World Wide Web - deals with programs that can communicate over computer networks. What is a client? What is a server? How do clients ask servers to perform their services? How do servers give results back to clients? What is a URL (uniform resource locator)? How can a program load World Wide Web pages? How can I use Visual Basic 6 to develop collaborative applications?
This chapter gives you what you need to begin implementing client/server networked Visual Basic 6 programs immediately. We show how to write programs that "walk the Web." We discuss manipulating URLs, using a URL stream connection to read a file on a server, establishing simple clients and simple servers using stream sockets, client/server interaction with stream sockets and connectionless client/server interaction with datagrams.
The chapter concludes with a discussion of Visual Basic Scripting (VBScript) for enhancing World Wide Web documents. VBScript is a subset of Visual Basic 6. The chapter has a nice collection of exercises including several suggested modifications to the server examples.
If this is your first Visual Basic 6 book and you are an experienced computing professional, you may well be thinking, "Hey, this just keeps getting better and better. I can't wait to get started programming in this language. It will let me do all kinds of stuff I'd like to do, but that was never easy for me to do with the other languages I've used." You've got it right. Visual Basic 6 is an enabler. So if you liked the ActiveX and networking discussions, hold onto your hat, because Visual Basic 6 will also let you program multimedia applications.
Chapter 20: Multimedia: Images, Animation and Audio - deals with Visual Basic 6's capabilities for making computer applications come alive. It is remarkable that students in first programming courses will be writing applications with all these capabilities. The possibilities are intriguing. Imagine having access (over the Internet and through CD-ROM technology) to vast libraries of graphics images, audios and videos and being able to weave your own together with those in the libraries to form creative applications. Already more than half the new computers sold come "multimedia equipped." Within just a few years, new machines equipped for multimedia will be as common as machines with floppy disks today. We can't wait to see the kinds of term papers and classroom presentations students will be making when they have access to vast public domain libraries of images, drawings, voices, pictures, videos, animations and the like.
A "paper" when most of us were in the earlier grades was a collection of characters, possibly handwritten, possibly typewritten. A "paper" in just a few short years will become a multimedia "extravaganza" that makes the subject matter come alive. It will hold your interest, pique your curiosity, make you feel what the subjects of the paper felt when they were making history. Multimedia will make your science labs much more exciting. Textbooks will come alive. Instead of looking at a static picture of some phenomenon, you will watch that phenomenon occur in a colorful, animated, presentation with sounds, videos and various other effects. It will leverage the learning process. People will be able to learn more, learn it in more depth and experience more viewpoints.
The chapter discusses images and image manipulation, audios and animation. A feature of this chapter is an example that uses the Microsoft Agent control which allows the user to choose one of three predefined characters - Merlin, Genie and Robby the Robot. These characters actually speak and move (e.g., Robby the Robot removes his head and fixes himself with a screwdriver). Another key example of this chapter is the Multimedia MCI control - which we use to create a CD player and an AVI file player. We demonstrate the RealAudio control for receiving streaming audio and video from the Internet. We also demonstrate the Marquee control for scrolling an image from a specified URL. The chapter concludes with a discussion of the ActiveMovie control which enables an application to play video and sound in many different formats (i.e., MPEG, AVI, WAV, etc.).
Once you have read the chapter, you will be eager to try out these techniques, so we have included extensive exercises to challenge and entertain you; many of these make interesting term projects:
7 Programs That Cannot Be Created/Executed Using This Software | ||||
Chapter | Figure | Problem | ||
Chapter 17 | 17.2 | Requires Microsoft Word to be installed with Service Release 1 (SR-1). | ||
Chapter 17 | 17.15, 17.33, 17.34, 17.45 | These work correctly, but may issue various error messages when the projects are loaded into the Visual Basic 6.0 Working Model. Simply dismiss the dialogs that are displayed. | ||
Chapter 17 | 17.47 and 17.50 | Visual Basic 6.0 Working Model does not allow the programmer to create ActiveX DLLs. | ||
Chapter 17 | 17.52 and 17.54 | The ActiveX features of these examples are only available in the Professional and Enterprise editions of Visual Basic. | ||
Chapter 17 | 17.55 | The ActiveX features of this example are only available in the Professional and Enterprise editions of Visual Basic. | ||
Chapter 18 | 18.19 | The Data Environment Designer is only provided with the Professional and Enterprise editions of Visual Basic. | ||
Chapter 20 | 20.1 | Microsoft Agent must be installed before this program can execute. Refer to the discussion in the text for more information on downloading Microsoft Agent. | ||
Chapter 20 | 20.9 | The Animation control is only provided with the Professional and Enterprise editions of Visual Basic. |