'===========================================================================
' Subject: Key Word Data Base                 Date: 06-15-01 (19:34)       
'  Author: Gerald L. Wykoff                   Code: QB, QBasic, PDS, GWB   
'  Origin: wykoff@mbawiz.com                Packet: DATABASE.ABC
'===========================================================================
' Subject: FINDIT    Date: 6-10-1  (18:22)   
'    Author: Gerald L. Wykoff                       Code: QB, QBasic
'    Origin:  wykoff@mbawiz.com


REM    FindIT requires its own data storage file in the same folder as
REM    the application.  Just go to EDIT and create a TXT file named
REM    'locator.dat' in this 3-field format --
REM                 'keyword','address','helpful data...'
DECLARE SUB S.CHANGE ()
DECLARE SUB S.PRINT ()
DECLARE SUB S.SEARCH ()
DECLARE SUB S.APPEND ()
DECLARE SUB wind ()
COMMON SHARED locator.dat
'                                       NEW FEATURES FOR FINDIT
'                                       1.  Time
'                                       2.  Date
'                                       3.  Area Code Finder
'                                     x 4.  Zip Code Finder
'                                       5.  TSD Time-Distance-Speed
'                                       6.  QPC Quantity-Price-Cost
'                                       7.  Currency   Convert money terms
'                                       8.  Measures   Weight & Length
'                                       9.  PERT      Estimator
'                                       10. Temp     Temperature Converter
'                                       11. Mean     Average Calc.
'                                      x12. Postage Calc.
'                                       13. Speed    Converts rpm and sfpm
'                                       14.
BEGIN:                                  
   VIEW PRINT 2 TO 24
   CLS
   SCREEN 9
   COLOR 13, 8
LINE (5, 5)-(630, 5), 12
LINE -(630, 338), 12
LINE -(5, 338), 12
LINE -(5, 5), 12
LINE (4, 4)-(631, 4), 3
LINE -(631, 339), 3
LINE -(4, 339), 3
LINE -(4, 4), 3
'                                       open file
'
' type the name of the file
   LOCATE 9, 5
   COLOR 15
15
STEP1:
'
' open view port that contains main menu
'
   CLS
   SCREEN 9
   COLOR 14, 8
LINE (5, 5)-(630, 5), 12
LINE -(630, 338), 12
LINE -(5, 338), 12
LINE -(5, 5), 12
LINE (4, 4)-(631, 4), 3
LINE -(631, 339), 3
LINE -(4, 339), 3
LINE -(4, 4), 3

   VIEW PRINT 5 TO 24

LOCATE 17, 20
CALL S.SEARCH
GOTO 1100


'
'  print all keywords to the screen
'
45
'CLS
LINE (5, 5)-(630, 5), 12
LINE -(630, 338), 12
LINE -(5, 338), 12
LINE -(5, 5), 12
LINE (4, 4)-(631, 4), 3
LINE -(631, 339), 3
LINE -(4, 339), 3
LINE -(4, 4), 3

'
' find out what action is to be performed:
'
   LOCATE 5, 20
   COLOR 14
   PRINT "  What would you like to do? "
   COLOR 15
   LOCATE , 10
   PRINT "         1.  Print this file's keywords and info on screen"
   LOCATE , 10
   PRINT "         2.  Append new keywords, information to this file"
   LOCATE , 10
   PRINT "         3.  Change existing information in this file"
   COLOR 14
   LOCATE , 20
   INPUT "                     Please select 1, 2 or 3"; ask3$
SELECT CASE ask3$
    CASE "1"
    GOTO 31
    CASE "2"
    GOTO 32
    CASE "3"
    GOTO 33
END SELECT
'
31
CALL S.PRINT
GOTO 1100
'
32
CLS
LINE (5, 5)-(630, 5), 12
LINE -(630, 338), 12
LINE -(5, 338), 12
LINE -(5, 5), 12
LINE (4, 4)-(631, 4), 3
LINE -(631, 339), 3
LINE -(4, 339), 3
LINE -(4, 4), 3
'
LOCATE 19, 20
CALL S.APPEND
GOTO 1100
'
33
CLS
LINE (5, 5)-(630, 5), 12
LINE -(630, 338), 12
LINE -(5, 338), 12
LINE -(5, 5), 12
LINE (4, 4)-(631, 4), 3
LINE -(631, 339), 3
LINE -(4, 339), 3
LINE -(4, 4), 3
'
	 LOCATE 13, 10
	 COLOR 12
	 PRINT "Warning: ";
	 COLOR 15
	 PRINT "            The change utility cycles you through ALL your keyword entries."
	 LOCATE 15, 10
	 COLOR 14
	 INPUT "   Still want to change any information in the file ? Y/N  ", IFLAG$
	 IF UCASE$(IFLAG$) = "Y" THEN CALL S.CHANGE
'
	 CLS
LINE (5, 5)-(630, 5), 12
LINE -(630, 338), 12
LINE -(5, 338), 12
LINE -(5, 5), 12
LINE (4, 4)-(631, 4), 3
LINE -(631, 339), 3
LINE -(4, 339), 3
LINE -(4, 4), 3

	 LOCATE 20, 15
	 COLOR 14
	 INPUT "  Do you want to continue working with this file? Y/N", IFLAG$
	 IF UCASE$(IFLAG$) = "Y" THEN CLS 2: GOTO STEP1:
'
'                         this 1100 exit now line
1100
CLS
SCREEN 9
COLOR 15, 8
LINE (5, 5)-(630, 5), 12
LINE -(630, 338), 12
LINE -(5, 338), 12
LINE -(5, 5), 12
LINE (4, 4)-(631, 4), 3
LINE -(631, 339), 3
LINE -(4, 339), 3
LINE -(4, 4), 3

	 COLOR 14
	 LOCATE 21, 20
	 INPUT "Do you want to continue ? Y/N  ", IFLAG$
	 IF UCASE$(IFLAG$) = "Y" THEN GOTO 45
END
'=================
25
	 DO
	 COLOR 14
			LOCATE , 5
			INPUT "  Type in the keyword you want stored ( TO EXIT, TYPE NO ) :  ", NAME$
			IF NAME$ = "NO" OR NAME$ = "no" THEN EXIT DO
			LOCATE , 5
			LINE INPUT "  Type in the path\file for above keyword -  ", ADDRESS$
			LOCATE , 5
			LINE INPUT "  Type any additional information -  ", REMARK$
			WRITE #2, NAME$, ADDRESS$, REMARK$
			PRINT
	 LOOP
			'
			' close file
			'
	 CLOSE #2
	 END
1000
CLS
SCREEN 9
COLOR 15, 8
CALL wind
LOCATE 2, 25
COLOR 15
PRINT "FIND-IT!"
LOCATE 10, 20
PRINT "The current date is "; DATE$
LOCATE 12, 20
PRINT "The current time is "; TIME$
1050
LOCATE 20, 25
COLOR 14
INPUT "Tap Enter Key Twice to Quit"; quit$
IF UCASE$(quit$) = "" THEN END

			SUB S.APPEND
	 OPEN "LOCATOR.DAT" FOR APPEND AS #2
	 VIEW PRINT 16 TO 24
			'
			' loop to type information
			'
	 DO
			LOCATE , 5
			INPUT "  Type in the keyword ( TO EXIT, TYPE NO ) :  ", NAME$
			IF UCASE$(NAME$) = "NO" THEN EXIT DO
			LOCATE , 5
			LINE INPUT "  Type in the path/file or location info -  ", ADDRESS$
			LOCATE , 5
			LINE INPUT "  Enter any additional information -  ", REMARK$
			WRITE #2, NAME$, ADDRESS$, REMARK$
			PRINT
	 LOOP
			'
			' close file
			'
	 CLOSE #2
	 CLS 2
	 VIEW PRINT 5 TO 24
			END SUB

SUB S.CHANGE
CLS
'
' declare arrays to store information
'
	 DIM NAME$(1 TO 250), ADDRESS$(1 TO 250), REMARK$(1 TO 250)
'
' open file
'
	 OPEN "LOCATOR.DAT" FOR INPUT AS #2
'
' open work window
'
	 VIEW PRINT 8 TO 24              '17 TO 24
	 counter = 1
'
' loop to print old data and input new data
'
	 DO UNTIL EOF(2)
			INPUT #2, NAME$(counter), ADDRESS$(counter), REMARK$(counter)
			PRINT NAME$(counter), ADDRESS$(counter), REMARK$(counter)
