Jeanne's World
   House o' HyperCard
       Scripts of the Month

Jeanne's House o' HyperCard:


Find It Again, Sam
Using the Power of the Message Box

When you use HyperCard's Find menu item, you can keep pressing the Return key to find the next occurrence of the string. People often ask how they can get this behavior from a scripted find. The answer is to use the invisible power of the message box:

  on mouseUp
    ask "What do you want to find?"
    if the result is "Cancel" then exit mouseUp
    put it into myString
    set the blindTyping to true
    type "find" && quote & myString & quote & return
  end mouseUp

This handler places a find command in the message box, without making the box visible. This is how it's done:

Using Other Commands

Of course, you can use any variant of the find command in place of the plain find above by changing the string you put into the message box:

find whole "Hello there"
find string international (the short name of this card)
find chars stuffToFind of marked cards

You can substitute any other command (assuming, of course, that it's a command that makes sense for the user to execute over and over). For example, the go and doMenu "New Card" commands might be useful in some stacks.

  on markTheCards theCriterion
    unmark all cards
    do "mark cards where" && theCriterion
    set the blindTyping to true
    type "go next marked card" & return
    -- the user can scan the marked cards
    -- by pressing Return over and over
  end markTheCards

Setting Up Multiple Commands


Little-known find fact:
The visual effect command can be used with find:
on findYourself
  ask "What's your name?"
  put it into userName
  visual effect dissolve
  -- the effect is seen...
  find userName
  --...when find switches cards
end findYourself

In fact, you can use not just single commands, but any string that can be executed in the message box. So since the message box (in HyperCard 2.0 and later) can handle "do", you can also use this trick for multi-line commands, as long as the total is less than 256 characters.

Suppose the string you want to find has been placed in the variable theString, and you want to execute the commands

  visual effect dissolve fast
  find whole theString

To accomplish this, you'll need to place this text in the message box:

do "visual effect dissolve fast" & return & "find whole"

along with the contents of theString in quotes. Your handler will look like this:

  on findWithVisual theString
    if theString is empty then
      ask "What do you want to find?"
      if the result is "Cancel" then exit findWithVisual
      put it into theString
    end if
    set the blindTyping to true
    type "do" && quote & "visual effect dissolve fast" ¬
    & quote && "& return &" && quote & "find whole" ¬
    & quote && "&& quote &" && theString && "& quote"
  end findWithVisual

Jeanne A. E. DeVoto jaed@jaedworks.com