Display Status of a Repeat Loop

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Display Status of a Repeat Loop

Post by richardmac » Wed Dec 15, 2010 6:45 pm

Hello,
Just got on board with LiveCode recently, previous a MetaCard guy. Here's my issue. In a repeat loop, I used to put a running count into a field so I could see the progress of the script. This does not work in LiveCode so I'm looking for a workaround.

Example:

repeat with i = 1 to 1000
-- do some action here
put i into field "status"
end repeat

When run, the field "status" would flash the numbers going by and I could see how far the script was. Now it does not. Instead of 1000, picture the number of lines in a 15 MB text file - like 70 thousand lines or so. I'd like to be able to see where I am in the process while the script runs. Best workaround/idea?

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Display Status of a Repeat Loop

Post by Klaus » Wed Dec 15, 2010 7:01 pm

Hi Richard,

you need to give the app a little (very little indeed :wink:) time to update the screen:
...
repeat with i = 1 to 1000
-- do some action here
put i into field "status"
wait 0 with messages
## as I said VERY little time :D
end repeat
...
That should do the trick.


Best

Klaus

P.S.
MetaCard still works with the LiveCode engine! 8)

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Display Status of a Repeat Loop

Post by Klaus » Wed Dec 15, 2010 7:04 pm

Addendum!

Since displaying something in a field during a repeat loop will slow down performance heavily,
you should not display EVERY number in the field. Better only display every 100th or even 1000th number!

Code: Select all

...
repeat with i = 1 to 1000
  -- do some action here
  if i mod 100 = 0 then
    put i into field "status" 
  end if
end repeat
...
You get the picture!


Best

Klaus

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Display Status of a Repeat Loop

Post by jmburnod » Wed Dec 15, 2010 7:08 pm

Caramba!

Klaus is so fast :shock:
Yes it work and the addendum is useful

Jean-Marc
https://alternatic.ch

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Display Status of a Repeat Loop

Post by Klaus » Wed Dec 15, 2010 7:16 pm

Yep, call me "Speedy Gonzales"! :D

richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Re: Display Status of a Repeat Loop

Post by richardmac » Wed Dec 15, 2010 8:37 pm

Awesome! Will implement immediately. Thanks for the help - I really appreciate it.

Post Reply