put "Enter a five digit zip code." into field "displayResults"
end InitializeFields
on checkKey
set x = charToNum(the key)
if (x < 48 OR x > 57) AND x <> 8 then dontPassEvent
if length(field "zipHole") = 5 AND x <> 8 then dontPassEvent
end checkKey
on checkFieldLength
if length(field "zipHole") = 5 then go frame "sea"
end
on searchAndReport
global index, zip, foist
set foist = 1
put EMPTY into field "displayResults"
if length(field "zipHole") < 5 then
put "Please enter five digits and press return." into field "displayResults"
put empty into field "zipHole"
else
put "Let me look up zip code" && field "zipHole" & "." & RETURN ¼
& "Back in a flash!" into field "displayResults"
put field "zipHole" into zip
put (char 1 to 2 of field "zipHole") into xx
set flag = 0
set index = 1
repeat while (line (index) of field xx <> empty)
if line (index) of field xx contains zip then
report (xx)
set flag = 1
end if
set index = index + 5
end repeat
put string (value (xx) - 1) into xy
if value (xy) < 0 then put "00" into xy
if length (xy) < 2 then put "0" before xy
set index = 1
repeat while (line (index) of field xy <> empty)
if line (index) of field xy contains zip then
report (xy)
set flag = 1
end if
set index = index + 5
end repeat
put string (value (xx) - 2) into xz
if value (xz) < 0 then put "00" into xz
if length (xz) < 2 then put "0" before xz
set index = 1
repeat while (line (index) of field xz <> empty)
if line (index) of field xz contains zip then
report (xz)
set flag = 1
end if
set index = index + 5
end repeat
if flag = 0 then
put "To locate a dealer near you:" & RETURN & "Call 1-800-GO-TOYOTA!" into field "displayResults"
else
put RETURN after field "displayResults"
end if
put EMPTY into field "zipHole"
end if
end searchAndReport
on report zz
global index, zip, foist
if foist = 1 then put "The Toyota Dealer(s) nearest to zip code" && zip && "is(are):" & RETURN into field "displayResults"
put RETURN & line (index + 1) of field zz & RETURN & line (index + 2) of field zz & RETURN after field "displayResults"
put word 1 to 3 of line (index + 3) of field zz after field "displayResults"
set x = charToNum (char 1 of word 3 of line (index + 3) of field zz)
if (x < 48 OR x > 57) then put " " & word 4 of line (index + 3) of field zz after field "displayResults"
set x = charToNum (char 1 of word 4 of line (index + 3) of field zz)
if (x < 48 OR x > 57) then put " " & word 5 of line (index + 3) of field zz after field "displayResults"
set x = charToNum (char 1 of word 5 of line (index + 3) of field zz)
if (x < 48 OR x > 57) then put " " & word 6 of line (index + 3) of field zz after field "displayResults"
set x = charToNum (char 1 of word 6 of line (index + 3) of field zz)
if (x < 48 OR x > 57) then put " " & word 7 of line (index + 3) of field zz after field "displayResults"
put RETURN & "(" & char 1 to 3 of line (index + 4) of field zz ¼
& ") " & char 4 to 6 of line (index + 4) of field zz ¼
& "-" & char 7 to 10 of line (index + 4) of field zz & RETURN after field "displayResults"
set foist = 0
end report
---PARSING HANDLERS
on openFile whichFile
global gFileHandle
if objectP(gFileHandle) then gFileHandle(mDispose)
set gFileHandle = fileIO(mNew, "READ", the pathname & whichFile)
end
on resetFilePosition
global gFileHandle
gFileHandle(mSetPosition, 0)
end
--on translateLine textString
-- global gNewRecord
-- set buffer = ""
-- set itemList = []
-- repeat with n = 1 to the number of chars in textString
-- beep
-- if char n of textString <> " " then
-- set buffer = buffer & char n of textString
-- set spacePrevious = FALSE
-- else
-- if spacePrevious = TRUE AND buffer = "" then
-- nothing
-- else if spacePrevious = TRUE then
-- delete char the number of chars in buffer of buffer
-- append itemList, buffer
-- set buffer = ""
-- else
-- set buffer = buffer & char n of textString
-- set spacePrevious = TRUE
-- end if
-- end if
-- end repeat
-- delete char the number of chars in buffer of buffer
-- append itemList, buffer
-- set gNewRecord = ""
-- repeat with n = 1 to count (itemList)
-- set gNewRecord = gNewRecord & TAB & getAt(itemList, n)
-- end repeat
-- delete char 1 of gNewRecord
--end
on translateLine whichLine
global gNewRecord
set gNewRecord = char 1 to 30 of whichLine & TAB & char 31 to 60 of whichLine & TAB & char 61 to 73 of whichLine & TAB & char 74 to 84 of whichLine & TAB & char 85 to 100 of whichLine & TAB & char 101 to (the number of chars in whichLine) of whichLine
end
on condenseFile
global gFileHandle, gNewRecord, gWriteFileHandle
if objectP(gWriteFileHandle) then gWriteFileHandle(mdispose)
set gWriteFileHandle = fileIO(mNew, "WRITE", the pathName & "NEW DB")
openFile "FRAN.TXT"
set gOriginalString = gFileHandle(mReadFile)
repeat with n = 1 to the number of lines in gOriginalString
if line n of gOriginalString <> "" then
set currentLine = line n of gOriginalString
if currentLine contains "Unas" or currentLine contains "unas" then