on mouseup answer file "Which file would you like?" of type text --gives us an 'Open File' dialog box put it into filename --puts our selection into a variable open file filename --opens the file we've selected read from file filename for 16000 --reads the first 16000 characters put it into card field 1 --puts the characters into our field close file filename --closes the file end mouseup
After you've typed the script above (you do not need to type in the comments following the double hyphens), click on close and click on "Yes" to the query of whether you want to save the changes. Now close the Button Info box, and try it out. Click on th e button, and you should get the standard 'Open File' dialog box, which will let you open a text file for reading into your card's field. We only read the first 16000 because that is a limit of HyperCard IIGS, which it inherited from its Macintosh predec essor. Now that you have a working import button, we need to create a button that will help us save text. Begin by creating another new button, and place it under the "Open Text File" button. Double-click the button to bring up the Info box, and name thi s button "Save Text File". Choose an icon as before, then click on the script button and type in this script:
on mouseup --this handler exports text ask file "Name your text file" --brings up 'Save As' dialog if it is not "" then --if name isn't blank, puts --name into variable "exName" open file exName --opens a file with the name --stored in variable write card field 1 to file exName --puts contents into new file close file exName --closes file (thus saving it) else exit exportText --if name's blank, exit end if choose browse tool --picks browse tool end mouseup
This script will give you a typical 'Save As' dialog box which you can use to name a file. HyperCard then opens the file (when HyperCard opens a file that doesn't exist, it creates it first, then opens it for reading/writing) and writes the contents of y our text field to the file. The file is then closed, and thus you have used HyperCard to create and save a text file. Whoa! you may be thinking, does this mean I didn't need to go out and buy AppleWorks GS after all? I could have had it all in HyperCard? Well, not exactly. You can make a perfectly good text editor with HyperCard, able to open and save files, do right, left or center justification (only one though), with a font and size of your choosing. But you have to deal with the restrictions of only one font/size and justi-fication per field, and small file size. However, you may find that certain stacks lend themselves to these types of use, and being able to have these buttons is a great time saver. For example, a class-room might want to create a digital yearbook. Each card could have a field with a biography of each student, which they might write on their own in Appleworks or FrEdWriter. Saving the files as text, the kids can give their disks to the yearbook editor, who can import the story to a card in the HyperCard stack, where it can be further custom-ized with a photograph, a sound clip of the student, artwork, etc.
One of the great advantages of HyperCard is that it is object-based. Having created these import and export buttons, we can select the button tool, select the button, and choose "Copy Button" from the "Edit" menu, then paste the button into an entirel y different stack. Not only will the visual button be copied, but so will the script associated with it. When HyperCard Mac's creator Bill Atkinson called HyperCard a software erector set, this is just what he had in mind. Individual modules that can be assembled piece by piece into unique software solutions for your needs. Almost everything you see on a HyperCard IIGS card can be copied: buttons, fields, background graphics, so as you create useful buttons and scripts you can transfer them to other sta cks without having to create all of your work from scratch. So use these two buttons in your stacks and give your stacks the ability to move text around. Posted to Genie and my Web site are copies of "HC.Word" my own implementation of these concepts. HC.Word has text in and out buttons, as well as justification buttons and a choose font button, for a pretty functional text editing stack. The stack is not locked, so you can freely browse and use the HyperTalk s cripts in your own stacks. If you don't have access to the Web or Genie, you can order a disk from me that has HC.Word, along with other HyperCard IIGS stacks on it for $5.00, which includes the shipping. The full contents of the disk are:
If you are interested in the disk, send a check or money order for $5.00 made out to me at:
Steve Cavanaugh
The Apple Blossom
8 Ardsley St.
Brockton, MA 02402.