Page 1 of 1

comparing two fields

Posted: Thu Feb 07, 2013 2:20 pm
by Andycal
I've got two fields each one has a list of product codes in them, but the second one has fewer codes.

What I'm trying to do is check to see if each product from the first field is in the second field. If it's not, pop the code into a third field.

Sounds easy, but I'm baffled. The find command just puts a box around the text, how do I actually do something with it?

Re: comparing two fields

Posted: Thu Feb 07, 2013 2:36 pm
by Andycal
OK, I found the 'Not found' bit in the docs, however the find starts from the last found, so I've got this:

Code: Select all

on mouseUp
   repeat for each line tLine in field one
      find string item one of tLine in field two
      if the result is "Not found" then put tLine & CR after field three
   end repeat
end mouseUp
However it will miss any products higher up in the field. Can you reset to the beginning?

Re: comparing two fields

Posted: Thu Feb 07, 2013 2:46 pm
by dunbarx
Hi.

Try this. I hope you see which fields are which.

Code: Select all

on mouseUp
   put fld "masterList" into masterList
   put fld "fieldToCheck" into fieldToCheck
   repeat for each line tLine in masterList
      if tLine is not among the lines of fieldToCheck then put tLine & return after fld "missingLines"
   end repeat
end mouseUp
Please look up the repeat and "is among" stuff in the dictionary.

Craig Newman

Re: comparing two fields

Posted: Thu Feb 07, 2013 2:53 pm
by Klaus
Hi Andy,

don't use FIND here, instead use LINEOFFSET!

fld 1 = the one with MORE content
fld 2 = the one with LESS content
fld 3 = for the differences, right?

OK, do this:

Code: Select all

...
## Do not access fields directly, too much overhead behind the scenes (read SLOW!), 
## put their contents into variables and work with these!
put fld 1 into tMoreContent
put fld 2 into tLessContent

## For a 100% 1:1 comparison: "This string" <> "this string"
## check "wholematches" in the dictionary
set the wholematches to true
repeat for each line tLine in tMoreContent
  if lineoffset(tLine,tLessContent) = 0 then
     ## line NOT in fld 2!
    put tLine & CR after tDiff
  end if
end repeat

## Get rid of trailing CR
delete char -1 of tDiff

## NOW put tDiff into field 3 "en bloc" :-)
put tDiff into fld 3
...
Best

Klaus

Re: comparing two fields

Posted: Thu Feb 07, 2013 2:58 pm
by Andycal
dunbarx wrote:Hi.

Try this. I hope you see which fields are which.

Code: Select all

on mouseUp
   put fld "masterList" into masterList
   put fld "fieldToCheck" into fieldToCheck
   repeat for each line tLine in masterList
      if tLine is not among the lines of fieldToCheck then put tLine & return after fld "missingLines"
   end repeat
end mouseUp
Please look up the repeat and "is among" stuff in the dictionary.

Craig Newman
Worked a treat! Thanks!