'
' if you want to change any information, you must
' answer Y (Yes) to the next question
'
			INPUT "      Do you wish to change this information? Y/N ", flag$
			IF UCASE$(flag$) <> "Y" THEN GOTO NEXT.STEP
			PRINT "      Note: You must enter information or the record won't change"
			INPUT "           Type in a new keyword -  ", friend$
			IF friend$ <> "" THEN NAME$(counter) = friend$
			LINE INPUT "      Enter a new path/file or location -  ", ADDR$
			IF ADDR$ <> "" THEN ADDRESS$(counter) = ADDR$
			COLOR 12
			PRINT "        Avoid punctuation marks with new information"
			COLOR 14
			LINE INPUT "           Add any new information you want -  ", PH$
			IF PH$ <> "" THEN REMARK$(counter) = PH$
NEXT.STEP:
			PRINT
'
' increase counter variable by 1
'
			counter = counter + 1
'
' end of the loop
'
	 LOOP
'
' close file
'
	 CLOSE #2
'
' re-open the file for output
'
	 OPEN "LOCATOR.DAT" FOR OUTPUT AS #2
'
' rewrite the updated information
'
	 FOR I = 1 TO counter - 1
			WRITE #2, NAME$(I), ADDRESS$(I), REMARK$(I)
			PRINT NAME$(I), ADDRESS$(I), REMARK$(I)
'
' pause to allow information to be read
'
			SLEEP 1
	 NEXT I
	 CLOSE
	 CLS 2
	 VIEW PRINT 5 TO 24
END SUB

SUB S.PRINT
BEGIN1:
CLS
'
' open file
' open view port
'
	 OPEN "LOCATOR.DAT" FOR INPUT AS #2
	 VIEW PRINT 3 TO 24           '16 TO 24
	 CLS 2
	 '==========
'
' loop to output all records from the file
'
	
	 counter = 1
56
	 DO UNTIL EOF(2)
			CLS
			COLOR 14
			max.lines = 1
			INPUT #2, NAME$, ADDRESS$, REMARK$
			LOCATE 10, 3
			PRINT counter; " "; NAME$; TAB(20); ADDRESS$; TAB(45); "----"; SPC(3); REMARK$
			counter = counter + 1
			IF counter > max.lines THEN EXIT DO
		LOOP
			LOCATE 23, 25
			COLOR 11
			INPUT " Do you wish to see more keywords (Y or N) "; ask5$
			IF UCASE$(ask5$) = "Y" THEN GOTO 56
' end of output
	 CLOSE #2
	 CLS 2
	 VIEW PRINT 5 TO 24
END SUB

' subprogram S.SEARCH
' search for information about a particular person
'
SUB S.SEARCH

'****   ADDED the following variables to increase speed and faster parsing
'****   STATIC moves the variables off the stack thus making them persistent
'****     and local to the sub

STATIC intKWCount AS INTEGER   'keyword counter
STATIC intKWLen   AS INTEGER   'keyword length
STATIC intKPLen   AS INTEGER   'path length
STATIC intKDLen   AS INTEGER   'description length
STATIC intDashLen AS INTEGER   'length of strDash variable
STATIC intRow     AS INTEGER   'print row
STATIC intCol     AS INTEGER   'print column

STATIC strKeyWord() AS STRING  'keyword
STATIC strKeyPath() AS STRING  'path
STATIC strKeyDesc() AS STRING  'notes or description
STATIC strTemp      AS STRING  'temp variable for parsing description
STATIC strDash      AS STRING * 4

DIM intI          AS INTEGER
DIM intJ          AS INTEGER
DIM intMaxDes     AS INTEGER

'**** initialize variables

BEGIN2: '

intKWCount = 0
intKWLen = -999
intKPLen = -999
intKDLen = -999
intDashLen = 4
intRow = 5
intCol = 5
intMaxDes = 40

strDash = "--- "

CLS
'
' open file
' open view port
'

	 OPEN "LOCATOR.DAT" FOR INPUT AS #2
VIEW PRINT 5 TO 24           '16 to 24
	 CLS 2
'
COLOR 14
' type the name of a keyword'
	 LOCATE , 5
CLS
SCREEN 9
COLOR 13, 8
LINE (5, 5)-(630, 5), 12
LINE -(630, 338), 12
LINE -(5, 338), 12
LINE -(5, 5), 12
LINE (4, 4)-(631, 4), 3
LINE -(631, 339), 3
LINE -(4, 339), 3
LINE -(4, 4), 3
LOCATE 5, 32
   PRINT "FIND-IT";
   COLOR 14: LOCATE 6, 20
   PRINT " -- THE KEYWORD SEARCH UTILITY"
   LOCATE 7, 14
   PRINT "FOR WRITERS, AUTHORS, RESEARCHERS AND COMPUTER OPERATORS"
   COLOR 11
LOCATE 13, 20
PRINT "The current date is "; DATE$
LOCATE 14, 20
PRINT "The current time is "; TIME$
COLOR 15
LOCATE 17, 15
	 LINE INPUT "  Type in a keyword you want to locate -  ", NAME.NEW$
PRINT
'
' loop to search for information about this keyword
' *** and increment intKWCount variable.  Doing it this way increases speed of
' *** of access because you are doing only one thing at a time.
' *** CLS

	 DO UNTIL EOF(2)
			INPUT #2, NAME$, ADDRESS$, PHONE$
'     IF NAME.NEW$ = NAME$ OR NAME$ = LCASE$(NAME.NEW$) OR NAME$ = UCASE$(NAME.NEW$) THEN GOSUB RESULT:
			IF NAME.NEW$ = NAME$ OR NAME$ = LCASE$(NAME.NEW$) OR NAME$ = UCASE$(NAME.NEW$) THEN
				intKWCount = intKWCount + 1
			END IF
	 LOOP

	 CLOSE #2

'*** Allow closing if keyword is not found

	 IF intKWCount = 0 THEN EXIT SUB

	 OPEN "LOCATOR.DAT" FOR INPUT AS #2

REDIM strKeyWord(1 TO intKWCount) AS STRING  'set size of keyword string variable
REDIM strKeyPath(1 TO intKWCount) AS STRING  'set size of keyword path string variable
REDIM strKeyDesc(1 TO intKWCount) AS STRING  'set size of keyword description variable

intKWCount = 0            'reinitialize keyword counter

DO UNTIL EOF(2)
	INPUT #2, NAME$, ADDRESS$, PHONE$
	IF NAME.NEW$ = NAME$ OR NAME$ = LCASE$(NAME.NEW$) OR NAME$ = UCASE$(NAME.NEW$) THEN
		intKWCount = intKWCount + 1
' **** find the length of the variables
		IF LEN(NAME$) > intKWLen THEN intKWLen = LEN(NAME$)
		IF LEN(ADDRESS$) > intKPLen THEN intKPLen = LEN(ADDRESS$)
		IF LEN(PHONE$) > intKDLen THEN intKDLen = LEN(PHONE$)
		strKeyWord(intKWCount) = NAME$
		strKeyPath(intKWCount) = ADDRESS$
		strKeyDesc(intKWCount) = PHONE$
	END IF
LOOP

CLOSE #2

intKWLen = intKWLen + 2
intKPLen = intKPLen + 2
	
COLOR 1
CLS 2
COLOR 14

'*** parse the fields and print them

FOR intI = 1 TO intKWCount

' *** make the temp string long enough for the keyword, path, and dashes

	strTemp = STRING$(intKWLen + intKPLen + intDashLen, " ")

' *** stuff it with keyword, path, and dashes

	MID$(strTemp, 1, intKWLen) = strKeyWord(intI)
	MID$(strTemp, intKWLen, intKPLen) = strKeyPath(intI)
	MID$(strTemp, intKWLen + intKPLen - 1, intDashLen) = strDash

	LOCATE intRow, intCol
	PRINT strTemp

' *** parse the description so it is the length of intMaxDes

	DO

' *** check the description length

		IF LEN(strKeyDesc(intI)) > intMaxDes THEN

' *** shorten it if it is too long

			IF MID$(strKeyDesc(intI), intMaxDes, 1) = " " THEN
				strTemp = LEFT$(strKeyDesc(intI), intMaxDes)
				strKeyDesc(intI) = MID$(strKeyDesc(intI), intMaxDes + 1)
			ELSE
				intJ = intMaxDes

' *** find the first " " in the string that is less than intMaxDes

				DO
					IF MID$(strKeyDesc(intI), intJ, 1) = " " THEN EXIT DO
					intJ = intJ - 1
				LOOP

				strTemp = MID$(strKeyDesc(intI), 1, intJ)
				strKeyDesc(intI) = MID$(strKeyDesc(intI), intJ + 1)

			END IF
		ELSE
			strTemp = strKeyDesc(intI)
			strKeyDesc(intI) = ""
		END IF
		LOCATE intRow, intCol + intKWLen + intKPLen + intDashLen - 1
		PRINT strTemp
		intRow = intRow + 1
	LOOP UNTIL strKeyDesc(intI) = ""
NEXT intI

	 PRINT
	 COLOR 11
	 LOCATE , 6
	 PRINT "  The above represents all the information for that keyword entry."

FINISH: '
'
' subroutine FINISH works if you want to repeat the search
'
	 LOCATE 24, 15
	 INPUT "Do you wish to try another keyword search? Y/N  ", IFLAG$
	 IF UCASE$(IFLAG$) = "Y" THEN CLOSE #2: GOTO BEGIN2:
	 CLOSE #2
	 CLS 2
	 VIEW PRINT 5 TO 24
END SUB

SUB wind
CLS
SCREEN 9

' --------------------------------------------------------------------------------
' Define the window's properties.
' --------------------------------------------------------------------------------
'.
'.
'.

row = 10: height = 300       '10 AND 100
col = 10: length = 600       '10 AND 200

' --------------------------------------------------------------------------------
' Draw the form's boarder.
' --------------------------------------------------------------------------------

LINE (column, row)-(column + length, row + height), 0, B

' --------------------------------------------------------------------------------
' Create a border and fill it in.
' --------------------------------------------------------------------------------

FOR I% = 1 TO 2

row = row + 1: column = column + 1: height = height - 1: length = length - 1

LINE (column, row)-(column + length, row), 7
LINE (column, row)-(column, row + height), 7

NEXT I%

' --------------------------------------------------------------------------------
' Create the control box.
' --------------------------------------------------------------------------------

row = row + 1: column = column + 1: height = height - 1: length = length - 1

LINE (column, row)-(column + length, row), 0
LINE (column, row)-(column, row + height), 0
					 
LINE (column, row)-(column + 18, row + 18), 7, BF
LINE (column, row)-(column + 18, row + 18), 0, B

LINE (column + 18, row - 2)-(column + 18, row + 5), 0
LINE (column - 2, row + 18)-(column + 5, row + 18), 0
				 
' --------------------------------------------------------------------------------
' Create the click portion in the control box.
' --------------------------------------------------------------------------------

LINE (column + 5, row + 7)-(column + 13, row + 9), 15, BF: LINE (column + 5, row + 7)-(column + 13, row + 9), 0, B

' -------------------------------------------------------------------------------
' Add the click portion's shade.
' --------------------------------------------------------------------------------

LINE (column + 14, row + 7)-(column + 14, row + 9), 8
LINE (column + 6, row + 10)-(column + 14, row + 10), 8, B

' --------------------------------------------------------------------------------
' Create the title bar.
' --------------------------------------------------------------------------------

LINE (column + 18, row)-(column + length, row + 18), 9, BF
LINE (column + 18, row)-(column + length, row + 18), 0, B

LINE (column + length, row - 3)-(column + length + 2, row + height), 7, BF
LINE (column + length, row - 3)-(column + length + 3, row + height), 0, B

LINE (column + length, row - 2)-(column + length, row - 1), 7
LINE (column + length - 18, row - 2)-(column + length - 18, row - 1), 0

LINE (column + length, row + 18)-(column + length + 2, row + 18), 0

' --------------------------------------------------------------------------------
' Create the bottom line border and paint it.
' --------------------------------------------------------------------------------

LINE (column, row + height - 3)-(column + length, row + height - 3), 0, B
LINE (column, row + height - 2)-(column + length + 2, row + height), 7, BF
LINE (column - 2, row + height)-(column + length + 2, row + height), 0, B

' --------------------------------------------------------------------------------
' Get side break lines.
' --------------------------------------------------------------------------------

LINE (column - 2, row + height - 18)-(column, row + height - 18), 0
LINE (column + length - 2, row + height - 18)-(column + length + 2, row + height - 18), 0

LINE (column + 18, row + height)-(column + 18, row + height - 2), 0
LINE (column + length - 18, row + height)-(column + length - 18, row + height - 2), 0

' --------------------------------------------------------------------------------
' Paint the inner form.
' --------------------------------------------------------------------------------

LINE (column + 1, row + 19)-(column + length - 1, row + height - 4), 8, BF    '8
END SUB

