Cancel a repeat with a button

Jan Schenkel janschenkel at yahoo.com
Wed May 13 10:41:59 EDT 2009


--- On Wed, 5/13/09, Ludovic Thébault <ludovic.thebault at laposte.net> wrote:

> From: Ludovic Thébault <ludovic.thebault at laposte.net>
> Subject: Cancel a repeat with a button
> To: "How to use Revolution" <use-revolution at lists.runrev.com>
> Date: Wednesday, May 13, 2009, 7:01 AM
> Hello,
> 
> How interrupt a repeat loop by a button ?
> While a copy of a lot of files with rev, i want the user
> can cancel the copy.
> 
>  repeat for each line l in it
>           if char 1 of l <> "." then
>             put convertpath(tstack&"/"&l)
> into tpath1
>             put convertpath(tlibrary&"/")
> into tpath2
>             get shell("cp
> "&tpath1&&tpath2)
> 	end if
> end repeat
> 
> Thanks.
> 

Hi Ludovic,

Change the repeat loop to something like this:
##
enable button "CancelCopy"
set the uInterrupted of me to false
repeat for each line l in it
  if char 1 of l <> "." then
    put convertpath(tstack&"/"&l) into tpath1
    put convertpath(tlibrary&"/") into tpath2
    get shell("cp "&tpath1&&tpath2)
  end if
  wait 0 milliseconds with messages
  if the uInterrupted of me then exit repeat
end repeat
disable button "CancelCopy"
##

Now set the script of your button "CancelCopy" to:
##
on mouseUp
  set the uInterrupted of button "CopyFiles" to true
end mouseUp
##

The 'wait with messages' inside your repeat loop will allow the engine to react to clicks on the button "CancelCopy"

HTH,

Jan Schenkel.
=====
Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)



      



More information about the use-livecode mailing list