question about how to update an item in a field in batch mode

Sarah Reichelt sarah.reichelt at gmail.com
Tue Jan 22 15:19:33 EST 2008


On Jan 23, 2008 5:32 AM, Peter Alcibiades <palcibiades-first at yahoo.co.uk> wrote:
> Trying Sarah's suggestion first, but cannot seem to make it work:
>
> on mouseUp
>   set the itemDelimiter to tab
>   repeat for each line L in field "tSales"
>     get lineOffset(item 1 to 2 of L, "tStock")
>     if it > 0 then subtract 1 from item 5 of line it of field "tStock"
>   end repeat
> end mouseUp
>
> It does nothing.  The reason being that variable it is always 0, though there
> should be a match for items 1 to 2.  If I make it just match on item 1, same
> thing.

In the lineOffset comparison, you are asking it to find the text in
the string "tStock" which you have quoted. You have not supplied a
variable name or indicated a field. I strongly recommend that you put
the fields into variables and work with them instead of directly with
the fields. This will be many times faster.

> Then if I take out the condition, something even stranger happens.  It writes
> as many zeros as there are items doing the match before item 1 of line 1 of
> tStoc.  (there are two items which should match in the sample file, and for
> some reason the only one it finds is the second one!)

This makes sense. You are asking it to change line 0 of the data every
time through the loop and as there is no line zero, Rev is changing
what appears before line 1 which is the closest it can get.

Cheers,
Sarah



More information about the use-livecode mailing list