Why?

Klaus Major k_major at os.surf2000.de
Thu Mar 6 06:45:01 EST 2003


Hi Tariel,

> on mouseUp
>
>   Put "N,33,0,No Answer" into line 1 of TestLog
>   Put "N,11,0" into line 2 of TestLog
>
>   repeat for each line LL in TestLog
>     if last char of LL <> comma then
>       put comma after LL
>       -- HERE LL with line 2 of TestLog gets replaced
>       -- by previous LL which was holding line 1 of TestLog
>     end if
>     add item 2 of LL to tTest
>   end repeat
>
>   put tTest
>
>   -- returns 66 instead of 44 that one might expect
>
> end mouseUp
>
> I was getting inconsistent results in large script and it took me a 
> while to narrow down the bug to the script above.
> I can work around this phenomena of course but just curious why is 
> this happening?
>
> Best regards
> Tariel

This is no bug but "repeat for each xxx" is a READ-only thing.

That means you cannot change "each xxx", just read it.

So you will have to put a "modified "each xxx" into another variable.

Like this:

...
   put empty into your_temp_var
   Put "N,33,0,No Answer" into line 1 of TestLog
   Put "N,11,0" into line 2 of TestLog

   repeat for each line LL in TestLog
     if last char of LL <> comma then
       put LL & comma & CR after your_temp_var
       -- HERE LL with line 2 of TestLog gets replaced
       -- by previous LL which was holding line 1 of TestLog
       else ###!!!
          put LL & CR after your_temp_var
     end if
     delete char -1 of  your_temp_var
     ## get rid of last CR
     put  your_temp_var into TestLog
     add item 2 of LL to tTest
   end repeat
...

Took a while until i got used to this... ;-)

Hope that helps.

Regards


Klaus Major
k_major at os.surf2000.de




More information about the metacard mailing list