[comp.sys.mac.hypercard] Wanted: "Find Next"

n_hays@fennel.cc.uwa.oz.au (11/20/90)

I've been generally pleased with Hypercard 2 (my thanks to the team)
in spite of the fact that half my scripts died with its introduction.
One thing which I find a particular nuiscance, however, is the change 
to the way HC handles "finds".
I have a simple script designed to extract a copy of any line 
containing a particular word.
It runs along the lines of:
 
Put "foo" into ThingToFind
repeat until cooked
  find string ThingToFind
  do stuff with it
end repeat
 
The problem is that HC 1.x could always be relied upon to find the
NEXT example of ThingToFind on any given card. HC 2 always returns
to the first example. Moving to the next card is no good since there
may be two or more valid finds on the same card. Testing for the
"lastfound" works unless there are two or more examples on the
same card. It seems that I have to keep a track of some
arbitrary number of previously found examples and test for them
each time. This is kludgy in the extreme and slows things down a lot,
since HC has to find each example at least twice.
Am I missing something obvious here?
It seems to me that HC desperately needs a built in "Find Next"
command.
 
Neale Hays
 
ps. My thanks to Jim Taylor for mailing me the stack I wanted. 
It is much appreciated.
 
 
*********************************************************************
n_hays@fennel.cc.uwa.oz.au   University of Western Australia
I can't send mail, sorry.
*********************************************************************

batman@apple.com (Ken Laws) (11/22/90)

In article <1990Nov20.155800.2630@fennel.cc.uwa.oz.au> 
n_hays@fennel.cc.uwa.oz.au writes:
> One thing which I find a particular nuiscance, however, is the change 
> to the way HC handles "finds".
> I have a simple script designed to extract a copy of any line 
> containing a particular word.
> It runs along the lines of:
>  
> Put "foo" into ThingToFind
> repeat until cooked
>   find string ThingToFind
>   do stuff with it
> end repeat
>  
> The problem is that HC 1.x could always be relied upon to find the
> NEXT example of ThingToFind on any given card. HC 2 always returns
> to the first example.

I've tried to reproduce this, but without the exact script I can't.
A few tests using 2.0 and 2.0v2 reveal no changes from 1.2.5's behavior.
The only things I can think of (off the top of my head) that would cause 
this problem are:
A. You go to another card after finding.
B. You use the "click" or "drag" commands.

Ken Laws
HyperCard Team (Kevin is my boss... and a damn good one, too)

Disclaimer: Not to be taken internally.
            Void where prohibited.
            I don't speak for Apple.

n_hays@fennel.cc.uwa.oz.au (11/23/90)

In article <11336@goofy.Apple.COM>, batman@apple.com (Ken Laws) writes:
> In article <1990Nov20.155800.2630@fennel.cc.uwa.oz.au> 
> n_hays@fennel.cc.uwa.oz.au writes:
>> One thing which I find a particular nuiscance, however, is the change 
>> to the way HC handles "finds".
>> I have a simple script designed to extract a copy of any line 
>> containing a particular word.
>> It runs along the lines of:
>>  
>> Put "foo" into ThingToFind
>> repeat until cooked
>>   find string ThingToFind
>>   do stuff with it
>> end repeat
>>  
>> The problem is that HC 1.x could always be relied upon to find the
>> NEXT example of ThingToFind on any given card. HC 2 always returns
>> to the first example.
> 
> I've tried to reproduce this, but without the exact script I can't.
> A few tests using 2.0 and 2.0v2 reveal no changes from 1.2.5's behavior.
> The only things I can think of (off the top of my head) that would cause 
> this problem are:
> A. You go to another card after finding.
> B. You use the "click" or "drag" commands.
> 
> Ken Laws
> HyperCard Team (Kevin is my boss... and a damn good one, too)
> 
> Disclaimer: Not to be taken internally.
>             Void where prohibited.
>             I don't speak for Apple.
Ok - here it is. This script is designed to cycle through all the
cards of a stack except for the first which is special. It finds
all instances of a particular word and copies the sentences in which
that word appears to a field on the first card, together with info
about the card from which it was extracted. It ends when it finds
the example that it first found, so the first and last sentences are
the same. This is a reconstruction of my original script, but I've
tried it out with HC 1.2.5 and it works. In HC 2 it finds the first
example, selects the line, puts it in storehouse and, on the next
repeat, finds the first match again thereby bringing the script
to an end. HC 1.2.5 finds the NEXT match, either on another card
or somewhere else on the same card (unless there are no more matches
of course in which case the script ends).
As I said, its possible to kludge around this - but its ugly. Simply
repeating the "find string Wsearch" works unless there are two matches
on the same card - ie. it's dependant on moving to another card.
Any help much appreciated. 
On reflection, it occurs to me that the
problem is possibly not a different "find", but how long HC 2
"remembers" things. I have run across this problem before, with 
scripts that use values such as "the selection" as a variable. 
HC 1.2x remembers such a value for the duration of the handler, or
until it is changed, while HC 2 will forget it within the space of
a repeat loop.
 
 
 
 
on Wordsearch
  put empty into Wordsearchcount
  put empty into wordsearchtest
  put empty into wordsearchtest2
  ask "Find all Occurrences of Which Word?"
  if it is empty then exit to hypercard
  put it into WSearch
  put "Searching - please wait"
  go to first card of background "Standard"
  repeat
    find string Wsearch
    put the foundchunk into chunky
    select the foundline
    put the selection into eureka
    if eureka is empty then
      play "boing"
      put "Nothing Found"
      exit to hypercard
    end if
    if the id of this cd is the id of first cd then
      if Wordsearchcount is 0 then
        play "boing"
        put "Nothing Found"
        exit to hypercard
      end if
      exit repeat
    end if
    
    add 1 to Wordsearchcount
    
    if wordsearchcount = 1 then
      put field title into Wordsearchtest
      put chunky into Wordsearchtest2
    end if
    put eureka&&return&&field "author"&&return&&field "title"B
    &&return&&"-----------------------------------------------"B
    &&Return&&return after storehouse
    
    if wordsearchcount is not 1 then
      if field "title" = Wordsearchtest and chunky = B
      Wordsearchtest2 then
        exit repeat
      end if
    else
      next repeat
    end if
  end repeat
  go to first card
  put storehouse after cd field "Wordsearch"
  put wordsearchcount&&"Matches"&return before cd field "Wordsearch"
  if the visible of cd field "Wordsearch" is not "true" then
    send mouseup to button "Wordsearch"
  end if
  hide message box
