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?
comparing two fields
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: comparing two fields
OK, I found the 'Not found' bit in the docs, however the find starts from the last found, so I've got this:
However it will miss any products higher up in the field. Can you reset to the beginning?
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
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: comparing two fields
Hi.
Try this. I hope you see which fields are which.
Please look up the repeat and "is among" stuff in the dictionary.
Craig Newman
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
Craig Newman
Re: comparing two fields
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:
Best
Klaus
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
...
Klaus
Re: comparing two fields
Worked a treat! Thanks!dunbarx wrote:Hi.
Try this. I hope you see which fields are which.Please look up the repeat and "is among" stuff in the dictionary.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
Craig Newman