Jeanne's World House o' HyperCard Scripts of the Month |
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:
type
command) places the typed text in the message box. The final return character executes the contents of the message box, just as though the user had pressed the Return key.
blindTyping
property to true lets you type into a hidden message box without making it visible. Since the handler sets the blindTyping
to true, the type
command doesn't cause the message box to pop up the way it normally would when text is typed into it.
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
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