Indexing 101 3/3

 BBS: Inland Empire Archive
Date: 06-18-92 (06:18)             Number: 809
From: RICHARD VANNOY               Refer#: NONE
  To: ALL                           Recvd: NO  
Subj: Indexing 101 3/3               Conf: (2) Quik_Bas
INDEXING 101, page 3 of 3

So, to sum up the binary search routine, lets look for an
employee by number and name.

IF input was a number THEN
   Binary search the EMPLNUMB.NDX for the number.
   If found, go to the indicated record in EMPLOYEE.DBF and
   display or process the data.
   If not found, print an error message.
IF input was a string
   Binary search the EMPLNAME.NDX for the name.
   If found, got to the indicated record in EMPLOYEE.DBF and
   display or process the data.
   If not found, print an error message.

Note that the logic for a number or a string is identical,
so you write the code for a number looked up in
EMPLNUMB.NDX, then make a copy of the same code and make the
minor modifications of looking for a string in EMPLNAME.NDX.

That's how it works!  Indexing may seem bulky or unnecessary
at first, but I can never emphasize enough the increase in
speed you get.  You will just have to try it or see it for

The part of an indexing system that takes the most caution
and care is the maintenance of the .NDX files.  Remember
that whenever you add a record, delete a record, or change
the data (field) that is in an index file, then THAT index
file must be IMMEDIATELY updated with the correct
information for the system to work.  It can be easy if you
take it a step at a time.

In our example, let's say you add an employee.  The new
employee's data goes in the next available record of
EMPLOYEE.DBF, say number 1234.  His name is Jones Casey,
and his employee number is 2345.  Now create a new record

EmpNumb.  Record Number
  2345       1234

Put this info at the end of the EMPNUMBR.NDX file and
reverse bubble sort it up to where it belongs.  Do the same

EmpName     RecordNumber
Jones Casey  1234

in the EMPLNAME.NDX file.

All maintenance must be done on the fly (right NOW!),
because the very next operation may be to find the employee
you just added, or otherwise process the record that was
just manipulated, so do it now.

That should acquaint you with the basic theory of index file
creating and use.  The best way to fully understand the
concepts is to set up an indexed file and try things out.
I suggest you set up a data base with no index, then add one
index, and later one other to get you started.
<End of INDEXING 101 by Richard Vannoy>
> MegaMail 2.1b #0:He's a few fries short of a Happy Meal!
--- Maximus 2.00
 * Origin: D.J.M.BBS (1:202/307)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET