Syntax for incrementing a numeric 'word'

Keith Clarke keith.clarke at clarkeandclarke.co.uk
Wed Jun 27 05:23:20 CDT 2012


Thanks John & Corey. 

Your two responses have helped with both cleaning-up the source list and increasing the efficiency of the code.

Not to self... Get more comfortable with abstracting problems into arrays, rather than relying on proving each step of the code by rendering into a field - as arrays often prove so useful!
Best,
Keith.. 

On 27 Jun 2012, at 10:07, John Dixon wrote:

> 
> 
> Does this help you...?
> 
> on mouseUp
>   put empty into fld "result"
> 
>   set itemDel to tab
>   replace comma with space in fld "source"
>   replace "." with space in fld "source"
>   replace space & "'"  with space in fld "source"
>   replace  "'"   & space with space in fld "source"
>   replace "?" with space in fld "source"
> 
>   repeat with count = 1 to the number of words of fld "source"
>      put lineOffset( word count of fld "source", fld "result") into boo
>      if boo = 0 then
>         put word count of fld "source" & tab &  1 & cr after fld "result"
>      end if
>      if boo > 0 then
>         add 1 to item 2 of line boo of fld "result"
>      end if
>   end repeat
> 
>   --sort lines of fld "result" numeric descending by item 2 of each
> end mouseUp
>> From: keith.clarke at clarkeandclarke.co.uk
>> Subject: Syntax for incrementing a numeric 'word'
>> Date: Wed, 27 Jun 2012 09:24:26 +0100
>> To: use-livecode at lists.runrev.com
>> 
>> 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 at 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 at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list