find

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

find

Post by robm80 » Wed Aug 27, 2014 10:34 am

With find "foo":

Code: Select all

 repeat with i=2 to tNum
      find "foo" in fld "comment"
      put the short name of this card into tSn
      if tSn is not in btn "foundbox" then
         put tSn & cr after btn "foundbox"
      end if
   end repeat
I get all those cards in the combobox "foundbox" and find goes automatically to the first card: here is a box drawn around word "foo".
When I go to anyone of the other cards, there is no box. I need to see the box on every card :!:
Possible :?:
When I remove "with i=2 to tNum" the script hangs and I have to restart.
Rob

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: find

Post by jmburnod » Wed Aug 27, 2014 12:08 pm

Hi Rob,

What happens if you insert a wait 1000 milliseconds in the loop ?
Best
Jean-Marc
https://alternatic.ch

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: find

Post by Klaus » Wed Aug 27, 2014 12:16 pm

Dag Rob,

what happens if you also add the correct CARD description to your repeat loop to REALLY address all cards?

Code: Select all

...
repeat with i = 2 to tNum
      find "foo" in fld "comment" OF CD i
      put the short name OF CD i into tSn
      if tSn is not in btn "foundbox" then
         put tSn & cr after btn "foundbox"
      end if
end repeat
...
Best

Klaus

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: find

Post by robm80 » Wed Aug 27, 2014 12:49 pm

What happens if you insert a wait 1000 milliseconds in the loop
Nothing. Hangs and restart.
what happens if you also add the correct CARD description to your repeat loop to REALLY address all cards?
What card description when searching for probably 5 words among 1000 cards ?

Rob

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: find

Post by Klaus » Wed Aug 27, 2014 1:32 pm

Hm, I don't get it!?

to be sure I understand your problem at all:
1. You have a field named "comment" on ALL cards except card 1?
2. You want to find the string "foo" in the field "comment" on EVERY card except card 1?
3. IF field "comment" on card X contains the string "foo" then you want to collect the NAMES of these cards?

Is that correct so far?

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: find

Post by robm80 » Wed Aug 27, 2014 3:31 pm

HI Klaus,
1. You have a field named "comment" on ALL cards except card 1?
2. You want to find the string "foo" in the field "comment" on EVERY card except card 1?
3. IF field "comment" on card X contains the string "foo" then you want to collect the NAMES of these cards?
Completely correct. And I want the founded string be framed on every card.
The collected names are directed to a combobox, that will go to the card who's name is hit.
Thank you, Rob

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: find

Post by jmburnod » Wed Aug 27, 2014 3:51 pm

Hi Rob,
I want the founded string be framed on every card.
Yes. As when you use the command find.
I think you have to set the textstyle of the foudchunk to "box" after you found "foo"

Code: Select all

...
 find "foo" in fld 1 of cd i
      if the foundchunk  <> empty then
         set the textstyle of the foundchunk to "box"
      end if
...
Best
Jean-Marc
Last edited by jmburnod on Wed Aug 27, 2014 3:56 pm, edited 1 time in total.
https://alternatic.ch

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

Re: find

Post by dunbarx » Wed Aug 27, 2014 3:55 pm

Rob.

Do you know what Jean-Marc meant? The "box" you get after a successful find is not a textStyle of the foundChunk. It is ephemeral, and will disappear if you even look at it the wrong way. But setting the textStyle of the foundChunk, to "box" or whatever, sticks, and is saved with the stack.

Craig Newman

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: find

Post by jacque » Wed Aug 27, 2014 6:26 pm

I posted an example handler in your other thread, which you revised, but the revision will fail; you need to keep a list of all instances of the find, which is what the original did. Tracking only the card name isn't enough, you need the foundchunk. If you aren't sure why, try entering the search word twice into the comment field on any card. As soon as the handler gets to that card, it will abort and the remainder of the cards will not be searched.

As Craig said, the native boxed text is very temporary. For permanent boxing, you need to use my example but change the line that sets a color to set the textstyle of the foundchunk to "box" instead. This will be a permanent part of the field text, just as though you'd manually selected the text and changed the style.

To remove the boxed text, run through the saved list of foundchunks and set each one's text style to empty. Or easier, just do this on a preOpenCard handler:

Code: Select all

put field "comment" into field "comment"
That will reduce the entire field text to plain style.

To avoid searching the first card, the easiest thing to do is to set the dontSearch of that card to true. You can do that in the card's property inspector. No script is required.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: find

Post by robm80 » Thu Aug 28, 2014 5:22 am

