set the itemDelimiter to tab
repeat with i = 1 to num_lines
if item 7 of line i of tTariffDataGrid is "Share" then delete line i of tTariffDataGrid
end repeat
put tTariffDataGrid into field "Field"
Am I missing something from the code that is stopping certain lines being deleted?
Hi Daniel,
Oh you have hit on a fun one I think.
Here is how I understand it, you have lines:
1
2
3
4
5
delete line 3
You now have
1
2
4
5
the position of line 4 is now line 3 and the "pointer" is now looking at the line with the number 5 in it.
Oh never mind!
This should do it for you:
OK I copped out on my answer, let me try again.
You have lines;
1[a]
2[a]
3
4
5[a]
repeat with i = 1 to 5
if "b' is in line i of myvar then delete line i of myvar
Ok so now i = 3
delete line 3
1[a]
2[a]
4
5[a]
on the next repeat i = 4, looking at the above and just counting 4 lines down gives us 5[a]
4 never gets inspected. So subtracting 1 from i returns it to 3 and 4 will get deleted.
Well thats a bit better.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
...
put the num of lines of tTariffDataGrid into tNumOfLines
repeat with i = tNumOfLines down to 1
if item 7 of line i of tTariffDataGrid is "Share" then
delete line i of tTariffDataGrid
end if
## now happily delete all the lines that match your creteria :-)
end repeat
...
But better use the "repeat for each..." snytax, this is INSANELY fast!
More than thousands of lines in a fraction of a second!
Although "repeat for each" is READ ONLY (you cannot alter the lines) this technique is commonly and successfully used:
...
repeat for each line tLine in tTariffDataGrid
## tLine is the ACTUAL content of that line!
if item 7 of tLine <> "Share" then
## you cannot modify tLine, so we simply create a new variable!
put tLine& CR after tNewList
end if
end repeat
## delete trailing CR
delete char -1 of tNewLine
put tNewLine into field "Field"
...