| ||
|
If you click on the tab in the connect property for a data control there is a drop down list of all the types of databases you can connect to. Way down at the bottom is Text;. There is little documentation to assist you with this choice. Surprisingly it allows you to manipulate simple text files like you would a database.
The immediate advantage is the size of the database. Where most database sizes start at around 50,000 bytes, this database may be only a few hundred bytes! This may be desirable when you wish to backup, copy, or send it over the internet. Text Databases are also referred to as Comma Separated Values or CSV. | ||
| There is one great drawback to Text Databases. Although you can easily add new records, you can not edit previous records. | ||
|
One fundamental concept to understand is that your text file will be a single table. The second thing is that the first line of the file will describe the fields. Each subsequent line of the file will be a record with fields (corresponding to the first line describing the fields).
Accordingly, apply these princlples and create a database with Notepad ** | ||
| ||
| You have just created the database! It will have three fields for you to keep track of phone numbers for people. If you wanted to create an Access database, you would need to own a copy of Access or use rather complicated code such as in Demo 6. This is the other advantage of a simple text database. | ||
| ||
|
Now go to the Properties Window and select Data1. Find the property called Connect. Click the tab and choose Text; at the bottom.
Next find the property named DatabaseName. When you click the tab you will be allowed to browse to find a database. Choose the phoneno.txt file that you just saved with Notepad. Finally find the property named EOFAction. Click the tab and choose 2 - Add New. | ||
|
Now connect each Textbox to Data1.
To do this find the DataSource property of each Textbox. Click on the tab and choose the Data1 control from the dropdown list. | ||
|
Now connect each Textbox with a field in the database.
To do this find the DataField property of each Textbox. Click the tab for each Textbox and choose one of the three fields for each. | ||
| That is all there is to it! You don't have to write any code! | ||
** You can also create the same database with the following code:
Private Sub createTxt()
Dim f%, fname$
fname = "phoneno.txt"
If Dir$(fname) <> "" Then Exit Sub
f = FreeFile
Open fname For Output As f
Write #f, "FirstName", "LastName", "PhoneNo"
Close f
End Sub
|