|
Click Here! |
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
IntroductionIn recent years Visual Basic has revolutionized Windows programming. By handling many of the tedious details of Windows programming, Visual Basic allows developers to focus on more application-specific tasks. Despite the fact that Visual Basic handles the more mundane Windows programming details, few books cover sophisticated programming methods. Books that do mention advanced concepts do so only briefly, and they often demonstrate complicated techniques with over-simplified examples. For instance, the Scribble application for drawing a simple freehand picture using the mouse is often used to demonstrate such concepts as SDI and MDI interfaces, saving and loading data in files, common dialogs, drawing attributes, and even object-oriented data structures. The Scribble application may teach important lessons, but it provides little help in solving real-world problems because very few real applications call for freehand drawing. The reader is left to decide how to apply the lessons learned to solve real programming problems. By providing complete solutions to realistic problems, Advanced Visual Basic Techniques goes farther than other Visual Basic texts. A book can stretch artificial examples like Scribble only so far. It would be difficult to extend Scribble to reasonably demonstrate client/server architectures, storage of bitmaps for database applications, and Web browsing. By giving separate solutions to a variety of realistic problems, Advanced Visual Basic Techniques can explain all of these techniques within meaningful contexts. Advanced Visual Basic Techniques bridges the gap between programming technique and real-world applications. It provides working solutions to a selection of realistic problems that you might actually want to solve, and, in the course of explaining the solutions, it demonstrates advanced programming concepts that you will find in few other Visual Basic programming books. What You Will GainThis book and its compact disk will provide you with the following:
If you are not already an experienced Visual Basic application developer, you will be one by the time you have studied all the sample applications. Armed with an arsenal of powerful implementation techniques, you will be prepared to attack the most complex development problems. Intended AudienceThis book covers intermediate and advanced Visual Basic application programming topics. It does not teach the Visual Basic language itself. If you have a good understanding of the fundamentals of Visual Basic, you are ready for the applications and advanced techniques in this book. If you do not know how to place controls on a form, write an event handler to respond to a command buttons Click event, or run a Visual Basic program, you might want to brush up on the basics a bit before proceeding. Even if you have not yet completely mastered Visual Basic, you will be able to understand and run the applications. With occasional references to your Visual Basic manuals, you will be able to modify the examples to build similar applications of your own. By the time you have finished exploring all of the examples, you will have become an experienced Visual Basic application developer. How to Use This BookYou might take a couple of different approaches to using this book. Naturally, you can read the book from front to back, studying each chapter in turn. This will give you a broad introduction to many powerful application implementation techniques. You will then be able to incorporate those techniques into your own Visual Basic applications. A second approach is to pick a chapter that describes an application similar to one you want to build. Then you can study that chapter and modify the application to suit your particular needs. If you want to conduct a survey using a Web page, for example, you could move immediately to Chapter 18. The WebSurvey application described there provides a framework you can use to conduct your survey. With a few modifications you will be running your survey in no time. The later section How this Book Is Organized describes each of the sample applications so that you can find the one that best fits your particular needs. Each chapter begins with a description of the application explained in that chapter. Each also includes a Key Techniques section listing the main concepts and programming methods described in that chapter. A third strategy for using Advanced Visual Basic Techniques is to select a technique or concept you would like to use in your applications. You can then learn more about that technique by studying the corresponding sample applications. For example, you might want to add a recent file list to your drawing application. The ExpenseReporter application described in Chapters 1 and 2 uses a recent file list. By reading the appropriate sections in Chapter 1, you can learn how to add this feature to your application. Finally, each of the applications described in this book was selected for its easy usability. You will probably find at least one or two that you can use as they are written. For example, the PropertySetter, Aligner, Scroller, and AddInMaker applications described in Chapters 4 through 7 are handy tools that make Visual Basic programming easier. You can add these applications to the Add-Ins menu of your Visual Basic development environment and take advantage of their power even if you do not examine their code in detail. How This Book Is OrganizedThe chapters presented later in the book are generally more advanced than those at the beginning. You may think the earlier chapters are less state-of-the-art, but they are not necessarily less complicated or less difficult to understand. For example, Chapters 1 and 2 describe a single-document interface application. Putting all of the finishing touches on even a simple application can be quite difficult. It is no trivial task to give this application recent file lists, help, context-sensitive help, scrolling regions, printing, printer control, print previewing, field validations, and all of the other features needed by a professional-quality application. The chapters are arranged so that they do not depend on your having read the earlier material. This means you can read the chapters in any order you like. The exception to this rule is Chapter 2, which continues the discussion of the ExpenseReporter application described in Chapter 1. Chapter 1 explains ExpenseReporter from the users point of view. Although the concepts explained in Chapter 2 do not require that you understand all of Chapter 1, they will make more sense if you have read at least the beginning of Chapter 1. Applications later in the book may use techniques described earlier without any explanation. For example, several applications provide some form of help, but help systems are described only in the first few chapters. When you are working with an application, if you come across a topic that was covered earlier, you can always go back to the previous chapters to learn more. The chapters in Advanced Visual Basic Techniques are divided into five parts. Part IApplication BasicsThe applications described in these chapters cover basic techniques that are common in many Visual Basic applications. Some concepts, such as help and context-sensitive help, are essential for any successful application. Others, including object-oriented input and output, are useful in a wide variety of circumstances.
Part IIProgramming ToolsThese applications implement useful programming tools. You can add them to your Visual Basic development environments Add-Ins menu and use them to make routine programming tasks easier. In addition to providing you with helpful tools, these applications show how you can create other programming aids to automate mundane programming chores.
Part IIIDatabasicsPart III contains database applications that run on the same computer that holds the database. Using a database, your applications can easily manage large amounts of complex data. A database also allows multiple applications to use the same data in different ways without interfering with each other.
Part IVClient/Server ApplicationsPart IV includes client/server applications. In a client/server application, one program, the server, provides some sort of service for another application, the client. Client/server applications allow a system to distribute functionality across a network to provide features such as improved performance and centralized resource management.
Part VActiveXActiveX is a specification that describes how objects should interact with each other. Because Visual Basic 5 complies with the ActiveX standard, it allows a programmer to build new objects that were not possible before. These objects include controls created from other controls. The chapters in Part V explain how to create ActiveX controls that can be used in Visual Basic projects or applications written in other languages.
Part VISpinning the WebThe World Wide Web allows millions of computer users to visit a multitude of different computers effortlessly. On those computers, visitors can find a practically limitless number of pages of multimedia information. The applications presented in Part VI deal with creating and manipulating Web pages in Visual Basic.
ApproachMost Windows programs are event-driven. The computer spends most of its time sitting around waiting for the user to do something that will send the program into action. When the user presses a command button, selects a menu item, or adjusts the value of a scroll bar, the program briefly awakens. It performs some task and then lapses back into hibernation to await the users next command. This sort of design makes an application responsive to the users needs, but it can make the application design harder to explain. Simple diagrams such as flow charts cannot adequately represent the programs architecture. Because the application spends most of its time idle, there is little control flow to diagram. Other constructions, such as entity-relationship (ER) diagrams, can describe relationships among classes and certain other large-scale objects, but they do not explain how event-driven programs work. It is probably more productive to think of a typical Windows program as a collection of user interface elements tied to underlying code. A form contains command button, menu, and list box controls. There is often little or no meaningful relationship among these controls. It makes no sense to think of one command button as a child of another. It also makes little sense to think of a menu item passing control to a list box. Generally, the user interacts with a control, and that control invokes some Visual Basic source code. It is the controls themselves and the underlying code that define the applications architecture. The chapters that follow focus on the code behind the controls. Each chapter begins by explaining what its application does from the users point of view. It then gives a list of the key techniques demonstrated by the underlying code behind the controls. The sections that follow describe those key concepts. Note that the concepts do not always match one-to-one with the controls. For example, the ExpenseReporter application described in Chapter 1 contains many fields that contain numbers. This application uses field validation functions to ensure that the user enters only valid numeric values in those fields. In this case, a single set of field validation routines can manage user input for dozens of different text boxes. An applications controls function independently, but the underlying key concepts are often coupled. For example, the functions that implement recent file lists are closely related to the subroutines that load, save, and create new files. Because there is no clear flow of control among these subroutines, you may need to read about them all to get a clear understanding of how they fit together. This book describes only pieces of code that are particularly interesting or confusing. Control placement and source code that is straightforward are not described here. You can find the complete source code for every application on the accompanying compact disk. See the section Using the Compact Disk for instructions on loading the source code from the disk. Equipment You Will NeedTo run and modify the example applications, you need a computer that is reasonably able to run Visual Basic 5.0. A 486-based computer running Microsoft Windows 95 or Windows NT will work. You will also need a compact disk drive to load the programs from the accompanying compact disk. The client/server applications described in Chapters 10 through 13 use more advanced networking and OLE server techniques that work only in the Visual Basic Enterprise Edition under Windows 95 and Windows NT. The ActiveX applications presented in Chapters 14 through 19 use features introduced in Visual Basic 5. If you do not have the Enterprise Edition, or if you are running an older version of Windows, some of these applications will not run as they are presented in the book. You can still read the chapters and learn valuable lessons about the application architectures. Using the fundamental architectures and some file management tricks, you can even implement similar applications without using OLE servers. This is a hard route to follow, however, and you may be better off if you upgrade your software and save yourself a lot of time and trouble. All the applications on the CD, except the programs in Chapter 13, have been tested in Visual Basic 5.0 under Windows 95 and Windows NT. The programs explained in Chapters 1, 2, and 4 through 13 were also tested using 32-bit Visual Basic 4.0. Though the programs may look slightly different in the two environments, they will perform in roughly the same manner. The applications described in Chapters 3 and 14 through 19 use features introduced by Visual Basic 5.0 so they will not run with earlier versions of Visual Basic. The applications will run at different speeds on different computers with different configurations, but they will all work. If you own a 200 megahertz Pentium with 64MB of memory, applications will run much faster than they would if you owned a 486-based computer with 8MB of memory. Both machines will be able to run the applications, but at different speeds. You will quickly learn the limits of your hardware. Using the Compact DiskThe accompanying compact disk contains Visual Basic source code for all the applications described in the book. The files on the compact disk are separated by chapter. Code for the PeopleWatcher application described in Chapter 8, for example, is stored in the Ch8 subdirectory. Some chapter directories contain subdirectories that hold data or different programs described within the chapter. You can load the example programs into the Visual Basic development environment using the Open Project command in the File menu. You can select the files directly from the compact disk, or you can copy them onto your hard disk first. Note that files on a compact disk are always marked read-only because you cannot save files to a compact disk. If you copy files onto your hard disk, the copies are also marked as read-only. If you want to modify these files, you must give yourself write permission for them: this is particularly important for database files because the database programs will not run if their databases cannot be accessed. You can do this with the Windows Explorer. First, copy the files you want onto your hard disk. Then select the files and invoke the Properties command in the Explorers File menu. Uncheck the Read Only check box and press the OK button. At this point, you can make changes to the copied application and save the changes to your hard disk. Do not worry about making careless changes to the copy and accidentally breaking the application. You can always restore the original versions from the compact disk.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.
|