The created text file has to come into a database with the following
fields, and in the following order:
Name
Company
Street Address
City, State
Zip Code
Phone 1
Phone 2
Phone 3
Phone 4
Check field
Tabs will separate the records, so it will be a standard merge file. More
fields than these can exist, and if you want to separate Last and First
Names, and State, that can be done in FileMaker later, or the script could
possibly be modified.
The check field will mirror the original HyperCard form of the database,
and so will contain much redundant information. However, since there will
always be data that we can't parse (titles, divisions, odd or foreign
addresses, etc.), we need this field so you can double-check your data, and
perform additional manipulations.
on mouseUp
ask "Please name the new text file." with "HC.txt"
if it is empty or the result is "Cancel" then exit mouseUp
put it into fileName
set cursor to watch
set lockMessages to true
set lockRecent to true
if number of bg fields = 0 then
answer "There are no background fields from which to export data!"
exit to HyperCard
end if
set lockRecent to true
open file fileName
lock screen
repeat the number of cards
set cursor to busy
--
-- Now figure the how many lines we have, and where the lines go.
-- Our rules:
-- If there are 3 lines, then they are Name, street address, citystatezip.
-- If there are more than 3 lines, then
-- the last line is citystatezip,
-- the next to last line is street
-- the third to last line is company
-- and whatever else is filler.
-- In all cases, the first line is Name.
put number of lines in bg field 1 into numFieldLines
repeat with i = 1 to numFieldLines
if line i of bg field 1 is empty
then exit repeat
else put i into lastLine
end repeat
-- Now we initialize our variables.
-- If we don't do this, then they may carry over their values to the next record.
put empty into theName
put empty into theCompany
put empty into theStreet
put empty into theCityAndState
put empty into theZip
if lastline > 2 -- If there are 3 or more lines of data
then
get line lastline of bg field 1
put last word of it into theZip
delete last word of it
put it into theCityAndState
end if
if lastline > 4 OR lastLine = 2
then put line 1 of bg field 1 & " *See Notes" into theName
else put line 1 of bg field 1 into theName -- Name
if (lastLine - 2) > 1 -- if there's a third to last line, it's company
then put line (lastLine - 2) of bg field 1 into theCompany -- company
if (lastLine - 1) > 1 -- if there's a second to last line, it's street
then put line (lastLine - 1) of bg field 1 into theStreet -- street
-- Here's our parsed information about the card.
put theName & comma & theCompany & comma & theStreet & comma & ┬
theCityAndState & comma & theZip & comma into theText
put line 1 of bg field 2 & comma after theText -- phone numbers
put line 2 of bg field 2 & comma after theText
if line 3 of bg field 2 is not empty
then put line 3 of bg field 2 & comma after theText
else put comma after theText
if line 4 of bg field 2 is not empty
then put line 4 of bg field 2 & comma after theText
else put comma after theText
put bg field 3 after theText -- move the date to the notes field
write theText & return to file fileName
go next card
end repeat
close file fileName
set lockRecent to false
unlock screen
end mouseUp
This article is adapted from the Claris Tech Info database.
Support Information Services