Delete item won't work in Repeat for each loop

Mark Schonewille m.schonewille at economy-x-talk.com
Wed May 24 17:42:02 EDT 2006


Hi Ian,

When you delete items, the number of items gets smaller while the  
variable that counts the items goes up. At some point, you're trying  
to delete items that don't exist. Use "down to" to avoid this:

repeat with x = number of lines of myList down to 1
   delete line x of myList
end repeat

(in this simple example, you can also use "delete last item", obviously)

Best,

Mark

--

Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz

Salery is the easiest way to get your own web store on-line: http:// 
www.salery.biz/salery.html



Op 24-mei-2006, om 23:35 heeft Ian McKnight het volgende geschreven:

> Hi all
>
> I have a text file of 60 or so return delimited lines each containing
> 17 comma delimited items. I wrote a script to read the file into a
> variable called theImportedData, delete 2 records, alter a 3rd,
> display the results in a field and then save the file again.
>
> I came up with the followiing two handlers. Both are executed by Rev
> Media but removeFields1 doesn't do anything! ie the delete lines do
> not alter the file. removeFields2 does what its supposed to do.
>
<snip script>

> Am I missing something? I think I must because I can't see what is
> wrong with the 1st script -- and Rev doesn't find a problem either
> because it executes without error. The data in the variable is just
> untouched and gets saved again intact.
>
> I'm quite happy to use the 2nd script but I'm curious as to why the
> first one doesn't work.
>
>
> Thanks
>
> Ian McKnight




More information about the use-livecode mailing list