Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Database Basics
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
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!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
Publication Date: 08/01/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
Part 5Database Programming
Chapter 19Database Basics
One of the most outstanding features of Visual Basic is the powerful assortment of database programming tools it provides. In this chapter, well start examining these tools.
If you surveyed all the computers in the world, what kind of program would be running most often? Not games, not word processors, but database programs. When a long distance company calls to pitch its service, the agent uses a database program. When someone sends an order for elk-lined pajamas to L.L. Bean, the order goes into a database program. When the clerk at the auto parts store checks to see whether they have a left-handed cam inverter for your 1971 Ford Falcon, he or she uses a database program. Wherever information needs to be managed, you usually find a database program at work.
A good percentage of those programs were created with Visual Basic. Recognizing that database programming is in great demand, Microsoft wisely included a slew of powerful database tools in Visual Basic. The Basic language itself has all the features you need to create a simple database program from scratch, as youll see in the early part of this chapter. Visual Basic also includes some specialized database tools that permit you to create sophisticated user interfaces and access a variety of standard database file formats, all with relatively little programming.
Well look at some of Visual Basics database tools later in the chapter. First, we need to get some basics under our belt.
So, Whats A Database?
A database is a collection of information, or data, arranged in a particular manner. The basic unit of information in a database is called a record. Each record in a database contains two or more fields that hold specific types of information. Perhaps the most common example of a database is an address list. Each entry in the database constitutes one record: an individuals name and address information. Each record in the database contains fields that hold separate items of information: first name, last name, address, city, and so on. These fields are the same for every record in the database, and they are assigned names identifying the data they contain.
A database is sometimes displayed in row and column format. Each row contains one record, and each column contains one field, as illustrated in Figure 19.1. In this case, a single record can be referred to as a row, and an individual field as a column. The entire collection of records is called a table. Some databases contain more than one table, with the records in each table having a different field structure. We will deal with multiple-table databases in later chapters; for now, well stick to single-table databases.
A database program is designed to let you work with the information in a database. Some capabilities are common to any database programadding, finding, and deleting records, for example. Many other capabilities are customized to fit a specific program. In an address list database, for example, you may want the ability to print envelopes and sort the records by ZIP code. A graphics database might need the ability to input and store images from a scanner. The possibilities are endless. If you write database programs as part of your job, you never know what someone might ask you to do next. Heres one of the advantages of Visual Basic: As a full-featured programming language, it offers the flexibility to build many capabilities right into the database program. Thanks to its database tools, most of the fundamental database tasks are simple to accomplish.
Figure 19.1 A database table has one row per record and one column per field.
Doing It From Scratch
Before Visual Basic had specialized database tools, programmers had no choice but to create all of the programs functionality by using Visual Basics standard controls and the Basic language. Many database programs were created this way. This approach is still possible, but the practice of programming database applications from scratch is a lot less common. Still, you should know the process for a couple of reasons. For certain relatively simple database tasks, the old methods are more than adequate and provide a smaller, faster program that avoids the overhead associated with the specialized data access tools. Later in the chapter, when I cover the Jet database engine (one of Visual Basics database tools), Ill explain some of the factors to consider when deciding upon the best approach. In addition, learning how to create a database program without using the specialized tools will teach you some valuable programming techniques.
The program well develop in this section is a bare-bones address list. Its not something you would actually use to keep track of names and addresses, because its lacking a number of features that most people would consider essential. It demonstrates the fundamentals of roll-your-own database programming, however, as well as several other Visual Basic techniques. After you complete this project, youll have a basic, but perfectly functional, program that you can enhance as needed.
Planning The Database
What features do we want in the address-list program? Most fundamental, of course, is keeping track of peoples address information. The first step is to define a data structure to hold the required information, as shown here:
Type Address
FName As String * 20
LName As String * 20
Address As String * 40
City As String * 15
State As String * 2
Zip As String * 5
End Type
The user-defined Address type gives us a place to store address information while the program is running. It also defines the structure of the random access file used for disk storage of the database information. We reviewed the relationship between a user-defined type and random access files in Chapter 13; now, well see them in action.
The program should have the basic features of viewing records, adding new records, deleting records that are no longer needed, and editing existing records. Well also add the ability to display an alphabetical list of all records. A number of other features are possible, but lets stop here. We want the project to be manageable. Later, Ill describe some other features you might want to add.
Figure 19.2 The completed address database form.
Designing The Form
The address form needs one Text Box for each of the six pieces of information, or fields, that every address record will contain. Each Text Box also requires an identification label. Command Buttons arranged in two control arrays of four buttons each will permit the user to enter commands. Start a Standard EXE project and place these controls on the form. The completed form, which is saved as ADDRESS.FRM, is shown in Figure 19.2. The upper row of Command Buttons is assigned the Name property of cmdAction, with Index properties zero to three, from left to right. The lower set of Command Buttons is named cmdMove and has the same Index properties as cmdAction. The full description of this forms objects and properties is given in Listing 19.1. Save the project under the name ADDRESS.
Previous
Table of Contents
Next
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.
Wyszukiwarka
Podobne podstrony:
kodeks wykroczeń 19,01,2015KNR 19 01Kodeks Drogowy 19,01,2015 rĆwiczenia 4 19 01 2014TurboPascal 19 01 2010 TP PLIKIgenetyka test 1 19 01 2009odpowiedzi do egzaminu 19 01 2010Diskoteka 2015 Dance Club Vol 134 (19 01 2015) Tracklista19 01 Wymagania BHPMaliki zaprzecza że sunnici będą wykluczeni z wyborów (19 01 2010)TERMAQ G 19 01 NOWY100 Ibiza Dance 2015 (19 01 2015) TracklistaĆwiczenia 14 19 01więcej podobnych podstron