Mini Database

Author(s): Gene G. Buza
Publication: Synchro-Sette
Pub Details: Synchro-Sette v2 n7 (Volume 2, Issue 7)
Date: August 1983
Pages: 4-6, 18
Cartoon of a man and a woman puzzling over a sheet reading "MINI DATA-BASE ???"
Cartoon of a man and a woman puzzling over a sheet reading "MINI DATA-BASE ???"

MINI DATABASE

Have a little time on your hands? Typing in this program ought to keep you busy for an evening.

Perhaps you have been turned off by data programs that limit the amount of characters that can be entered into any of the data fields. The problem with such programs is two-fold.

1. The variables to be entered have to be dimensionalized as to their maximum size and to show how many there are. If a variable arises that requires more space than has been assigned to it, the program will truncate (chop off) any characters past the limit.

2. When variables are shorter than the dimesionalized size, the program puts enough blank spaces at the end of the variable to make up the difference. This, of course, wastes precious memory space.

“DATABASE” is a program that will store data efficiently with absolutely no wasted space other than the code numbers used for co-ordinate pointers.

This program creates a single string variable <A$> that constantly allows data to be manipulated. The string has the following characteristics:

  • is increased in size when data is entered | – is decreased in size when data is deleted | – allows data to be edited | – performs a data search when needed

This program is not a full-blown Data-Base as it does not allow sorting or numeric totalling. It is also not written as efficiently as it could be regarding its size. This was done purposely to allow the user to observe the flow of the program’s logic.

The secret to the programs use lies in the character codes used as pointers. If you turn to the Sinclair Character Code section of your manual, you will notice that a large portion of these codes are labled “NOT USED”. Other programs we and others have used in the past, might have used characters such a “*”, “/” and others as pointers that instruct a program during a search through a string, to break out and branch to another routine.

The “NOT USED” codes, such as those between 67 to 111, appear on the screen as question marks. Try this sample program:

10 FOR N = 67 TO 111
20 SCROLL
30 PRINT N, CHR$(N)
40 NEXT N

Yet they have definite characteristics that we can utilize. The data entry is kept to five fields. If this program were to be used as a general information program, such as to find information from periodicals, we might use the following:

SUBJECT – any word or phrase that would pertain to the information about to be entered

ITEM 1 thru 3 and LAST ITEM – this could be the name of the periodical, issue date, page # and any additional information about the subject.

The usefulness of a data-base program is that it is not dedicated to just one set of circumstances. It can be used as a telephone, name & address program, for inventory, recipes, test grades, etc.

KEYWORD SEARCH

When the data is entered, a search can be performed to extract the complete data block with just the entry of a keyword. Picture all the data that you will enter as being a line of boxes with a single character occupying each box. The first box in the string has the character code 111 in it. Data that is entered and terminated by pressing the ENTER key, has its characters put into these boxes in a straight line. The next box after that portion has one of the character codes from 67 to 70 inserted into it, starting with 67. After the last data item is entered, character code 111 is inserted. The process then repeats itself until no more data is to be entered.

The search by keyword examines the entire <A> string until the keyword is located. Another search is then performed both forward and backward, looking for the 111 codes. When they are found, this section is duplicated into a different variable in which another routine using the same techniques, breaks apart into the five separate fields.

DELETION OF BLOCKS

The block deletion works the same way as the search but removes the unwanted section of characters and pushes the two end sections together.

EDITING FIELDS

In this mode, a search routine locates the desired block, breaks it down into the five fields and allows one field at a time to be removed with a new field put in its place. The block then has the two portions of the remaining <A> string attached at each side.

This program will allow as much data to be entered as memory allows. Preliminary tests show over 12,000 characters to be about the limit for a 16K machine. As more data is entered, search routines will require more time to locate the newest data.

  10 LET A$=CHR$ 111
