Message Box question

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 47
Joined: Wed Aug 01, 2007 2:15 am

Message Box question

Post by mbossiere » Sat Nov 30, 2013 3:55 pm

Some of my projects remain and are kept uncompiled, that is, as editable stacks. These stacks contain in some cases thousands of cards with text fields. I frequently search them using the Message Box and a simple "search textToFind" which does a fine job of locating a word and finding subsequent instances with each press of the Return key. However, when I attempt to script this action by putting directly to the Message Box, as in:
put "Find" && quote & textToFind & quote -- (that is, in the message box)
my line is placed into the Result Area of the Message Box, not the Command Area.
CAN SOMEONE EXPLAIN TO ME WHY IT IS NOT POSSIBLE TO PUT DIRECTLY INTO THE COMMAND AREA VIA SCRIPT?

Likewise, I have tried the following as a way to create an easily executed serial-search for a word:
on commandKeyDown theKey
if theKey is not "F" then exit commandKeyDown
ask "Find:"
if it is not empty then find it
if the result is "Not found" then
answer the result
exit commandKeyDown
end if
put it into mySearch
repeat forever
answer "Find next " & mySearch & "?" with "Cancel" or "Next"
if it is "Cancel" then exit commandKeyDown
else
find mySearch
if the result is "Not found" then
answer the result
exit commandKeyDown
end if
end if
end repeat
end commandKeyDown

BUT THIS FAILS TO SUCCESSFULLY FIND ANY BUT THE FIRST INSTANCE!

Any ideas are appreciated. I want an easy search function (a la HyperCard and it's simpler Message Box) in order to casually flip thru a stack for a term.
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Message Box question

Post by dunbarx » Sun Dec 01, 2013 12:22 am

Hi.

I have not looked at your script, but the "find" command keeps an internal record of the "finds" it makes, and continues searching the cards of a stack based on an index created from the last successful found text. In other words, it will continue to find additional instances, card by card.

If there are other instances on the same card, it will find those before moving on.

So you might try making a stack of a handful of cards containing a bg field on it with some text that appears on several of those cards. IF you start at card 1 and execute the "find" command for that text, you will see that LC navigates to the card that has the next instance. The question becomes, then, what is different about your stack?

Craig Newman

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 47
Joined: Wed Aug 01, 2007 2:15 am

Re: Message Box question

Post by mbossiere » Sun Dec 01, 2013 5:38 pm

Thank you. Where, and how, does the Find command keep track of it's hits? And perhaps more important to me, HOW does one place a line of script into the Command Area of the Message Box (via script)? If I write:

put "Find" && quote & "Bozeman" & quote into message box

..it goes into the Result Area of the Message Box and will not respond as I expect to:

do message box

..and thus it is useless (for example, in Hypercard one can send a "do" command to the Message Box and any valid line in there will execute)
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Message Box question

Post by dunbarx » Sun Dec 01, 2013 6:31 pm

Hi.

You are an experienced HC user?

The "find" command works the same as in HC. The index is internally stored. The only way to find out where the most recent found text is located is under script control (or, I suppose, with the "recent" keyword)

The msg box in LC is complex, as you likely know. But you can;

put "sometext" into fld "message field" of stack "message box"

Craig

EDIT:

But do you need to worry about this? Try, in a button script:

Code: Select all

on mouseUp
 
   put "answer PP"
   put "answer kk" into fld "message field" of stack "message box"
   do msg
end mouseUp

Post Reply