Page 1 of 1

matchText error -> Handler can't find handler

Posted: Thu Apr 21, 2011 9:21 pm
by IsDark
I recently bought LiveCode, while building a Twitter desktop application I'm having issues with matchText and replaceText function. I browsed through the forum, copy, pasting and adapting a bit the code.

Forum is preventing me of posting an twitter profile example, so replace "twitter" with the any twitter profile

Code: Select all

on mouseUp
   put URL "twitter" into field Logs
   put empty into field Tweets
   put "<span class=" & quote & "entry-content" & quote & ">" into myExpression
   repeat for each line thisLine in field Logs
      if myExpression is in thisLine then
         put word 1 to -1 of thisLine into thisLine
         replace myExpression with empty in thisLine
         replace "</span>" with empty in thisLine
         replace "</a>" with empty in thisLine
         replaceText (thisLine,"<a\sclass=(.*)>",empty)
         put thisLine & cr after field Tweets
      end if
   end repeat
end mouseUp
When the user presses the button, the script download the select Twitter profile, isolate tweets and probably will display it in a field

Problem is matchText and replaceText are firing a Handler can't find handler error.

Since matchText was firing the same error, I changed the code and add all the cleaning statements plus the replaceText function

This line

Code: Select all

         replaceText (thisLine,"<a\sclass=(.*)>",empty)
or this line

Code: Select all

         replaceText (thisLine,"<a class=(.*)>",empty)
when used are both triggering the handler's error.

The ideal thing was to use the matchText function, extracting the data I want with a regular expression. When used it triggered the same error.

Re: matchText error -> Handler can't find handler

Posted: Thu Apr 21, 2011 11:42 pm
by Klaus
Hi IsDark,

1. "repeat for each..."is READ only, that means that you cannot change the value of "thisLine" in your script!
2. "replacetext" and "matchtext" are both FUNCTIONS, but you used them like handlers, which are not found as you experienced! 8)

Do something like this (not tested!) adn read my comments:

Code: Select all

on mouseUp
   ## "twitter" is definitively not a valid URL!
   ##  Put NAMES into QUOTES!
   put URL "twitter" into field "Logs"
   put empty into field "Tweets"
   put "<span class=" & quote & "entry-content" & quote & ">" into myExpression
   repeat for each line thisLine in field Logs
      if myExpression is in thisLine then
         put thisLine into thatLine
         put word 1 to -1 of thatLine into thatLine
         replace myExpression with empty in thatLine
         replace "</span>" with empty in thatLine
         replace "</a>" with empty in thatLine
         put replaceText (thatLine,"<a\sclass=(.*)>",empty) into thatLine

         ## Avoid accessing fields in a repeat loop, this will slow down things dramatically!
         ## Instead collect the data into avariable and put that variable into a field AFTER the loop!
         put thatLine & cr after tTweet
      end if
   end repeat
   put tTweet into fld "Tweets"
end mouseUp
Best

Klaus

Re: matchText error -> Handler can't find handler

Posted: Fri Apr 22, 2011 10:40 pm
by IsDark
Ah thanks, my error. I copy and paste the example from the Dictionary. Now is working. thanks

On a side note, as this script is checking a huge amount of data, I need to use a visual sign for the user in order for him to know the application is running the selected task.

I try using a scrollbar progress object. I can set the endValue and startValue property, but I'm having problems with setting the thumbPosition, something like this:

Code: Select all

put field TweetList into TempList
put the number of lines in TempList into MaxTempList
set the endValue of ProgressionBar to MaxTempList
set the startValue of ProgressionBar to 0
put 0 into CurrentLine
repeat for each line thisLine in TempList
  put CurrentLine + 1 into CurrentLine
 set the thumbPosition of ProgressionBar to CurrentLine
--- process the data here
end repeat
I copy this line

Code: Select all

set the thumbPosition of ProgressionBar to CurrentLine
From livecode Dictionary, but it triggers an error.

How can I show the progression of the list processing?.

Re: matchText error -> Handler can't find handler

Posted: Fri Apr 22, 2011 10:46 pm
by mwieder
try

Code: Select all

put CurrentLine + 1 into CurrentLine
or

Code: Select all

add 1 to CurrentLine
instead of

Code: Select all

put CurrentLine + 1 to CurrentLine

Re: matchText error -> Handler can't find handler

Posted: Fri Apr 22, 2011 11:01 pm
by IsDark
Typing error, sorry. My problem is with:

Code: Select all

set the thumbPosition of ProgressionBar to CurrentLine

Re: matchText error -> Handler can't find handler

Posted: Sat Apr 23, 2011 1:30 am
by doc
Assuming that your scrollbar is named "ProgressionBar", then I think this should work for you:

Code: Select all

set the thumbPosition of scrollbar "ProgressionBar" to CurrentLine
-- Or maybe the short version:
set the thumbPosition of sb "ProgressionBar" to CurrentLine
Does that help?

Best regards,
-Doc-

Edit: Added a very simple example stack

Re: matchText error -> Handler can't find handler

Posted: Sat Apr 23, 2011 2:20 am
by Dixie
Doc..

Or maybe the even 'shorter version'

Code: Select all

set the thumbPos of sb "ProgressionBar" to CurrentLine
Sorry Doc... I couldn't resist.... :D

be well,

Dixie

Re: matchText error -> Handler can't find handler

Posted: Sat Apr 23, 2011 2:22 am
by doc
Ya know, I didn't even think about it...
...it's all good. :lol:

-Doc-

Re: matchText error -> Handler can't find handler

Posted: Sat Apr 23, 2011 4:41 pm
by IsDark
Thanks, I got it now. My mistake was not including the type of control before the object name when changing propertyes

I was using

Code: Select all

set the thumbPosition of "ProgressionBar" to CurrentLine
instead of

Code: Select all

set the thumbPosition of scrollbar "ProgressionBar" to CurrentLine
Thanks