Newsgroups: comp.sys.apple2 Path: news.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!cs.utexas.edu!wupost!waikato!comp.vuw.ac.nz!actrix.gen.nz!dempson From: dempson@swell.actrix.gen.nz (David Empson) Subject: Re: Hypercard Question Organization: Actrix Information Exchange Date: Sun, 16 Jan 1994 03:52:36 GMT Message-ID: References: <199401152053.PAA13705@bottom.magnus.acs.ohio-state.edu> Sender: dempson@actrix.gen.nz (David Empson) Lines: 171 In article <199401152053.PAA13705@bottom.magnus.acs.ohio-state.edu> snash@magnus.acs.ohio-state.edu (Steven E Nash) writes: > I was wondering if there is someone out there who has an xcmd or > something that will allow me to save the text in one of my hypercard > stacks to a text file or even an applewoks file. I have my address > in a Hypercard stack and I have no way to save them as a text file > so I can print them out. You don't need an XCMD to do this - you can write a simple HyperCard script to extract the addresses. The simplest solution is a button which will write the details on the current card to a text file. A more elegant solution would be to write all of the cards out to a file. I'm assuming you are using the 'Addresses' stack that was supplied with HyperCard IIgs. I'm working from HCGS 1.1, so I'm not sure if any changes were made to the field names, etc. from version 1.0. The address card is laid out as follows: Name One line Company One line Address Two lines City One line State One line Zip Code One line Telephone Four lines Notes Eleven lines (you can type more than this, but will only be able to read the first eleven). The following script will write out each line to a text file, with tabs separating the fields. This can be imported into the AppleWorks data base as 22 categories (Name, Company, Address-1, Address-2, City, State, Zip Code, Telephone-1 through 4, Notes-1 through 11). If you didn't press RETURN between the lines of the address field (i.e. you used word wrapping to get to the next line), it will be output to the text file as a single line, and the second line will be blank. You will have to be in 'Scripting' mode in HyperCard to enter this script (go to the last card of the Home stack to change the level). Get back into the Addresses stack, and use 'Save a Copy...' from the File menu. Save the addresses stack somewhere else, as a backup copy in case you do something wrong. Now choose 'Stack Info...' from the Object menu. Click on the 'Script...' button in the dialog box. Scroll down to the bottom of the script, then add the following text (after the nameSort handler). HyperCard will automatically indent the script correctly, and it should look like this when you've finished. on writeAllCards ask "Save address list as:" with "Addresses.txt" if it is empty then exit writeAllCards put it into filename delete file filename put the result into error if error is not empty and word 2 of error is not 70 then answer "Unable to delete existing file:" && filename exit writeAllCards end if open file filename if the result is not empty then answer "Unable to create file:" && filename exit writeAllCards end if lock screen push card put the number of cards of background "Addresses" into count repeat with n = 1 to count set cursor to busy go to card n -- Note: whereever I have put a backslash, type option-return, which -- will appear as a 'not' symbol (a sideways reflected 'L'). put field "Name" & \ tab & field "Company" & \ tab & line 1 of field "Address" & \ tab & line 2 of field "Address" & \ tab & field "City" & \ tab & field "State" & \ tab & field "Zip Code" into it set cursor to busy repeat with i = 1 to 4 put it & tab & line i of field "Telephone" into it end repeat set cursor to busy repeat with i = 1 to 11 put it & tab & line i of field "Notes" into it end repeat write it & return to file filename end repeat pop card close file filename end writeAllCards If you would prefer to have the fields on separate lines, then replace each 'tab' in the script with 'return'. Now all we need to do is provide some way of calling up the script. I suggest adding another item to the "Addresses" menu. Go back up to the top of the script. On the first page, there is a section which starts "on openStack". A little way down into this is the following: if AddressMenu is empty then put addMenu(" Addresses ","Sort by Name" & return & \ "Sort by Company" & return & "Sort by City" & return & \ "Sort by State" & return & "Sort by Zip Code" & return & "-" & \ return & "Preferences") into AddressMenu Immediately before the last line of this, add: return & "Save to text file..." & return & "-" & \ Again, the backslashes are actually option-return. You will have to delete the extra blank line that is created when you press option-return after the new line. Scroll down through the script until you come to: on doMenu choice About half way through this function, you will see: else if choice is "Preferences" then Between the 'else' and 'if' lines, add: if choice is "Save to text file..." then writeAllCards else You will also need to add another 'end if' line before the 'end doMenu' line. You can press the TAB key to force HyperCard to re-align the text to check that you have the indentation right. When you've finished making changes, click the 'OK' button at the bottom of the script editor. You will have to leave the stack and return to it before the new menu item will appear. When you choose this item, it should ask you for a filename (prompting you with a default of 'Addresses.txt'). You can select an appropriate directory, change the name if required, then click 'Save'. (If you click 'Cancel', then nothing else will happen.) The script will take a while to write out all of the cards - about three seconds per card on an unaccelerated IIgs. I wrote this script on my other IIgs while typing it in here, and it seems to work fine. Assuming I made no typos, it should work for you. If you have any problems, E-mail me, and I'll see if I can help. -- David Empson dempson@swell.actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand