[comp.sys.mac.hypercard] Want find next button

utterbac@husc8.HARVARD.EDU (Margot Utterback) (10/13/89)

This has probably already been answered here, but I need a "find next" button.
I have a corporate directory which uses "find" to find the needed entry.
Since there may be several people with the same name I would like to be able 
to have the user press a button to find the next occurence.  I know at this
point the user can press return and find the next entry, put this is not 
obvious.  I tried "type return" but I just find the same occurence again!
This problem is noted in Danny Goodman's book, but there is no solution listed
there.

Margot

SAS102@PSUVM.BITNET (Steven A. Schrader) (10/13/89)

In article <2832@husc6.harvard.edu>, utterbac@husc8.HARVARD.EDU (Margot
Utterback) says:
>
>This has probably already been answered here, but I need a "find next" button.
>I have a corporate directory which uses "find" to find the needed entry.
>Since there may be several people with the same name I would like to be able
>to have the user press a button to find the next occurence.  I know at this
>point the user can press return and find the next entry, put this is not
>obvious.  I tried "type return" but I just find the same occurence again!
>This problem is noted in Danny Goodman's book, but there is no solution listed
>there.
>
>Margot

Try going to the next card and searching again.  This was the simplest solution
 I came up with.  Since you are not on the same card it will find the next occu
rance ...
-------
                    Steven A. Schrader
              (SAS102@Psuvm       SAS@Psuarch)
_________________________________________________________________________
                    227C Computer Building
                    The Pennsylvania State University
                    University Park, Pa. 16802
                    Phone : (814) 865 - 2160

                     343 Strouse Ave.
                     State College, Pa. 16803
                     (814)  237 - 8196

tim@hoptoad.uucp (Tim Maroney) (10/16/89)

In article <2832@husc6.harvard.edu> utterbac@husc8.UUCP (Margot Utterback) writes:
>This has probably already been answered here, but I need a "find next" button.
>I have a corporate directory which uses "find" to find the needed entry.
>Since there may be several people with the same name I would like to be able 
>to have the user press a button to find the next occurence.  I know at this
>point the user can press return and find the next entry, put this is not 
>obvious.  I tried "type return" but I just find the same occurence again!
>This problem is noted in Danny Goodman's book, but there is no solution listed
>there.

Please be sure to let us know if you find a solution, other than Steven
Schrader's idea of going to the next card and searching again.  (This
is probably adequate for your purposes, but not for mine; I'm searching
for text, not cards.  If it appears twice on a card, I want to see
both, one after the other.)  In general, the whole find mechanism is
underdocumented and underdeveloped; I've had a devil of a time getting
any sort of "Find next" functionality into my current stack project.

It seems that as soon as you do anything other than hit the return key
after finding, including pressing a menu equivalent key or a button,
HyperCard immediately loses the current "find selection", so you are
going to be searching from the start of the card again and finding the
same thing again.  And of course, if you do just hit return, then
you've lost a measure of control over finding; if you were searching in
a particular field, then too bad; return will find the next one in any
field.  Also, there's no control over which background you are
searching in any case, and we are all presumably aware of the problems
with searching for multi-word phrases.  And of course, you can't bypass
it and use the "contains" mechanism, because there's no way to select
something after you've found the offset and length of its substring.
Did I mention how stupid the hidden field handling is?

I've found the find mechanism to be the single most frustrating thing
about HyperCard.  Not only will it just not work as you would like (if
you think "find next" is hard, try doing a "replace" sometime), but
there is precious little documentation explaining just how it does
work.  This constantly leaves me with the feeling that they must have
put in a way to do what I want, but they didn't bother to tell us peons
how to do it.  It seems they're perfectly happy to make naive users
use the message box.  I'm not.
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

"It is better to be a human being dissatisfied than a pig satisfied;
 better to be Socrates dissatisfied than a fool satisfied."
	-- John Stuart Mill, UTILITARIANISM (1863)

Barry.Chern@f200.n226.z1.FIDONET.ORG (Barry Chern) (10/18/89)

Tim Maroney writes:
>Please be sure to let us know if you find a solution, other than Steven
>Schrader's idea of going to the next card and searching again.  (This
>is probably adequate for your purposes, but not for mine; I'm searching
>for text, not cards.  If it appears twice on a card, I want to see
>both, one after the other.)
  
Well, I thought there must be an easy way to do this. I was wrong. Even if 
you select after the first find, it still goes back and finds it again.
But I did come up with a work-around. If somebody else already had a
cleaner way to do this, I'd like to be reminded of it. My version
basically keeps track of how many finds you've done on the card. If you
already found one instance, it does two finds, if you've found 2, it finds 
3 times, etc. 
 
You'll notice that my "find" script has a line that says Find "D". this
was just my test stuff, you'll have to get your find info in there
somehow. You'll probably also want to add a lockscreen, so you don't see
all those sequential finds taking place. Here's the scripts.
Find button: (if you weren't using a button for your find, you don't need
the
globals. Just get the stuff to find into findWhat and put 2 into findNo at 
the
beginning of the Find Next script.)
   
on mouseUp
  global findWhat
  global foundlast
  global findNo
  put 1 into findNo
  put "d" into findWhat
  find findWhat
  put the foundchunk into foundlast
  add 1 to findNo
 end mouseUp
   
  
Find Next button:
  
on mouseUp
  global foundlast
  global findwhat
  global findNo
  put the id of this cd into thisCd
  select after foundlast
  repeat for findNo
    find findwhat
  end repeat
  put the foundchunk into foundlast
  if the id of this cd = thisCd then
    add 1 to findNo
  else
    put 2 into findNo
  end if
 end mouseUp
 
Hope everyone tests this out and gets back to me with bugs and
improvements.
Barry.
   
** Origin : Aurora Borealis BBS - 614-471-6209 - 9600 HST - 1:226/200 **
 

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

tim@hoptoad.uucp (Tim Maroney) (10/21/89)

Barry Chern's idea of refinding successive times and keeping track of
how many makes sense -- I also received an e-mail message discussing a
variant on this technique.  However, given the new features added to
HyperTalk in 1.2.1, and documented in the Release Notes stack that came
with it, it can be even easier.  After any find, simply select the
found text.  The next find command will start looking after the
selection.  This is how most text editors on the Mac work, and it
presents an intuitively obvious interface.  The command to do so is
just "select the findChunk".

Thanks to those on the net who told me to read the Release Notes stack,
which I had only been dimly aware existed, and which I assumed was
simply documentation of bug fixes.  In fact, it is an indispensable
addition to the on-line documentation.  I agree with the person who
wrote me and said that it was awfully slack that they hadn't updated
the on-line manual with the new features.  It would have saved me days
of head-scratching about the Find command if I'd known.
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

"Now hear a plain fact: Swedenborg has not written one new truth: Now hear
  another: he has written all the old falshoods.
 And now hear the reason.  He conversed with Angels who are all religious, &
  conversed not with Devils who all hate religion..."
    - Blake, "The Marriage of Heaven and Hell"

tim@hoptoad.uucp (Tim Maroney) (10/23/89)

In article <8764@hoptoad.uucp> tim@hoptoad.UUCP (Tim Maroney) writes:
>After any find, simply select the
>found text.  The next find command will start looking after the
>selection.  This is how most text editors on the Mac work, and it
>presents an intuitively obvious interface.  The command to do so is
>just "select the findChunk".

No, Tim, you idiot.  You should have tried it before making this
suggestion.  First, there's a display bug.  If you find successfully
and then "select the findChunk", then the text appears selected, but as
soon as the user does anything, the findChunk goes away, leading to the
text becoming unselected in appearance, even though it is still the
selection.  Selecting a range and finding it have different
rectangles.  Try and see what I mean -- finding a phrase in a title
field gives a rectangle which stops at the last letter of the title;
selecting the findChunk at this point selects all the way to the end of
the line on which the last word appears; so after the findChunk
vanishes, you're left with a spurious black rectangle starting right
after the last letter and going to the end of the line.

Second, the find command does *not* start after the current selection.
It starts at the end of the findChunk or at the beginning of the
current card (if there is no findChunk).  So this technique leads to
display anomalies and to finding the same string over and over again.
What a pain.

It looks like we're stuck with counting the "find index" of each string
in the card, then repeating the search that many times plus one on
"find next".  This is so nasty a hack that I believe it qualifies as a
bug in HyperCard.  There should be some global property specifying a
chunk expression for the next search to start at.  There isn't one in
HC 1.2.1; does anyone know if this has been added in a later version?
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

"There's a real world out there, with real people.  Go out and play there for
 a while and give the Usenet sandbox a rest.  It will lower your stress
 levels and make the world a happier place for us all." -- Gene Spafford

tsung@aerospace.aero.org (Fu-Sheng Tsung) (10/31/89)

One way to do "find next" in a field is to write your own "find"
routine in the script.  Say you found the string on line N the first
time, and that the field has M lines.  "Find next" would search for
the string beginning at line N+1 of the field; that is, you can

	global N, M
	get offset(searchString,line N+1 to M of field "Text")
	if it <> 0 then  -- string found
		-- update scrolling
		select char it to length(searchString) + it -1 of\
		line N to M of field "Text"
		-- update N (+ the number of lines in char 1 to it of ...)
	else
	  -- not found, or no more occurances

The main trick here is that you can actually specify a subfield ("line
N to M of field") in place of a field specification.  This is more
work than Barry's "index find" method, e.g. you need to update the
scrolling yourself, but the operation can look very nice (and
consistent with "Find") to the user.

Fu-Sheng Tsung