comparing content of two fields

Scott Morrow scott at elementarysoftware.com
Thu Apr 28 02:09:17 EDT 2011


Hello Ron,

Like Joe said, putting everything into a variable so you don't have to touch the field as often is the first and biggest step to speeding things up. With large lists, using the "repeat for each" structure may be faster.  Her is an example (untested off the cuff) Watch for line wraps.  If you want the lines to hilite as it check then you will need to  use a slightly different approach.  While the script is running, nothing will happen visually.  While this can be scripted differently to have lines hilite as they are checked, it will take a lot of extra time.
---------------------------------------------------
on mouseUp
   set the itemDelimiter to tab
   put field "All" into tBigData -- use this to compare with field "Rural" data
   put tBigData into tBigData2 -- we will change this data as matches are found
   put field "Rural" into tSmallData
   put 0 into tLineCounter -- init
   put empty into tListOfLines -- init
   repeat for each line tBigDataLine in tBigData
      add 1 to tLineCounter
      repeat for each line tSmallDataLine in tSmallData
           if item 1 of tBigDataLine = item 1 of tSmallDataLine then
            put "Rural" into item 4 of line tLineCounter of tBigData2
            put tLineCounter & CR after tListOfLines -- keep track of what lines to colorize
          else
            put "-" into item 4 of line tLineCounter of tBigData2
          end if
      end repeat
   end repeat
   put tBigData2 into field "All" -- update the text of the field
   --colorize the lines
   put token 1 to -1 of tListOfLines into tListOfLines -- trim
   repeat for each line tLine in tListOfLines
       set the textColor of line tLine of field "All" to "red"
   end repeat
end mouseUp
---------------------------------------------------

Warmest regards,

Scott Morrow

Elementary Software
(Now with 20% less chalk dust!)
web       http://elementarysoftware.com/
email     scott at elementarysoftware.com


On Apr 27, 2011, at 9:02 PM, Joe Lewis Wilkins wrote:

> Hi Ronald,
> 
> You can speed things up immeasurably by put the content of the fields into variables and then make your comparisons between the vars.  This is a universal truth. Always work with vars; not fields.
> 
> HTH,
> 
> Joe Lewis Wilkins
> Architect & Director of Product Development for GSI
> <www.glsysinc.com>
> 
> 
> 
> 
> 
> 
> 
> 
> On Apr 27, 2011, at 8:55 PM, Ronald Zellner wrote:
> 
>> I  have two data fields that have multiple tabbed columns,
>> I want to determine which items in the main field (1247 lines)  also appear in the second field (436 lines).
>> 
>> Using this code to compare line by line:
>> 
>> on mouseUp
>> 
>>  set the itemDelimiter to tab
>>  repeat with x = 1 to the number of lines in field "All" -- there are 1247 lines
>> 
>>     repeat with y = 1 to the number of lines in field "Rural"  --there are 436 lines
>>        if item 1 of line x of field "All" = item 1 of line y of field "Rural" then
>>           put "Rural" into item 4 of line x of field "All"
>>           set the textColor of line x of field "All" to "red"
>>           exit repeat
>>        else
>>           put "-" into item 4 of line x of field "All"
>>        end if
>> 
>>     end repeat
>>  end repeat
>> end mouseUp
>> 
>> 
>> This seems to function properly, but
>> 
>>   1.   it is very, very slow
>>   2.  The results do not show up until the whole set is completed, not as each line is checked.
>> 
>> Any thoughts on a better way to approach this?
>> 
>> Ron
>> _______________________________________________
>> 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