Checking a field list
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 73
- Joined: Sat Apr 08, 2006 6:51 pm
Checking a field list
Some of the lines in field A are in field B as well. I want to go down the lines in field A and, if line i of fld A is in fld B, put ln i of fld A into fld C. If ln i of fld A is not in fld B, I want to put ln i of fld A into fld D.
I have been trying to do this with nested loops but can't get it to work right. Any help would be very welcome!
I have been trying to do this with nested loops but can't get it to work right. Any help would be very welcome!
In nova fert animus mutatas dicere formas corpora.
Re: Checking a field list
why would you nest loops to do that?
Code: Select all
repeat for each line theLine in fieldA
if theLine is among the lines of fieldB then
put theLine & return after fieldC
else
put theLine & return after fieldD
end if
end repeat
delete char -1 of fieldC
delete char -1 of fieldD
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
- Posts: 73
- Joined: Sat Apr 08, 2006 6:51 pm
-
- Posts: 73
- Joined: Sat Apr 08, 2006 6:51 pm
Re: Checking a field list
How would you modify this code to sort by the first word of each word of each line in fieldA instead of the entire line?
repeat for each line theLine in fieldA
if theLine is among the lines of fieldB then
put theLine & return after fieldC
else
put theLine & return after fieldD
end if
end repeat
delete char -1 of fieldC
delete char -1 of fieldD
repeat for each line theLine in fieldA
if theLine is among the lines of fieldB then
put theLine & return after fieldC
else
put theLine & return after fieldD
end if
end repeat
delete char -1 of fieldC
delete char -1 of fieldD
In nova fert animus mutatas dicere formas corpora.
Re: Checking a field list
Hi.
Do you mean that if the first word of a line in fld A is anywhere is fld B? In that case:
repeat for each line theLine in fieldA
if word 1 of theLine is in fieldB then
etc.
Craig Newman
Do you mean that if the first word of a line in fld A is anywhere is fld B? In that case:
repeat for each line theLine in fieldA
if word 1 of theLine is in fieldB then
etc.
Craig Newman
-
- Posts: 73
- Joined: Sat Apr 08, 2006 6:51 pm
Re: Checking a field list
Sorry, I didn't explain clearly. For each line thisLine in fieldA, If the first word in thisLine of fieldA = the first word in any line of fieldB, then ...
also, is there a way to deal with conditions in which the first word in thisLine of fieldA = the first word in two or more different lines in fieldB?
also, is there a way to deal with conditions in which the first word in thisLine of fieldA = the first word in two or more different lines in fieldB?
In nova fert animus mutatas dicere formas corpora.
Re: Checking a field list
OK.
So now you need to map the lines of one field to the lines in the other. A different form of repeat is best here:
You may need a bit of houseKeeping, if the number of lines of fld A is not the same as field B, and maybe other stuff. But you should get the idea.
In the second case:
Not sure exactly how you want the output, so I just put the line number(s) in fleldB that matched word 1 of each line in fieldA. Try some data and see if this works. If not, ask again.
Craig Newman
So now you need to map the lines of one field to the lines in the other. A different form of repeat is best here:
Code: Select all
on mouseup
repeat with y = 1 to the number of lines of fld "fieldA"
if word 1 of line y of fld "fieldA" = word 1 of line y of fld "fieldB" then
put line y of fld "fieldA" into line y of fld "fieldC"
else
put line y of fld "fieldA" into line y of fld "fieldD"
end if
end repeat
end mouseup
You may need a bit of houseKeeping, if the number of lines of fld A is not the same as field B, and maybe other stuff. But you should get the idea.
In the second case:
Code: Select all
on mouseup
put "" into fld "fieldC"
put "" into fld "fieldD"
repeat with y = 1 to the number of lines of fld "fieldA"
repeat with u = 1 to the number of lines of fld "fieldB"
if word 1 of line y of fld "fieldA" = word 1 of line u of fld "fieldB" then
put u & ":" && line y of fld "fieldA" & return after fld "fieldC"
end if
end repeat
end repeat
end mouseup
Craig Newman