Good morning Jacque, J-M and Craig,
Thanks for all your advises.
There are now several questions:

1. Why the doFind script needs line 4: " if the result <> "" or the shiftkey is down then exit repeat"
Without this line the scipt does not work.
2. The boxes are drawn everywhere needed, but removing them is a new problem"
put field "comment" into field "comment" does not remove the boxes, but underlines the whole text of fld "comment"
3. All objects of the cards were set to background behavour, so they were grouped.
Now I want to ungroup them, but nope; there is no group anymore: each object can be selected.
I needed the ungrouping to write an opencardscript for (when it removes the boxes) "put field "comment" into field "comment".
Because of this I scripted

Code: Select all

on mouseUp
   lock screen
   put number of cards into tNum
   
   repeat with i=1 to tNum
      put field "comment"  of cd i into field "comment"
   end repeat
   
   unlock screen
end mouseUp
But as you might expect, now on every card the text of fld "comment" is underlined
Do I have to recreate the whole application?

Hope you see the light, Rob

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: find

Post by jacque » Thu Aug 28, 2014 5:59 am

robm80 wrote: 1. Why the doFind script needs line 4: " if the result <> "" or the shiftkey is down then exit repeat"
Without this line the scipt does not work.
The repeat loop has no exit condition, it will loop forever, so there needs to be a way to tell it when to stop. When no more instances are found, the result is set to "not found". Otherwise the result is empty (meaning a match was found.) So we stop when the result isn't empty. The shift key is something I put in to give you a way to abort prematurely if you wanted to stop the search manually.
2. The boxes are drawn everywhere needed, but removing them is a new problem"
put field "comment" into field "comment" does not remove the boxes, but underlines the whole text of fld "comment"
Fields can have a default style, which is applied to all the text it contains. The characters in a field can have their own style too, which you apply by selecting them with the mouse. When the script removes the character styles (the boxes) the text will default to the field style. I assumed that was plain but you must have set it at some point. Open the field's property inspector and in the Text pane, unselect underlined. Set the field's default style to plain (the "P".) Then the script will work.
3. All objects of the cards were set to background behavour, so they were grouped.
Now I want to ungroup them, but nope; there is no group anymore: each object can be selected.
I needed the ungrouping to write an opencardscript for (when it removes the boxes) "put field "comment" into field "comment".
Don't ungroup the objects. If you do that now, you will lose the text from all fields. You are using a shared group with different text on each card. Ungrouping will wipe out all that.

You don't need to ungroup anyway, and in fact the current setup is the correct one. You can get to the group script in any number of ways:

1. Open the application browser from the Tools menu. Click your stack on the left, then any card that has that group on it. Find the group in the right-side pane and right-click to edit the script.
2. Open the project browser from the Tools menu. Expand the objects until you see the group. Right-click it to edit the script.
3. Click "Select Grouped" in the Toolbar at the top of the screen. That toggles whether you are able to select groups, or the objects inside the group. You've probably turned this off, which is why you think you can't select groups any more. Once you can select the group, right-click to edit the script.
4. Type in the message box: edit script of group "whatever"

Any of those methods will get you to the group script.
Do I have to recreate the whole application?
You'll never need to recreate the stack. Anything you get yourself into, you can get yourself out of. The main problem is that you're still not sure what does what, so it's easy to get lost. Keep hammering at it, it will all fall into place pretty soon.

If you haven't yet read the User Guide (in the Help menu) you'll find out all sorts of things. All the behaviors we've been talking about are in there. You don't have to read it all at once, just look at the things you're learning at any given time. Also, the dictionary will be your constant companion. For starters, see what it says about "find".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: find

Post by robm80 » Thu Aug 28, 2014 10:02 am

Jacque, Thank you so much, I understand more and more now.
BUT new problems. Please see first if my script is OK:

Code: Select all

on mouseUp
   put empty into tZoekstring
   put empty into btn "foundbox"
   put number of cards into tNum
   show btn "foundbox"

   ask "What word"
   put it into tZoekstring  
   if tZoekstring is empty then
      break
   end if   
   doFind tZoekstring     
end mouseUp 

on doFind tZoekstring
   lock screen
   repeat
      find words tZoekstring in fld "comment"
      if the result <> "" or the shiftkey is down then exit repeat
      set the textstyle of the foundchunk to "box"
      put the short name of this cd && the foundchunk into tRef
      if tRef is among the lines of tList then
         exit repeat
      else
         put tRef & cr after tList
      end if
   end repeat
   put  tList into btn "foundbox"
   unlock screen
