Dec 222017
 
Sample database and index routines in Qbasic 4.5.
File DATABA.ZIP from The Programmer’s Corner in
Category BASIC Language
Sample database and index routines in Qbasic 4.5.
File Name File Size Zip Size Zip Type
DATABASE.BAS 29376 7669 deflated
DATABASE.DOC 6980 2764 deflated
TPCREAD.ME 199 165 deflated

Download File DATABA.ZIP Here

Contents of the DATABASE.DOC file








DATABASE.BAS
MicroComputer Services
Jose Garcia
PO Box 580 Dauphin, PA 17018
(717)921-8764
CIS user number 71211,124


DATABASE.BAS is a simple name/address database program to demonstrate
the text entry, record selection (by means of a bounce bar) and index
routines that I have written. It was written with version 4.5 but will
run in version 4.0 as well. QuickBASIC MUST BE STARTED WITH THE /AH
PARAMETER - in other words for this program to work properly you MUST
start QuickBASIC by typing QB /AH (more on this later). Any of the code
can be used by other programmers but I ask that the comments be left
intact. The program creates a database record file, names.dat and an
index file, names.ndx in the default directory. If you have questions,
comments or improvements concerning the code please drop me a line -
either U.S. mail or CIS. I will reply as soon as my schedule permits.

I originally wrote DATABASE.BAS to demonstrate the txt.edit routine that
I had written. As I started DATABASE.BAS I realized that I needed a
program that would emulate some common dBASE procedures. Thus,
DATABASE.BAS grew to it's present size. It is not perfect and I hope that
programmers who download this file will improve the coding and let me
know the improvements made to the routines contained in DATABASE.BAS.


The comments in the coding should help to explain what is happening and
I will add to that now. To begin with, the TXT.EDIT routine is completely
generic and can be used in other programs or compiled and used from
within a QB library. All that needs to be done is to dimension a
temporary array to hold the fields declared in the TYPE statement, make
each element in the array represent one of those fields. Then call
TXT.EDIT (arrayname), (starting screen row), (starting screen column),
(flag, - 0 or 1, where 0 is overtype mode and 1 is insert mode). The
routine will continue until all array elements (fields) have entries or
's. Then the array elements are switched back to the TYPE variables
to be used by the rest of the program.

The GETNAME routine can be used in other programs if the screen locations
(LOCATE) are changed to accommodate your program and the TYPE variables
are changed to your names. BORDER, HIGHLIGHT, LOWLIGHT, PAUSE and
BOX routines will have to be included. It allows the user to choose a
record entry easily by using the arrow keys, highlighting the record
desired and pressing . It eliminates the errors caused by users
having to type in the names of record entries and making typographical
errors.




The DB.INDEX routine called in the ON ERROR routine is used if the
database file contains records but the index file is missing. It can be
used to restore a corrupted index file or to build an new index file using
the records contained in the data base. Note: it only works with database
files created by QuickBASIC programs, it will not work with Ashton-Tate's
dBASE version database files (.DBF). Your code will have to be changed
to use your TYPE'd variable names, database record filename and your
index filename in the DB.INDEX, OPENINDEX, REINDEX and UPDATENDX
routines. The index file is read and entered into a dynamic array at the
start of the program. All updates to the index are made to the memory
array and are not written to file until the program exits normally (by
using 5 at the main menu or arrowing down to QUIT and pressing .
NOTE:If records are added to the database record file while running in the
QuickBASIC environment and you "BREAK" out of the program
instead of QUITing with choice 5 on the menu, the index file will not be
updated and you will get an error the next time you run the program.
Always QUIT the program through the menu. Else DEL NAMES.NDX to fix.
The new index is then written to disk and will be ready for the next
session. The index array is stored dynamically in the far heap and
outside of the 64K BASIC boundary for variables (DGROUP) so that arrays
larger than 64K can be used (this would happen in large commercial
applications). To ensure correct operation of the DB.INDEX, OPENINDEX,
REINDEX and UPDATENDX routines, QB MUST be started with QB /AH.
Also, use the /AH switch when compling from the command line with BC.

The menu routine is "borrowed" from Frank Neal, it is a popular menu
bounce-bar routine. For it to work, the variables choice% and np% MUST
be dimensioned as shared with a DIM SHARED choice%, np% statement.
Where choice% is the variable that returns the users menu choice and np%
is the variable that contains the number of menu choices, also the number
of elements in the array m$ should be dimensioned, but is not necessary.

The DELETE routine is of interest because of the method used in deleting
records. When a record is deleted, the DELETE routine simply adds an
ASCII 20 (the paragraph symbol) as the first character in the field being
indexed. When records are displayed, any record beginning with an ASCII
20 is simply skipped. When new records are added, the DATAENTRY routine
after getting a new entry but before it is added to the database record
file looks in the index to see if there is an entry that starts with
an ASCII 20. If there is such an entry, the new record is saved with the
record number of the record containing the ASCII 20, thus overwriting it
and finally physically deleting it from the database file and index.

The REINDEX, SEARCH%, NOSPACE$ and SORT routines were implemented
from routines contained in the book Microsoft QuickBASIC Second Edition
by Douglas Hergert. The SORT routine is a shell sort. The SEARCH%
function is a binary search. The NOSPACE$ function removes any spaces
in the index record of the fields names.first and names.last. The REINDEX
routine simply adds a new entry to the index array in memory.

I would appreciate any comments or improvements concerning this code.
It did take me some time and effort to get the routines "up and running"
so please take the time to contact me.

Enjoy,
Jose Garcia


 December 22, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)