HyperCard: Script for Importing Comma-Separated Text (7/92)

This article provides a script that will import a comma-separated text file
into HyperCard. It assumes that:
* There is a comma between fields.
* There is a return between records.
* If a field itself contains a comma, then the field has quote marks around
(though it will work just as well if ALL fields have quotes around them).

on mouseUp
answer file "Import from which file?" of type text
if it is empty then exit mouseUp
put it into fileName
open file fileName
go to last card
repeat forever

read from file fileName until return
if it is ∫mpty then
go to first card
close file fileName
exit mouseUp
else
doMenu "New Card"
put "," into last char of it
end if

repeat with x=1 to the number of fields
if char 1 of it is quote then
put char 2 to offset(quote&",",it) - 1 of it into field x
delete char 1 to offset(quote&",",it) of it
else
put char 1 to offset (",",it) - 1 of it into field x
delete char 1 to offset (",",it) of it
end if

end repeat
end repeat
end mouseUp


This article is adapted from the Claris Tech Info database.
Published Date: Feb 19, 2012