BBS: Inland Empire Archive Date: 05-09-92 (01:15) Number: 191 From: TOM HAMMOND Refer#: NONE To: LYN BORCHERT Recvd: NO Subj: HASHING 6/9 Conf: (2) Quik_Bas
Continued from Hashing 5/9
*********************** start of program export ************************
' hash.bas start of part 1 of 7 - cut and paste as needed
' ====================================================================
'
' Hashed Access Demonstration Program For The QuickBasic Echo
' By Mike Avery, Started 12-28-91
' Version 1:00.00 - Make it work. 12-28-91
' Version 1:01.00 - Add Disk Functions 12-29-91
' ====================================================================
DECLARE FUNCTION Hash! (TestString$)
DECLARE SUB GetData (Key$, Index%, SeekCount%, SaveIndex%)
DECLARE SUB Waiter ()
DECLARE FUNCTION WhackIt$ (InputString$)
CONST DeletedValue$ = "EXPLETIVE DELETED"
CONST ArraySize% = 531 'Change the size here - the rest adjusts itself
CONST RetryLimit% = 100 'I get bored easily....
CONST ScreenLimit% = 21 'how many lines do we show at once?
CONST True = -1: CONST False = NOT (True)
DIM SHARED a$(ArraySize%, 1) 'our little data base
DIM SHARED SortSpace$(ArraySize%, 1) 'Workspace for sorted lists
PowerMax% = INT((LOG(ArraySize%) / LOG(2)) + 2)
DIM SHARED PowersOfTwo%(PowerMax%)
'build the table - lookup is faster than calculation
FOR I% = 0 TO PowerMax%
PowersOfTwo%(I%) = 2 ^ I%
NEXT I%
DO WHILE TestName$ <> "STOP"
CLS
PRINT "Doofus Phone Book System"
PRINT
PRINT
INPUT "Name/Help/Dump/Sort/Load/Save/Analyse/Stop"; TestName$
TestName$ = UCASE$(RTRIM$(LTRIM$(TestName$)))
IF TestName$ = "DUMP" THEN
GOSUB DumpIt
ELSEIF TestName$ = "SORT" THEN
GOSUB SortIt
ELSEIF TestName$ = "ANALYSE" THEN
GOSUB Analyse
ELSEIF TestName$ = "HELP" THEN
GOSUB Help
ELSEIF TestName$ = "LOAD" THEN
GOSUB LoadIt
ELSEIF TestName$ = "SAVE" THEN
GOSUB SaveIt
ELSEIF TestName$ <> "" AND TestName$ <> "STOP" THEN
CALL GetData(TestName$, Index%, SeekCount%, SaveIndex%)
' At this point, one of 3 conditions exists.
' 1. We ran out of retries, and it doesn't matter what Index%_
points to,
' 2. Index% points to our data, or
' 3. Index% points to an empty record and SaveIndex may or may not
' point to a deleted record we can reuse.
PRINT
PRINT "It took "; SeekCount%; "tries to determine that..."
'in a productional program, you'd probably drop that message...
PRINT
IF SeekCount% >= RetryLimit% THEN
PRINT "The data base is full and/or needs to be resized"
YesOrNo$ = ""
DO WHILE YesOrNo$ <> "Y" AND YesOrNo$ <> "N"
INPUT "Do you want to see a data base dump (Y/N)"; YesOrNo$
IF YesOrNo$ <> "" THEN
YesOrNo$ = WhackIt$(YesOrNo$)
END IF
IF YesOrNo$ = "Y" THEN
GOSUB DumpIt
ELSEIF YesOrNo$ <> "N" THEN
PRINT "Please Enter A Y for Yes or a N for NO."
END IF
LOOP
TestName$ = "STOP"'force a shutdown
CALL Waiter
' save data base here, if converted to a disk based system
ELSEIF a$(Index%, 0) = TestName$ THEN
PRINT a$(Index%, 0); "'s Phone Number Is "; a$(Index%, 1); "."
Action$ = "Dummy"
DO WHILE Action$ <> "" AND Action$ <> "C" AND Action$ <> "D"
INPUT "Change the number, Delete The Number, or enter";_
Action$
Continues in next file (HASHING - 7 of 9)
--- WM v2.00/91-0231
* Origin: The Modem Zone BBS (314) 893-5106 (1:289/2)

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