end doFind 
The problem is that, although I do find words, tList contains lines that are not correct:
sshot-19.jpg
sshot-19.jpg (22.31 KiB) Viewed 9148 times
The lines 3 and 6 should not be there, they are the names of the cards.

I have put

Code: Select all

on opencard
   put field "comment" into field "comment"
end opencard
into the main group, but now, when I go to line 4, the box has gone, because of that script.
What's wrong ?
Thanks again, Rob

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: find

Post by jmburnod » Fri Aug 29, 2014 5:13 pm

Hi Rob,
The result of find command return the foundchunk or ""not found", it is never empty
Please try:

Code: Select all

if the result = "not found" or the shiftkey is down then exit repeat
instead

Code: Select all

if the result <> "" or the shiftkey is down then exit repeat
However, I dont understand how you get this result, the script should stop at the first search since its result is necessarily <> "" :shock:

P.S. the foundchunk can be empty but not the result of a find command
Best regards
Jean-Marc
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: find

Post by jacque » Fri Aug 29, 2014 7:55 pm

Actually, the result will be empty if the find is successful. The foundchunk is not returned in the result, it is a separate function, just like the foundField, foundLine, foundLoc, and foundText.

Try this in the multi-line message box:

find "the"
put the result is empty --> true

So it is possible to abort a find command within a loop by checking to see if the result is empty.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: find

Post by jacque » Fri Aug 29, 2014 8:24 pm

robm80 wrote:Jacque, Thank you so much, I understand more and more now.
BUT new problems. Please see first if my script is OK:

Code: Select all

on mouseUp
   put empty into tZoekstring
   put empty into btn "foundbox"
   put number of cards into tNum
   show btn "foundbox"

   ask "What word"
   put it into tZoekstring  
   if tZoekstring is empty then
      break
   end if   
   doFind tZoekstring     
end mouseUp 

on doFind tZoekstring
   lock screen
   repeat
      find words tZoekstring in fld "comment"
      if the result <> "" or the shiftkey is down then exit repeat
      set the textstyle of the foundchunk to "box"
      put the short name of this cd && the foundchunk into tRef
      if tRef is among the lines of tList then
         exit repeat
      else
         put tRef & cr after tList
      end if
   end repeat
   put  tList into btn "foundbox"
   unlock screen
end doFind 
The problem is that, although I do find words, tList contains lines that are not correct:
sshot-19.jpg
The lines 3 and 6 should not be there, they are the names of the cards.

I have put

Code: Select all

on opencard
   put field "comment" into field "comment"
end opencard
into the main group, but now, when I go to line 4, the box has gone, because of that script.
What's wrong ?
Thanks again, Rob
Not related to your question, but the "break" command typically goes in a switch statement. What you want here is "exit mouseUp". I'm a little surprised it works, I've never used it this way. Does it really exit the handler?

I'd also be cautious about the "find words" variation. If the user types in "dog" and it ends a sentence, it won't be found because "dog" is not "dog." The same will happen if a word is at the beginning of a quoted phrase, because the quotation mark in front of or following the word won't match the plain word. Ditto for commas and other punctuation. I'd use plain old "find" I think, which matches most things.

The doFind handler is correct, and I can't repeat your results where only the card name occurs. If the find is successful there should be a foundChunk, so I'm stumped on that one. But whatever the reason, it isn't why the boxes are removed. That was a thinko on my part. The preOpenCard handler tells LiveCode to remove the boxes before the card opens, so naturally when you navigate to other cards, it will do exactly as asked and removed the styling.

I shouldn't have told you to do that in a preOpenCard. Since you want users to be able to browse through the cards and see the found text, you'll have to provide a different mechanism to remove the styling when the user is done looking at it. Now, what that will be will depend on how you want the stack to work. You could provide a button that does it, which the user clicks to revert the text. Or maybe you can think of something else that fits your stack design.

If you decide to provide a button, then you'd do almost exactly the same thing as the doFind handler. But you don't need to actually run the Find command again because you already have a list of found text. Instead, grab that text from your combo button and loop through each line, setting the textstyle of the characters on their cards to "plain". The nice thing about this is that you can do it without going to each card; you can set the text style on a different card just by referring to it:

Code: Select all

set the textstyle of char 1 to 4 of field 4 of card "16 blocks" to "plain"
Your handler will need to assemble that construct as it loops through the list of found matches. See if you can do it. It would be easiest if you change the doFind handler to put a comma after the card name in the list it creates, because then you can easily extract it by getting "item 1" of each line. Item 2 will be the foundChunk.

The conference is fast approaching so my time is becoming limited, but if you need help hopefully someone will chime in.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply