[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
HCGS Article 1
This is one of several articles I wrote on HyperCard GS. I've had some
e-mail asking that they be posted publicly, so here goes. If anyone uses
it in a newsletter, would they please post a copy of it to
Gareth Jones
#1, 3872 Sunset Street
Burnaby, British Columbia
CANADA
V5G 1T3
=============================
Filling the Addresses Stack
Gareth Jones
"Addresses" is one of the stacks that comes with the HyperCard
disks. It allows you to maintain a name-and-address book with plenty of
space for notes about your friends and business contacts. It also has
buttons for sorting the stack and finding any text in it quickly.
Although it is a good stack -- attractive and functional --
people may be put off using it by the idea of re-entering the information
that they are already keeping in a database file. I know, because my own
address list was kept in an AppleWorks GS database. However, I've found
that moving database or spreadsheet data into a stack can be simple and
straightforward.
The first step of the job is just to save the database as a text
file. In the case of AppleWorks GS, that means loading the database,
selecting "Save As..." from the File menu, and making sure that you click
the radio button for "ASCII text file" before you save the file.
The next step is to have a look at the text file you have saved.
Load it into a word processor and write down the order in which the
information was saved. In my file, for example, a person's full name
comes first, then the telephone number, the street address, and so on. As
is usual for databases and spreadsheets saved as text files, each of
these bits of information about a person is separated from the next by a
tab character; one person's information is separated from the next by a
return character.
Now go to the Addresses stack. You have some preliminary work to do:
1. Delete all cards except for the first and last.
2. Find ou the names of all the fields.
3. Use the "Save As..." menu selection to make sure that you
will have an unaltered copy of the stack to go back to if you make a
mistake in the next steps.
Now you have everything you need to import the text file.
1. Go to the first card.
2. Create a button. Double-click it with the button tool chose from
the Tools menu and type in a name for it. (I called it "Import," but give
it any name you want).
3. While the button information dialogue box is still on the screen,
click the "Script" button and type something similar to the following script.
Remember that everything that follows a double-dash ("--") is
just a comment to explain what a program line does. You won't need to
type the comments in!
on mouseUp
-- find the text file with your addresses
answer file "Where is the data file?" of type text
if it is empty then
exit mouseUp
else
put it into fileName
end if
set itemDelimiter to tab
-- each "item" is separated from the next by a tab
open file fileName
repeat forever
read from file fileName until return
-- read just one line from the file
put it into newLine
if it is empty then exit repeat
-- quit reading at the end of the file
doMenu "New Card"
-- create a new card, naturally
-- Adapt this to match the order of fields in your file
put item 1 of newLine into bkgnd field "Name"
put item 2 of newLine into bkgnd field "Telephone"
put item 3 of newLine into bkgnd field "Address"
put item 4 of newLine into bkgnd field "City"
put item 5 of newLine into bkgnd field "State"
put item 6 of newLine into bkgnd field "Zip Code"
put item 8 of newLine && item 9 of newLine && item 10 of newLine
into bkgnd field "Notes"
-- this saves the person's birthday and such in the "Notes" field.
end repeat
close file fileName -- you've finished with it
put "Finished" -- announce the fact that you're done
end mouseUp
When your script is done, close the script editing window and the
dialogue box, choose the browser tool (the one that looks like a hand)
from the Tools menu click on the button you have just created. The data
should import with no problems.
Now you have a unique stack with important personal information
in it. Save a backup copy of it on disk. If your hard drive crashes you
can re-install the original Addresses stack from your master HyperCard
IIgs disks, but your personalized copy may be destroyed. a little
forethought now can save you from losing track of your friends forever.