100 FAST
110 CLS
120 PRINT AT 1,10;"MINI DATABAS
E"
130 PRINT AT 4,0;"TO ENTER DATA
";TAB 30;1
140 PRINT AT 6,0;"TO DELETE DAT
A";TAB 30;2
150 PRINT AT 8,0;"TO EDIT DATA";
TAB 30;3
160 PRINT AT 10,0;"TO SEARCH FO
R DATA";TAB 30;4
170 PRINT AT 12,0;"TO SAVE DATA
ON TAPE";TAB 30;5
200 SLOW
210 PRINT AT 21,6;" ENTER ONE O
F AVOVE ";AT 21,6;" ENTER ONE OF
ABOVE "
220 LET Y$=INKEY$
230 IF CODE Y$<29 OR CODE Y$>34
THEN GOTO 210
240 FAST
250 CLS
260 GOTO VAL Y$*1000
1000 REM DATA ENTRY
1010 CLS
1020 PRINT
1030 PRINT "SUBJECT?"
1035 SLOW
1040 INPUT B$
1045 PRINT ,,B$
1050 IF B$="" THEN GOTO 100
1060 LET A$=A$+B$+CHR$ 67
1070 PRINT ,,"ITEM NO. 1?"
1080 INPUT B$
1085 PRINT ,,B$
1090 LET A$=A$+B$+CHR$ 68
1100 PRINT ,,"ITEM NO. 2?"
1110 INPUT B$
1115 PRINT ,,B$
1120 LET A$=A$+B$+CHR$ 69
1130 PRINT ,,"ITEM NO. 3?"
1140 INPUT B$
1145 PRINT ,,B$
1150 LET A$=A$+B$+CHR$ 70
1400 PRINT ,,"LAST ITEM?"
1410 INPUT B$
1415 PRINT ,,B$
1416 PAUSE 100
1420 LET A$=A$+B$+CHR$ 111
1430 GOTO 1000
2000 REM DELETE DATA BLOCK
2010 PRINT AT 10,0;"ENTER KEYWOR
D OF DATA TO BE DELETED :::"
2020 SLOW
2030 INPUT C$
2040 FAST
2050 FOR N=1 TO LEN A$-LEN C$+1
2060 IF A$(N TO N+LEN C$-1)=C$ T
HEN GOTO 2200
2070 NEXT N
2080 CLS
2090 PRINT AT 10,0;"DATA NOT IN
FILE :::"
2100 PAUSE 500
2110 CLS
2120 GOTO 100
2200 FOR A=N TO 1 STEP -1
2210 IF CODE A$(A)=111 THEN GOTO
2230
2220 NEXT A
2230 FOR B=N TO LEN A$
2240 IF CODE A$(B)=111 THEN GOTO
2260
2250 NEXT B
2260 CLS
2270 PRINT ,,A$(A+1 TO B-1)
2280 PRINT ,,"IS THIS THE DATA B
LOCK YOU WANT DELETED?"
2290 PAUSE 40000
2300 IF INKEY$="N" THEN GOTO 207
0
2310 LET A$=A$( TO A)+A$(B+1 TO
LEN A$)
2320 GOTO 100
3000 REM EDIT DATA
3010 PRINT ,,"ENTER KEYWORD?"
3020 SLOW
3030 INPUT C$
3040 FAST
3050 FOR N=1 TO LEN A$-LEN C$+1
3060 IF A$(N TO N+LEN C$-1)=C$ T
HEN GOTO 3100
3070 NEXT N
3080 GOTO 2080
3100 FOR A=N TO 1 STEP -1
3120 IF CODE A$(A)=111 THEN GOTO
3140
3130 NEXT A
3140 FOR B=N TO LEN A$
3150 IF CODE A$(B)=111 THEN GOTO
3170
3160 NEXT B
3170 LET D$=A$(A+1 TO B-1)
3175 GOTO 3800
3180 FOR I=1 TO LEN D$
3190 IF CODE D$(I)=67 THEN GOTO
3210
3200 NEXT I
3210 CLS
3220 PRINT ,,"SUBJECT IS ";D$( T
O I-1)
3230 PRINT ,,"ENTER NEW SUBJECT
OR PRESS ENTERFOR NO CHANGE?"
3240 SLOW
3250 INPUT E$
3260 IF E$="" THEN LET E$=D$( TO
I-1)
3265 LET D$=E$+D$(I TO LEN D$)
3270 FAST
3275 LET F$=E$+CHR$ 67
3280 CLS
3290 LET C=I+1
3300 FOR I=C TO LEN D$
3310 IF CODE D$(I)=68 THEN GOTO
3330
3320 NEXT I
3330 PRINT ,,"ITEM 1 IS ";D$(C T
O I-1)
3340 PRINT ,,"ENTER NEW ITEM OR
PRESS ENTER FOR NO CHANGE?"
3350 SLOW
3360 INPUT E$
3370 IF E$="" THEN LET E$=D$(C T
O I-1)
3380 LET F$=F$+E$+CHR$ 68
3390 FAST
3400 CLS
3410 LET C=I+1
3420 FOR I=C TO LEN D$
3430 IF CODE D$(I)=69 THEN GOTO
3450
3440 NEXT I
3450 PRINT ,,"ITEM 2 IS ";D$(C T
O I-1)
3460 PRINT ,,"ENTER NEW ITEM OR
PRESS ENTER FOR NO CHANGE?"
3465 SLOW
3470 INPUT E$
3480 IF E$="" THEN LET E$=D$(C T
O I-1)
3490 LET F$=F$+E$+CHR$ 69
3500 FAST
3510 CLS
3520 LET C=I+1
3530 FOR I=C TO LEN D$
3540 IF CODE D$(I)=70 THEN GOTO
3560
3550 NEXT I
3560 PRINT ,,"ITEM 3 IS ";D$(C T
O I-1)
3570 IF E$="" THEN LET E$=D$(C T
O I-1)
3575 SLOW
3580 INPUT E$
3590 IF E$="" THEN LET E$=D$(C T
O I-1)
3600 LET F$=F$+E$+CHR$ 70
3610 FAST
3620 CLS
3630 LET C=I+1
3640 PRINT ,,"LAST ITEM IS ";D$(
C TO LEN D$)
3650 PRINT ,,"ENTER NEW ITEM OR
PRESS ENTER FOR NO CHANGE?"
3655 SLOW
3660 INPUT E$
3670 IF E$="" THEN LET E$=D$(C T
O LEN D$)
3680 LET F$=F$+E$
3690 FAST
3700 CLS
3710 LET A$=A$( TO A)+F$+A$(B TO
LEN A$)
3720 GOTO 100
3800 CLS
3810 PRINT ,,D$
3820 PRINT ,,,,"IS THIS THE CORR
ECT DATA BLOCK?"
3830 PAUSE 40000
3840 IF INKEY$="Y" THEN GOTO 318
0
3850 GOTO 3070
4000 REM KEYWORD SEARCH
4010 CLS
4020 PRINT AT 10,0;"ENTER KEYWOR
D OR PHRASE?"
4030 SLOW
4040 INPUT C$
4050 FAST
4060 CLS
4070 FOR N=1 TO LEN A$-LEN C$+1
4080 IF A$(N TO N+LEN C$-1)=C$ T
HEN GOTO 4200
4090 NEXT N
4100 PRINT AT 10,0;"NOT IN FILE
:::"
4120 PAUSE 500
4130 GOTO 100
4200 LET NN=N
4205 FOR A=N TO 1 STEP -1
4210 IF A$(A)=CHR$ 111 THEN GOTO
4230
4220 NEXT A
4230 FOR B=N TO LEN A$
4240 IF A$(B)=CHR$ 111 THEN GOTO
4300
4250 NEXT B
4300 LET D$=A$(A TO B)
4310 FOR N=1 TO LEN D$
4320 IF CODE D$(N)=67 THEN GOTO
4340
4330 NEXT N
4340 GOSUB 4800
4350 FOR N=1 TO LEN D$
4360 IF CODE D$(N)=68 THEN GOTO
4380
4370 NEXT N
4380 GOSUB 4800
4390 FOR N=1 TO LEN D$
4400 IF CODE D$(N)=69 THEN GOTO
4420
4410 NEXT N
4420 GOSUB 4800
4430 FOR N=1 TO LEN D$
4440 IF CODE D$(N)=70 THEN GOTO
4460
4450 NEXT N
4460 GOSUB 4800
4700 PRINT D$(2 TO LEN D$-1)
4705 PAUSE 40000
4710 IF INKEY$="Z" THEN COPY
4720 CLS
4730 FOR N=NN+1 TO LEN A$-LEN C$
+1
4740 GOTO 4080
4799 STOP
4800 PRINT D$(2 TO N-1)
4810 PRINT
4820 LET D$=D$(N TO LEN D$)
4830 RETURN
5000 REM SAVE DATA ON CASSETTE
5010 PRINT ,,"ENTER FILE NAME, P
REPARE","RECORDER AND PRESS ENTE
R :::"
5020 SLOW
5030 INPUT Z$
5040 SAVE Z$
5050 GOTO 100

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