19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

324 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

TABLE 11.2<br />

Countries<br />

Country pop1995 currency<br />

Brazil 155.8 real<br />

China 1185.2 yuan<br />

India 846.3 rupee<br />

Indonesia 195.3 rupiah<br />

Japan 125.0 yen<br />

Mexico 85.6 peso<br />

Nigeria 95.4 naira<br />

Russia 148.2 ruble<br />

USA 263.4 dollar<br />

Source: An Urbanized World—Global Report on Human Settlements 1996, a report presented at Habitat<br />

II, a UN conference on the world’s cities held in Istanbul in June 1996.<br />

A database (or relational database) is a collection of one or more (usually related)<br />

tables that has been created with database management software. The best known dedicated<br />

database management products are Access, Btrieve, dBase, FoxPro, <strong>and</strong> Paradox. Every<br />

version of <strong>Visual</strong> <strong>Basic</strong> 6.0 can manage, revise, <strong>and</strong> analyze a database that has been created<br />

with one of these products. Section 11.3 shows how to create a database with <strong>Visual</strong> Data<br />

Manager, a miniversion of Access that is supplied with <strong>Visual</strong> <strong>Basic</strong>. Section 11.3 also gives<br />

a code template for creating a database programmatically.<br />

The databases used in this chapter can be found in the collection of files accompanying<br />

this text. The database files have the extension .MDB. For instance, the file MEGAC-<br />

TY1.MDB is a database file containing the two tables presented on the preceding page.<br />

(Note: MDB files should be copied from the CD onto a hard drive <strong>and</strong> accessed from the<br />

hard drive.)<br />

THE DATA CONTROL<br />

<strong>Visual</strong> <strong>Basic</strong> communicates with databases through the data control. Data controls can read,<br />

modify, delete, <strong>and</strong> add records to databases. The following walkthrough uses a data control<br />

to connect <strong>Visual</strong> <strong>Basic</strong> to the database MEGACTY1.MDB.<br />

■ A DATA CONTROL WALKTHROUGH<br />

1. Press Alt/File/New Project <strong>and</strong> double-click on St<strong>and</strong>ard EXE.<br />

2. Double-click on the data control icon. Set its Name property to datCities <strong>and</strong> its<br />

Caption property to Cities.<br />

3. Stretch it horizontally to see the caption Cities.<br />

4. Select the DatabaseName property <strong>and</strong> set it to the filespec for the file<br />

MEGACTY1.MDB.<br />

An Open File dialog box will help you locate the file.<br />

5. Select the RecordSource property <strong>and</strong> click on the down-arrow button at the<br />

right of the Settings window.<br />

The names of the two tables in the database, Cities <strong>and</strong> Countries, are displayed.<br />

6. Select Cities.<br />

7. Place a text box, txtCity, on the form.<br />

Text boxes are said to be data-aware because they can be bound to a data control<br />

<strong>and</strong> access its data.<br />

8. In the Properties window, select the DataSource property of txtCity.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!