I built a label with multiple lines, put "1 2 3/n2 3 4/n3 4 5" into it and ran this line of code on it:

   add 1 to word 2 of line 2 of field "field"

It worked just as you'd expect it to.

However, this seems a very slow way to do it.

Hashes work a treat for this kind of thing.

on mouseUp
   -- keep track of how many times each word is used.
   repeat for each word tWord in field "txt"
      add 1 to tHash[tWord]
   end repeat

   -- print overview
   put the number of lines in field "txt" into field "numlines"
   put the number of words in field "txt" into field "numwords"
   put the number of lines in the keys of tHash into field "numuniq"

   -- print details
   repeat for each line tLine in the keys of tHash
     put tLine&" "&tHash[tLine]&CR after field "result"
   end repeat
end mouseUp

Simpler, and I'd wager significantly faster.

-Ken

On 27/06/2012 09:24, Keith Clarke wrote:
Hi folks,
I'm working on a simple script to identify and count the unique words dumped 
into a 'Source' field to create a 'Results' list field with the word and 
counter.

However, this script is throwing errors at the line when I attempt to increment 
the second word by adding 1 to it. What's wrong with the syntax for 
incrementing the counter chunk?

on mouseUp
    put empty into field "Results"
    repeat for each word tWord in field "Source"
       if field "Results" is empty then put tWord & tab & 1 after field 
"Results"
       if tWord is among the words of field "Results" then
          repeat for each line tLine in field "Results"
             if word 1 of tLine <> tWord
             then exit repeat
             else add 1 to word 2 of line tLine in field "Results"
             end repeat
          else put tWord & cr after field "Results"
       end repeat
end mouseUp

Best,
Keith..
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to