...we
can't start without a keyword to search!!
If "[Keyword]" "=" ""
AlertBox "Search Error"
"Please enter a keyword to search"
GotoLine "EX"
EndIf
SetVar "[matches]" "0"
.
Initiate [xf] to start at record #1
SetVar "[xf]" "1"
.
Aquire the number of records in the database
FileLen "[PubDir]data.dat"
"[datalen]"
.
loop until [xf] is less than (and equal to) the number of records
While "[xf]" "<="
"[datalen]"
.
Read in the full line of data and get it's length
FileRead "[PubDir]data.dat"
"[xf]" "[fulline]"
StrLen "[fulline]" "[linelen]"
.
Parse out the first element of the string
SearchStr "*" "[fulline]"
"[pos]"
SubStr "[fulline]" "1"
"[pos]-1" "[Element]"
SubStr "[fulline]" "[pos]+1"
"[linelen]" "[fulline]"
.
Use [Sub] as a place marker to come back to after
.
program flow moves on to the COMPARE routine
SetVar "[Sub]" "SUB2"
.
Go to the COMPARE Subroutine
GotoLine "COMPARE"
.
Place marker for program flow
:SUB2
SearchStr "*" "[fulline]"
"[pos]"
SubStr "[fulline]" "1"
"[pos]-1" "[Element]"
SubStr "[fulline]" "[pos]+1"
"[linelen]" "[fulline]"
SetVar "[Sub]" "SUB3"
GotoLine "COMPARE"
:SUB3
SearchStr "*" "[fulline]"
"[pos]"
SubStr "[fulline]" "1"
"[pos]-1" "[Element]"
SubStr "[fulline]" "[pos]+1"
"[linelen]" "[fulline]"
SetVar "[Sub]" "SUB4"
GotoLine "COMPARE"
:SUB4
SetVar "[Element]" "[fulline]"
SetVar "[Sub]" "SUB5"
GotoLine "COMPARE"
:SUB5
.
Add "1" to the search loop, [xf]
Math "[xf]+1" "" "[xf]"
EndWhile
GotoLine "END" ...
(skip compare routine)
:COMPARE
.
Compare [Element] to the users [Keyword]
If "[Element]" "=" "[Keyword]"
.
Match found so
...set
[x] to the same value/record# as [xf]
...set
[matches] to value of 1
SetVar "[matches]" "1"
SetVar "[x]" "[xf]"
.
Move on to read record number [x] and parse data
GotoLine "RESULTS"
:ASK
.
Ask the user if this match was the record they wanted
MessageBox "Search:
[Element]" "[First] [Last]|[Email]|[Phone]||Is this what you were searching
for?" "Yes|No" "[ask_find]"
.
"Yes" was the users answer!
If "[ask_find]" "="
"1"
SetVar "[x]" "[xf]"
SetVar "[xf]" "[datalen]+1"
Else ...
from
.
"No" was the users answer
GotoLine "[Sub]"
EndIf
Else ...
(from If "[Element]" "=" "[Keyword]")
GotoLine "[Sub]"
EndIf ...
(from If "[Element]" "=" "[Keyword]")
GotoLine "END" ...
(skip results)
:RESULTS
.
Parse out record number [x] for displaying...
FileRead "[PubDir]data.dat"
"[x]" "[fulline]"
StrLen "[fulline]" "[linelen]"
SearchStr "*" "[fulline]"
"[pos]"
SubStr "[fulline]" "1"
"[pos]-1" "[Last]"
SubStr "[fulline]" "[pos]+1"
"[linelen]" "[fulline]"
SearchStr "*" "[fulline]"
"[pos]"
SubStr "[fulline]" "1"
"[pos]-1" "[First]"
SubStr "[fulline]" "[pos]+1"
"[linelen]" "[fulline]"
SearchStr "*" "[fulline]"
"[pos]"
SubStr "[fulline]" "1"
"[pos]-1" "[Email]"
SubStr "[fulline]" "[pos]+1"
"[linelen]" "[fulline]"
SetVar "[Phone]" "[fulline]"
...and
return to where we left-off
GotoLine "ASK"
:END
.
if no matches were found display a message to this affect
If "[matches]" "<>"
"1"
AlertBox "Search" "There
were no matches for [Keyword]"
EndIf
:EX
.
Reset the variables for the next search
SetVar "[Element]" ""
SetVar "[Keyword]" ""