Improving the Home Database

See all articles from CATS v5 n9
Author(s): Mark Fisher
Publication: CATS Newsletter
Pub Details: CATS v5 n9 (Volume 5, Issue 9)
Date: January 1988
Pages: 6-7

USING ARCHIVE PART II

Last month, I covered the basic framework of a home database, suitable for storing phone numbers and addresses for easy reference. Because of space limitations, however, I left out a number of important elements of the program. If you haven’t read last month’s installment, you’re going to feel lost (yes, you may feel lost even if you DID read the piece).

If you used the portions of the program that ran last month, you may have acquired some records that need editing. To do so, here are a few useful procs:

proc a
errchk
alter
endproc

proc dele
prompt;"Confirm DELETE (y/n
)"
input txt$
if lower(txt$)="y"
delete
endif
endproc

“Srch” allows you to look for a particular bit of data, and returns with the record that contains it. Archive has two basic methods of scanning files, FIND and SEARCH. FIND scans all text fields for a given string, while SEARCH checks all records, trying to find records that satisfy a numeric operator that you specify. For our purposes, FIND is adequate, but if you wanted to find, say, friends named “Tom” that live in “Columbia”, you’ll have to use proc exit and type it yourself using SEARCH.

proc srch
prompt;"Search for ? "
input txt$
if txt$>""
find txt$
if found()
sprint
else
warning;txt$+" not found"
pause;28
endif
endif
endproc

“Exit” will let you switch to the command line of Archive, either to work on your program, or to perform searches or data manipulations not included in your program.

proc exit
blank;11,0
blank;12,0
blank;13,0
blank;14,0
print at 11,0;"Files are sti
ll open! Type ""comget"" to resta
rt."
print "To select sub-files, u
se syntax (select instr (flag$,""
[your code here]"")"
print "To restore full listin
gs, use ""reset:start"""
stop
endproc

One of the first things that the program does on starting, is to ORDER the files by last name. If you want a different sequence, this suite of procs will allow you to select from a variety of possibilities. The ORDER command is quite straightforward, but suffers from several weaknesses: 1) Each invocation of ORDER sets up a data index in RAM. Since there is a relatively small, XfixedY block of memory for this, you may only order on the first eight characters of a given field. 2) Also because of the fixed order buffer, you may only sort by a maximum of eight fields at once. 3)Archive doesn’t allow a command to refer to a variable to get the name of a data field. An “ideal” proc for ORDER might look like:

proc ordput
input"Enter field name: ";xx$
order xx$;a
endproc

When Archive is executing an ORDER command, it looks only for a field name (xx$ in this case) – even though you may have set up a normal string variable of the same name. Since there is no data field with that name, the proc will stop with an error report.

What can you do? Well… it’s a kluge, but the proc “ordwrite” saves off the text of a procedure that will perform the desired sort. The procedure is then merged with the current program and executed. First, the proc “ordr” presents possible fields to be ordered:

proc ordr
cls
print "Order files by:";
local count
let count=0
while count<numfld()
print tab 16;count;" ";field
n(count)
let count=count+1
endwhile
let OK=0
while not OK
input "Enter choice #:";num
let OK=(num>0 and num<numfld
())
endwhile
let ord$=fieldn(num)
ordwrite
screen
endproc

proc ordwrite
spoolon "sequence_prg" export
lprint "proc ordput"
lprint "order "+ord$+";a"
lprint "endproc"
lprint chr(0)+chr(26)
spooloff
merge "sequence"
ordput
kill "sequence_prg"
endproc

Here are a few procs to ease movement through your file; “page” and “rev” allow you to automatically leaf through the file, stopping when you press “ESC”:

proc page
escmsg
while not eof()
sprint
pause;10
nxt
endwhile
endproc

proc rev
escmsg
while recnum()>0
bk
pause;10
sprint
endwhile
endproc

proc escmsg
prompt;"Press ESC to stop."
endproc

“Info” loads a second screen file containing your description of how this program operates, then waits until a keypress to re-load the basic screen layout.

proc info
cls
sload "info"
screen
print at 12,0;"Memory ava il
able: ";memory();",
";count();" records in fi
le."
prompt;"Press any key to r et
urn"
let c$=getkey()
sload "phonscrn"
screen
endproc

At the end of your editing session, you will almost certainly want a hard copy ofthe files; “lprnt” takes care of that. To avoid wasting too much paper, I use the “spoolon” command to divert the output from printer to screen.

proc lprnt
cls
print "Output to screen or pr
inter? (S/P)"
if upper(getkey())="S"
spoolon screen
else
print "Is printer ready? Sp
ace to continue, Q to quit"
if getkey()<>" ": screen :
return : endif
endif
first
while not eof()
lprint Hon$; tab 5;fname$;"
";lname$; tab 30;hphone$;tab 5
0;ophone$
lprint tab 6;street$;" ";ct
y$;", ";st$;" ";zip$;"(";flag$;")
"

lprint
next
let c$=getkey()
endwhile
spooloff
screen
endproc

That’s it! As with any file system, I’m sure that you’ll have some special requirements that aren’t covered by this application. I hope that you will gain enough familiarity with Archive through this tutorial to make the necessary changes – if not, write me a note and I’ll try to respond in this newsletter.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.