EasyManua.ls Logo

Tandy TRS-80 - Page 81

Tandy TRS-80
104 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
.APPENDIX
C
610
NEXT
N
620
CLOSE
#1
630
END
SAMPLE
PROGRAM
#4
SEARCH FOR A NAME
Since the file you created in "Sample Program
#3"
is
already in alphabetical order, you can immediately
find the name you want. This program shows how.
10
'
Search
a 1 ist
20
'
30
'
(NOTEs
This program
requires
that a file
called "NAMES/NOS
40
'
exists
—see
"Create
list and
alphabetize
—Sample
program
#3)
50
'
This
program
searches
a disk
file
which
holds
names and
60
'
phone numbers
in
alphabetical
order.
The file
is
a direct
70
'
access
file
called
"NAMES/NOS",
is
35 bvtes
long*
and
80
'
is
formatted
as
follows: 24
bvtes
for
the
name;
3 bvtes
90
'
for the
area
code?
8
bvtes
for
the
phone
number.
The
100
'
program
uses
iterative
searching.
110
'
120 OPEN
"D",#l,
"NAMES/NOS"
,35
130 FIELD
#1,24
AS
NAME*,
3
AS
AREA*,
8
AS
PHONE*
140
CLS
150 PRINT
3 99
,"ENTER
NAME(LAST,
FIRST
MI)
160
LINE
INPUT
NM*
170
'
180
'
Initialization
of variables
190
*
200 Nl*
=
NM*
210 IF
LEN(NM*>
< 24
THEN 800
220 IF
LEN(NM*)
> 24
THEN
820
230 FIRST
=
1
240
MID
-
INT(
(L0F(l)+l)/2)
250
LAST
=
LOF(l)
260
CNT
=
270
'
280
'
Program
checks
the
last
record
first
because
it won't
290
'
be checked
in
the
regular-
search
300
'
310
GET
#1,LAST
320 IF
NAME*
=
NM* THEN
450
330
'
340
'
Program
keeps
comparing
NM*
with NAME* from
record
MID
350
'
until NM*
is found
or enough
records
have
been
seen
360
'
to show
that
it isn't
in
the file
370
'
380 GET
#1,MID
390 IF
CNT >
(L0F(l)+l)/2
THEN 710
400 IF
NAME*
< NM* THEN
570
410
IF
NAME*
> NM*
THEN
640
420
'
430
'
When NM*
is found
it
is
printed
out
440
'
450 CLS
460
PRINT
3
104, NAME*
470 PRINT
a
136,
"
("
? AREA*
5"
)"
; PHONE*
480 PRINT
3
195,
"PRESS
<ENTER>
TO
CONTINUE,
"
490 PRINT
3
227,
"ELSE
PRESS
<Q>
TO QUIT"
500
AN*
=
INKEY*
510 IF
AN*
=
"Q"
THEN
CLOSE:
END
520 IF
AN*
=
CHR*(13)
THEN
140
530 GOTO
500
540
'
550
'
Subprogram
for when
NAME*<NM*
560
'
570
FIRST
=
MID
580
MID
=
(MID+LAS'D/2
590
CNT
=
CNT
+
1
600
GOTO
380
6.1.0
'
620
'
Subprogram
for
when
NAME*>NM*
630
'
640
LAST
=
MID
650
MID
=
<MID+FIRST)/2
660 CNT
=
CNT
+
1
670
GOTO
380
680
'
690
'
Subprogram
for when
NM*
is
not
f o u n
d
700
'
710
CLS
720 PRINT
3
100, Nl*;"
NOT
FOUND"
730 PRINT
3 132,
"TO
TRY
AGAIN
PRESS
<ENTER>"
740 AN*
=
INKEY*
750
IF AN*
=
"
"
THEN
740
760
GOTO
140
770
'
780
'
Subprograms
for
modifving
NM*
to a
20
bvte string
71

Related product manuals