problem with foundChunk()

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

problem with foundChunk()

Post by keram » Sun Jan 25, 2015 5:38 am

Hello,

I have a stack (see attachment) with a field containing lines - for simplicity they are just numbers.
When clicking on a line (number) in on the left side (q_list) the number is highlighted and turns into red color. At the same time it gets copied to the field on the right side (favorites) and the checkbox get selected.

When I disselect the checkbox the number on the left gets unhighlighted into grey color, and it gets deleted from the favorites field on the right.
So far it's OK. But when I try to select the checkbox again for the same number on the left then I'm getting this error:
button "Check": execution error at line 9 (Chunk: no target found), char 25
on line set the textColor of foundChunk() to "red" in the checkbox script which is this:

Code: Select all

global gFavorites
on mouseUp
   local tQuote
   get the text of fld "1line_f"
   put it into tQuote
   find whole tQuote  in the fld "q_list"
   if the hilite of me is true then
      if tQuote is not among the lines of gFavorites then put tQuote&cr&cr after gFavorites  --no duplicate lines
      set the textColor of foundChunk() to "red"
   else
      if tQuote is among the lines of gFavorites then filter lines of gFavorites without it --delete that line from fld "favorites" 
      set the textColor of foundChunk() to "#505050"
   end if
   
   refreshFavorites  -- script on the stack level
   
end mouseUp
and also when I enter a number into fld "1line_f", let's say 4, when the checkbox is unselected, then select the checkbox and disselect it again then I'm getting en error on this line: set the textColor of foundChunk() to "#505050"

How to correct the script to get it working OK?

Thanks!

keram
Attachments
select-unselect lines.zip
(3.2 KiB) Downloaded 197 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: problem with foundChunk()

Post by keram » Sun Jan 25, 2015 9:46 am

OK, I figured it out thanks to the examples that Terry included in the Beginner Lab stack in the card describing all about Find.
Here is the post about Beginner Lab stack (VERY useful for beginners like me) http://forums.livecode.com/viewtopic.ph ... 47#p115347

Anyway, the solution is to include find empty before the end mouseUp.
From Dictionary:
"The find empty form of the find command removes the box from the last word found and resets the find command, so that the next search starts from the beginning of the current card, rather than the location of the next find. Going to another card also resets the find command."
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

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

Re: problem with foundChunk()

Post by jacque » Sun Jan 25, 2015 5:31 pm

For something like this it would be more efficient and easier to use lineOffset instead of find.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: problem with foundChunk()

Post by keram » Mon Jan 26, 2015 5:31 am

Thanks Jacqueline,

I changed it to:

Code: Select all

global gFavorites
on mouseUp
   local tQuote, SearchBox
   put the text of fld "1line_f" into tQuote
   put fld "q_list" into SearchBox
   get lineOffset(tQuote,SearchBox)
   
   if the hilite of me is true then
      if  lineOffset(tQuote,gFavorites) = 0 then put tQuote&cr&cr after gFavorites  --no duplicate lines
      set the textColor of line it of fld "q_list" to "red"
   else
      set the textColor of line it of fld "q_list" to "#505050"
      filter lines of gFavorites without tQuote 
   end if
   refreshFavorites
end mouseUp
jacque wrote:it would be more efficient
By that, do you mean faster?
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

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

Re: problem with foundChunk()

Post by jacque » Mon Jan 26, 2015 9:45 pm

By that, do you mean faster?
That's a byproduct, yes, but mostly I meant code efficiency. The "find" command searches all the text in the whole stack unless you specifically limit it to a certain field, or add extra commands to stop the find if it changes cards. Also, "find" has to access every field which is an intensive and slower process. Using an offset command is an efficient one-liner and works with variables which is always much faster. The less a script needs to access fields, the better.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply