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.

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

to Example 1, the program will find the database when it is located in the same<br />

folder as the program. The assignment made in the Form_Load event procedure<br />

will override any setting made in the Properties window. (The setting in the<br />

Properties window even can be left blank.) The programs for Section 11 on the<br />

CD accompanying this textbook contain the above Form_Load event procedure.<br />

2. You will most likely alter the file MEGACTY1.MDB while experimenting with<br />

the data control or running the program in Example 1. You can always obtain a<br />

fresh copy of MEGACTY1.MDB by recopying it from the CD.<br />

3. You can prevent the user from altering the data in a table by setting the Read-<br />

Only property of its data control to True.<br />

4. The following controls can be bound to a data control: text box, check box,<br />

image, label, picture box, list box, combo box, data bound list box, data bound<br />

combo box, <strong>and</strong> FlexGrid.<br />

5. A form can contain more than one data control.<br />

6. Some entries in a table can be empty. For instance, in the Cities table, if the<br />

2015 projected value is not known for a particular city, it can be omitted.<br />

7. Do not use a method such as Move, Delete, or AddNew inside the Validate event<br />

procedure. Otherwise, an infinite loop will occur.<br />

8. Field names can be up to 64 characters in length <strong>and</strong> can consist of letters, numbers,<br />

<strong>and</strong> spaces. If spaces are used in a name, then the name must be enclosed<br />

in brackets when used in <strong>Visual</strong> <strong>Basic</strong>.<br />

9. Both tables in the database MEGACTY1.MDB have fields called country. If<br />

there is ever any question about which is being referred to, we can distinguish<br />

them by using the two (full) names Cities.country <strong>and</strong> Countries. country.<br />

10. In the MEGACTY1.MDB database, the values in the field city are all of data<br />

type String <strong>and</strong> the values in the field pop1995 are all of data type Single. We<br />

say that field city has type String (also known as Text) <strong>and</strong> the field pop1995<br />

has type Single. Two other common data types are Date/Time <strong>and</strong> Boolean (also<br />

known as Yes/No).<br />

11. When a field is first created, a type must be specified. When that type is String<br />

(or Text), a maximum length must also be specified. In the MEGACTY1.MDB<br />

database, the fields city <strong>and</strong> country have maximum length 20 <strong>and</strong> the field currency<br />

has maximum length 10.<br />

12. The database MEGACTY1.MDB was created with <strong>Visual</strong> Data Manager, which<br />

has the same format as Access. When the database to be used has been created<br />

with other software, such as FoxPro 3.0 or dBase 5.0, then the walkthrough<br />

requires an additional step. Namely, between Steps 3 <strong>and</strong> 4, the Connect property<br />

of the data control has to be set to the name of the software product. (This<br />

step was not necessary in our case because Access is the default software.)<br />

Note: Access database file names end with .MDB, which is an abbreviation for<br />

Microsoft Data Base. Btrieve, FoxPro, dBase, <strong>and</strong> Paradox database file names<br />

end with .DAT, .DBF, .DBF, <strong>and</strong> .DB, respectively.<br />

11.2 RELATIONAL DATABASES AND SQL<br />

■ PRIMARY AND FOREIGN KEYS<br />

A well-designed table should have a field (or set of fields) that can be used to uniquely identify<br />

each record. Such a field (or set of fields) is called a primary key. For instance, in the<br />

Countries table of Section 11.1, the country field is a primary key. In the Cities table, because<br />

we are only considering very large cities (of over 1 million population), the city field is a pri-

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

Saved successfully!

Ooh no, something went wrong!