-
Notifications
You must be signed in to change notification settings - Fork 6
/
names.bas
165 lines (139 loc) · 4.86 KB
/
names.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
' NAMES.BAS by David Bannon
' Copyright (C) 1992 DOS Resource Guide
' Published in Issue #6, November 1992, page 65
'
DEFINT A-Z
DECLARE SUB Menu (Row, Column, Option$(), Escape, Selection)
CONST TRUE = -1
CONST FG = 7, BG = 4
DIM Main$(1 TO 10)
FOR X = 1 TO 10
READ Main$(X)
NEXT
' Display the main menu
MainMenu:
DATA NAMES DATABASE, Keep track of those, Names and Numbers!, MAIN MENU, -
DATA 1. ENTER a name, 2. SEARCH for a name, 3. Quit, -, Select a number
CLS
CALL Menu(6, 30, Main$(), LastKey, Selection)
COLOR 7, 1
' A simple database program for entering names, phone numbers and
' company names, and searching for them.
file$ = "NAMES.TXT" ' Database file name
form$ = "\ \\ \"
form$ = "(\ \)\ \"
form$ = "\ \"
' Get the user's choice
DO: choice$ = INKEY$
LOOP UNTIL choice$ = "1" OR choice$ = "2" OR choice$ = "3"
SELECT CASE choice$
CASE "1" ' Add a name to the database
OPEN file$ FOR APPEND AS #1
WHILE UCASE$(last$) <> "END"
CLS : LOCATE 11, 25: PRINT "ADD a name to the database"
LOCATE 12, 25: PRINT "(To stop, enter END as a last name)"
LOCATE 14, 25: INPUT "Last name: ", last$
IF UCASE$(last$) <> "END" THEN
LOCATE 16, 24: INPUT "First name: ", first$
LOCATE 18, 40: PRINT "(Press Enter if n/a)"
LOCATE 18, 25: INPUT "Area code: ", area$
LOCATE 20, 22: INPUT "Phone number: ", phone$
LOCATE 22, 22: INPUT "Company name: ", compa$
WRITE #1, last$, first$, area$, phone$, compa$: CLS
END IF
WEND
CLOSE #1: last$ = "": GOTO MainMenu
CASE "2" ' Search for a name in the database
WHILE UCASE$(search$) <> "END"
OPEN file$ FOR INPUT AS #1
CLS : LOCATE 11, 25: PRINT "SEARCH for a name in the database"
LOCATE 12, 25: PRINT "(To stop, enter END as the name)"
LOCATE 14, 25: INPUT "Name to search for: ", search$: PRINT
IF UCASE$(search$) <> "END" THEN
DO WHILE (NOT EOF(1))
INPUT #1, last$, first$, area$, phone$, compa$
SELECT CASE UCASE$(search$)
CASE UCASE$(last$)
hit% = 1: LOCATE , 25
PRINT USING form$; last$; first$;
LOCATE , 25: PRINT USING form$; area$; phone$
LOCATE , 25: PRINT USING form$; compa$
CASE UCASE$(first$)
hit% = 1: LOCATE , 25
PRINT USING form$; last$; first$;
LOCATE , 25: PRINT USING form$; area$; phone$
LOCATE , 25: PRINT USING form$; compa$
CASE UCASE$(compa$)
hit% = 1: LOCATE , 25
PRINT USING form$; last$; first$;
LOCATE , 25: PRINT USING form$; area$; phone$
LOCATE , 25: PRINT USING form$; compa$
END SELECT
LOOP
IF hit% = 0 THEN
LOCATE , 25: PRINT "No match found for "; search$
END IF
hit% = 0: LOCATE , 25: PRINT
LOCATE , 25: PRINT "Press any key to continue"
DO WHILE INKEY$ = "": LOOP
CLOSE #1
END IF
WEND
CLOSE #1: search$ = "": GOTO MainMenu
CASE "3" ' Quit the program
CLS : SYSTEM
END SELECT
'
SUB Menu (Row, Column, Option$(), last, Selection) STATIC
LMax = 0 'Max length of options
NumOpts = UBOUND(Option$) 'Number of options
IF Selection = 0 OR Selection > NumOpts THEN Selection = 1
FOR A = 1 TO NumOpts 'Determine longest item
B = LEN(Option$(A))
IF B > LMax THEN LMax = B
NEXT
LMax = LMax + 2 'Add two for surrounding spaces
FOR A = 1 TO NumOpts 'Display the choices
COLOR FG, BG
F = Row + A - 1
LOCATE F, Column
IF Option$(A) = "-" THEN
PRINT STRING$(LMax, 196)
ELSE
PRINT " "; Option$(A); TAB(Column + LMax);
B = INSTR(UCASE$(Option$(A)), A$)
IF B THEN
LOCATE F, Column + B
PRINT MID$(Option$(A), B, 1)
END IF
END IF
NEXT
COLOR FG, BG
LOCATE Row + Selection - 1, Column
PRINT " "; Option$(Selection); TAB(Column + LMax);
B = INSTR(UCASE$(Option$(Selection)), A$)
IF B THEN
LOCATE Row + Selection - 1, Column + B
PRINT MID$(Option$(Selection), B, 1)
END IF
SELECT CASE T
CASE -71 'Home
Selection = 1
CASE -79 'End
Selection = NumOpts
CASE -72
Selection = Selection - 1 'Up arrow
IF Selection = 0 THEN Selection = NumOpts
IF MID$(Option$(Selection), 2, 1) = "-" THEN
Selection = Selection - 1
END IF
CASE -80 'Down arrow
Selection = Selection + 1
IF Selection > NumOpts THEN Selection = 1
IF Option$(Selection) = "-" THEN
Selection = Selection + 1
END IF
CASE ELSE
Selection = Letter
END SELECT
END SUB