![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Listing 19.12 The List Forms Load event procedure. Private Sub Form_Load() Dim i As Integer, buf As String When the form loads, go through the entire database file reading each record and adding it to the list box. For i = 1 To NumberOfRecords Get #FileNum, i, CR buf = RTrim$(CR.LName) buf = buf & , & RTrim$(CR.FName) buf = buf & & RTrim$(CR.Address) buf = buf & , & RTrim$(CR.City) buf = buf & & RTrim$(CR.State) buf = buf & & RTrim$(CR.Zip) List1.AddItem buf Next i End Sub The final item is the Resize event procedure shown in Listing 19.13. Code in this procedure sets the size of the List Box to fill the form, a familiar technique. Listing 19.13 The List Forms Resize event procedure. Private Sub Form_Resize() Make the list box the same size as the form. List1.Left = 0 List1.TOP = 0 List1.Width = frmList.ScaleWidth List1.Height = frmList.ScaleHeight End Sub Additional Features For The Address DatabaseOur address database works pretty well. We can enter new addresses, view and edit existing ones, and so on. After you use it for a short time, however, the shortcomings will become apparent. The most important feature it lacks, at least in my mind, is the ability to search for records based on a persons name. You certainly dont want to scroll through several hundred addresses just to find one. The ability to print envelopes would be nice, too, as would fields for additional information, such as phone numbers. A more serious drawback is the way the program handles deleted records. When you delete a record, the program does not actually remove that record from the file. Rather, as was shown in Listing 19.4, it simply erases the contents of the records fields. The blank record still takes up space in the file and will still display as we scroll through the database. There are several approaches we can take to solve this problem:
I leave these improvements to you, if you are interested. Remember, the purpose of this program is to show you how to create a database program without using Visual Basics specialized database tools. This may be the old way of doing it, but remember that I am not using old in a pejorative sense. Just because it is the old way does not automatically make it inferior to the new way. Now that you know how it is handled, you can make up your own mind. Using Visual Basics Database ToolsIf you do not want to program your database application from scratch, you can use Visual Basics tools to simplify your task. In fact, Visual Basics database toolbox contains an embarrassment of riches; sometimes, the problem faced by a new programmer is trying to figure out all of the ways that Visual Basic can do database programming. That, however, is a topic for Chapters 21 and 22. For the present, I want to show you the fundamentals of using the specialized database tools in a program. Once you have the basics under your belt, you will be ready to take on some more advanced database topics in later chapters. The Jet database engine is your highly skilled database programming assistant. In this context, the term engine is not used to mean a source of poweras in an automobile enginebut rather a mechanism or device. The Jet database engine sits between your Visual Basic program and the database file that contains the records. The program pulls levers and pushes buttons on its side of the engine, and the gears, cams, and springs in the engine go to work and perform the requested action on the database. The result, if requested, pops out of a slot ready for program use. Of course, pulling levers and pushing buttons means sending commands, but the basic idea is the same. We tell the engine what we want to accomplish, and the engine worries about how to do it. Part of the beauty of this system is the ability of the database engine to work with several different kinds of databases, including those shown here:
In other words, we can write a Visual Basic program to manipulate data in any of these database formats. Of course, all types of databases use the same logical file-table-record-field format, but each type of database file uses its own proprietary method of storing the data and its related information. The Jet database engine translates your programs requests into the specific commands required by the database file format in use. The Jet database engine that Visual Basic uses is actually the same one used by Microsofts Access database program. A Visual Basic program can interact with a database on two levels:
The second level is considerably more complicated to program, and we will not pursue it further in this book. The first approachwhere the database structure already exists and is fixedis by far the most useful and the one you will encounter most often. The database that our Visual Basic program will manipulate must already exist. It may be a clients database that contains thousands of records, or it might be a brand-new database created as part of the program development process. A new database can be emptythat is, contain no databut its table and record structure must be defined. How do you, the Visual Basic developer, create a database to be used by your program? You use a tool provided with Visual Basic, called the Visual Data Manager, or VisData. You start the Visual Data Manager from the Add-Ins menu. VisDatas four main functions are to:
Visual Data Manager is a programmers tool that is part of Visual Basic. It is not something you distribute with your applications. Ill show you how to use VisData in Chapter 21.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |