HyperCard: Various Search Scripts

You'll often use HyperCard to search for specific information. The usual way to do this is with the Find command in the message box, but sometimes a button that searches only specific fields is more appropriate.
The standard Find command searches all text fields on all backgrounds of the current stack. If you want searches to include more than one stack, you need to include a stack script in each stack to extend the Find command to search all relevant stacks.

The following button script searches for the selection in stacks "A" and "B":

on mouseUp
set lockScreen to true - so you don't see the stacks change
get selection
go to stack A
find it
if the result is empty then
go to stack B
find it
if the result is empty then
go back
answer "Sorry, no more information on that topic."
end if
end if
set lockScreen to false
end mouseUp

Sometimes, however, you may not want a search to occur because of an explicit Find Command: you'll want a script to search for text in your stacks as a result of an action.

For example, in a phone message stack, when you enter the name of the caller, you want to look up the caller's phone number in the Address stack. Include the following in the background script:

on closeField - on Tab or Return key or mouse click
set lockScreen to true
get field "Name" - from this stack
go to stack "address"
find it
get field "Phone" - from Address stack
go back - to first card of Address stack
go back - to original card
put it into field "Phone" - on the stack
set lockScreen to false
end closeField

If you know what you are searching for, such as a name, you can limit the search to certain fields, using the form:

find it in field "Name"
Published Date: Feb 18, 2012