Page 1 of 1
Delete item in field chosen from dropdown
Posted: Sat Oct 10, 2009 10:38 pm
by TodayIsTheDay
I've tried several versions of this and I'm stumped. All I'm trying to do is to delete an item in a field that I've chosen from a dropdown menu.
I'm using this:
Code: Select all
on menuPick pItemName
delete pItemName from field "Field321"
end menuPick
Posted: Sun Oct 11, 2009 12:15 am
by FourthWorld
You're on a good start, but you haven't specified a chunk type (the type of thing that you want to act on, line, item, word, character).
Are the items return-delimited? If so this should do it:
Code: Select all
on menuPick pItemName
set the wholeMatches to true
put lineoffset(pItemName, field "Field321") into tOS
if tOS > 0 then
delete line tOS of field "Field321"
end if
end menuPick
Posted: Sun Oct 11, 2009 2:57 am
by TodayIsTheDay
Thanks. Now added some code. I'm looping through and even able to delete multiple occurrences of it
But... With that being said, I don't see exactly how it works...
Could you or someone please tell me how this works?
Code: Select all
--We are setting a local variable called tLineNumber
local tLineNumber
--We are making TLineNumber the number 1
put 1 into tLineNumber
--loops through each line of my field
repeat for each line tLine in field "Very Long List"
--here is where I'm lost. Where did we get tline? I didn't declare it??
doStuff tLine, tLineNumber
--Why do we have to add 1 to tLineNumber if we've already told it to repeat for each line of my field "Very long list"??
add 1 to tLineNumber
end repeat
Posted: Sun Oct 11, 2009 3:29 am
by FourthWorld
It seems that tLineNumber is updated only for the benefit of the handler doStuff. Without knowing what doStuff does, we don't know why it needs that number.
Posted: Sun Oct 11, 2009 3:35 am
by TodayIsTheDay
I 'm not sure what it does.... I found the code sample in the notes of the repeat function in the Rev Dictionary.
I modified it as this:
Code: Select all
on menuPick pItemName
set the wholeMatches to true
local tLineNumber
put 1 into tLineNumber
repeat for each line tLine in field "Field321"
put lineoffset(pItemName, field "Field321") into tWordToDelete
if tWordToDelete > 0
then
delete line tWordToDelete of field "Field321"
end if
add 1 to tLineNumber
end repeat
end menuPick
Posted: Sun Oct 11, 2009 10:40 am
by bn
TodayIsTheDay,
repeat for each line tLine in field "Very Long List
here you create your variable
tLine, that is where it comes from
Why do we have to add 1 to tLineNumber if we've already told it to repeat for each line of my field "Very long list"??
repeat for each line tLine in field...
puts the
content of that line into tLine, so tline is all the text of the line, but tLine does not indicate what the line number is. If you need that then you have to make a counter, that is what tLineNumber is for, it just tells you what line number the repeat for each line tLine is working on.
on menuPick pItemName
 Â
 set the wholeMatches to true
 Â
  local tLineNumber
put 1 into tLineNumber
repeat for each line tLine in field "Field321"
Â
 put lineoffset(pItemName, field "Field321") into tWordToDelete
  if tWordToDelete > 0
  then
    delete line tWordToDelete of field "Field321"
  end if
 Â
  add 1 to tLineNumber
 Â
  end repeat
 Â
end menuPick
here you mix two forms. For what you want to do you dont need the repeat for each line, the repeat and the lineOffset is sufficient. tWordToDelete holds the line number, no need for an additional counter, pItemName holds the word, no need to look at the text of the line in repeat for each line tLine.
Code: Select all
on menuPick pItemName  Â
set the wholeMatches to true
repeatÂ
put lineoffset(pItemName, field "Field321") into tWordToDelete
if tWordToDelete > 0 then
delete line tWordToDelete of field "Field321"
else
exit repeat -- you are done, no more occurences, get out of the repeat loop
end if
end repeat
end menuPick
regards
Bernd