Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!rpi!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!midway!quads.uchicago.edu!chh9 From: chh9@quads.uchicago.edu (Conrad Halton Halling) Newsgroups: comp.sys.mac.hypercard Subject: Re: HC find quirks Message-ID: <1990Sep18.000821.4752@midway.uchicago.edu> Date: 18 Sep 90 00:08:21 GMT References: <1990Sep14.223831.17977@athena.mit.edu> <1990Sep14.232310.5317@midway.uchicago.edu> <1990Sep17.134816.4589@athena.mit.edu> Sender: news@midway.uchicago.edu (News Administrator) Distribution: comp.sys.mac.hypercard Organization: University of Chicago Lines: 133 In article <1990Sep17.134816.4589@athena.mit.edu> shawn@e40-008-11.athena [signed: shawn@athena.mit.edu] (Shawn O'Donnell) writes: >[stuff deleted] >I tried the two searches manually, and they worked properly. In the >script, though, they don't work. I don't think I'm doing anything >between the two find commands that should disturb the process... >[stuff deleted] After much experimentation, I have found the answer to Shawn's problem: *** Have the script click at some safe location (such as 0, 0) after *** *** the first find command. This resets some internal marker in *** *** HyperCard (what, I don't know, but it works!). The next find in *** *** a different field will begin on the same card. *** Lengthy details follow: When the two searches are done manually, as soon as you begin typing in the message box, you'll notice that the box around the text from the first find disappears; the result is that you have reset the find command simply by typing into the text box. Here is how I set up my experimental stack: Background "Index" contains a single card which contains bg fld "index" with the following contents: Subject_1 Topic_1 Topic_2 Topic_3 Subject_2 Topic_1 Topic_2 Topic_3 Subject_3 Topic_1 Subject_4 Topic_1 Topic_2 Background "ItemCards" contains as many cards as you like, with bg fld "subject" and bg fld "topic". put "Subject_1" into fld "subject" of cd 1 of bg "itemCards" put "Topic_1" into fld "topic" of cd 1 of bg "itemCards" put "Topic_2" into fld "topic" of cd 2 of bg "itemCards" [if the cards are in order, the subject field can remain empty.] etc. Lock the text of fld "index" of bg "index" and place the following handler into the script of fld "index": on mouseUp -- put the selectedLine into variable lineSelection and highlight -- the selectedLine for visual feedback set cursor to watch lock screen get the clickLoc set lockText of field "Index" to false click at it put the selectedLine into lineSelection set the lockText of field "index" to true unlock screen select lineSelection -- hide results of find commands and card movements lock screen -- put the contents of the selectedLine into variable lineText -- the "do" command is necessary here; otherwise lineText will -- contain the text in lineSelection ("line X of bkgnd fld 1"). do "put " & lineSelection & " into lineText" -- find the subject and topic; topics begin with space & space put empty into subjectText put empty into topicText if char 1 of lineText is space then put lineSelection into tempSelection repeat until subjectText is not empty -- back up one line put ((word 2 of tempSelection) - 1) into word 2 of tempSelection do "put " & tempSelection & " into tempText" if char 1 of tempText <> space then put tempText into subjectText put lineText into topicText end if end repeat else put lineText into subjectText end if -- find the first card with the subject -- You have to go to the first card of bg "itemCards" before -- performing the find; if you don't, even though you have requested -- 'bg fld "subject"', for some reason this gets translated by HyperCard -- into "bkgnd fld 1", and HyperCard simply finds the subject in -- fld "index" of bg "index" (which is "bkgnd fld 1"). go to card 1 of bg "ItemCards" find subjectText in fld "subject" -- click at a safe location where there is no button or field that -- will respond to a mouseDown or mouseUp; this resets the find -- command so it will begin the next search with the current card click at 0, 0 -- find the first card with the topic if topicText is not empty then find topicText in fld "topic" click at 0,0 end if unlock screen end mouseUp This script has been tested, and I know it works. Many odd things about the behavior of HyperCard turned up during my experimentation; these are described in the comments of the script. Since I don't have a definitive description of HyperCard, my approach to writing scripts is to experiment until I find what works. Everytime I try something, I learn something new. I saved my stack; if you, Shawn (or anyone else), want it, e-mail a request BY FRIDAY (after which I will discard the stack) and I will send you a binHexed Stuffit archive by e-mail. -- Conrad Halling chh9@midway.uchicago.edu