[comp.sys.mac] File I/O in HyperTalk

winkler@apple.UUCP (Dan Winkler) (09/04/87)

Here is an example of file I/O in HyperTalk that imports and exports
text.  The open file command does not use the documents search path --
it simply passes the name you gave, which could include a path, to
FSOpen.  If the file does not exist, HyperTalk automatically creates it
and then opens it.

on mouseUp
  -- export text
  put the short name of this stack & " text" into fileName
  ask "Export text to what file?" with fileName
  if it is empty then exit mouseUp
  put it into fileName
  open file fileName
  go to first card
  repeat for the number of cards
    repeat with i = 1 to the number of fields
      write field i to file fileName
      write tab to file fileName
    end repeat
    go to next card
  end repeat
  close file fileName
end mouseUp

on mouseUp
  -- import text
  ask "Import text from what file?"
  if it is empty then exit mouseUp
  put it into fileName
  open file fileName
  repeat
    doMenu "New Card"
    repeat with i = 1 to the number of fields
      read from file fileName until tab
      if it is empty then -- end of file
        if i = 1 then doMenu "Delete Card"
        close file fileName
        exit mouseUp
      end if
      delete last char of it  -- kill tab
      put it into field i
    end repeat
  end repeat
end mouseUp