end Wordsearch

Hmmm! the "option-return" character seems to have come out as a "B" - but
you get the idea.

Neale
**************************************************************************
n_hays@fennel.cc.uwa.oz.au   University of Western Australia

This University cannot afford to let me send mail!
**************************************************************************

smelly@polari.UUCP (Tom Benedict) (11/24/90)

I recommend avoinding the use of "the seletion" in your "Find Next" script
Selecting text usually 'resets' the Find command, because the find boxe is 
gone. Just get the foundtext frather than selecting the foundchunk.
(sorry this is so messy, I haven't fingured out how to backspace in this editor)

n_hays@fennel.cc.uwa.oz.au (11/25/90)

In article <2785@polari.UUCP>, smelly@polari.UUCP (Tom Benedict) writes:
> 
> I recommend avoinding the use of "the seletion" in your "Find Next" script
> Selecting text usually 'resets' the Find command, because the find boxe is 
> gone. Just get the foundtext frather than selecting the foundchunk.
> (sorry this is so messy, I haven't fingured out how to backspace in this editor)


The trouble is I'm after the whole sentence in which the found word occurs.
The "foundline" is no good - it returns a description of the line, rather
than its contents. 
I haven't found any way of avoiding using "the selection" in cases such as
this but please let me know if you have one.
Thanks
Neale

****************************************************************************
n_hays@fennel.cc.uwa.oz.au     The University of Western Australia

This University can't afford to let me send mail!
Blame W.A. Inc.
****************************************************************************

Barry.Chern@p4.f200.n226.z1.FIDONET.ORG (Barry Chern) (11/26/90)

n hays writes in a message to Tom Benedict on 24 Nov 90

NH> The trouble is I'm after the whole sentence in which the found 
NH> word occurs. The "foundline" is no good - it returns a description 
NH> of the line, rather than its contents. I haven't found any way 
NH> of avoiding using "the selection" in cases such as this

What you want, then, is "value of the foundLine".

B.
 
--  
Barry Chern via cmhGate - Net 226 fido<=>uucp gateway Col, OH
UUCP: ...!osu-cis!n8emr!cmhgate!200.4!Barry.Chern
INET: Barry.Chern@p4.f200.n226.z1.FIDONET.ORG

n_hays@fennel.cc.uwa.oz.au (11/26/90)

I wrote:

> The trouble is I'm after the whole sentence in which the found word occurs.
> The "foundline" is no good - it returns a description of the line, rather
> than its contents.

Garry Davis <gdavis@primate.wisc.edu> sent me mail suggesting I try
"the value of the foundLine". This has solved my problem - thanks very
much.
I look forward to the day it is possible to buy a book on HC 2 in this
part of the world. Or even get a copy of the release version of the help
stacks.

Neale
***************************************************************************
n_hays@fennel.cc.uwa.oz.au    The University of Western Australia
Bob Hawke and Paul Keating have decided I shouldn't be allowed to send mail.
***************************************************************************

smelly@polari.UUCP (Tom Benedict) (11/29/90)

u sh
you should be able to avoid selecting by evaluating the foundline.
The foundLine is a chunk experssion which can be evaluated using the VALUE
function. Just 'get the value of the foundLine' This should return the whole
line of text up to the next return character.
Good luck