Jump to content

Stop a loop ?


arcker
 Share

Recommended Posts

ok, i've this code (simplified) :

i want that when i click on "Stop", the ping stop...but it's impossible

the program continues to run

=>there is no possibilities until loop finished, even if i want to close the program

$annuler=guictrlcreatebutton("stop"...)
$start=guictrlcreatebutton("start"....)

while 1
$msg = guigetmsg()
if $msg = $start  then _loop()
if $msg = $stop then $stop=1
wend

func _loop()
    while $stop=0
  ;ping the machine
   sleep(1000)
   wend
endfunc

thx for any solution

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

The problem you have is that when Start is clicked, the program goes into an infinite loop in _Loop(). So it will never execute the code asking it to stop.

What you need is an Adlib function. Look it up in the help, but this _should_ do the trick (untested):

If $msg = $start Then AdlibEnable ("_loop", 1000)
If $msg = $stop Then AdlibDisable ()

Don't forget to take out the Sleep (1000) in the function.

ben

Link to comment
Share on other sites

while 1

$msg = guigetmsg()

if $msg = $start then _loop()

if $msg = $stop then exitloop

wend

lol :o

you can try stoping it by using a hotkey, but i think thats not what you want

anyways here is a code-snippet

hotkeyset("!{f6}","stop")
while 1
$msg = guigetmsg()
if $msg = $start  then _loop()
wend

func _loop()
    while $stop=0
 ;ping the machine
   if $msg = $stop then stop()
   sleep(1000)
   wend
endfunc

func stop()
$stop=1
endfunc

if you can't stop your code with the stop-button try alt+f6

Link to comment
Share on other sites

hotkeyset("!{f6}","stop")
while 1
$msg = guigetmsg()
if $msg = $start  then _loop()
wend

func _loop()
    while $stop=0
;ping the machine
   if $msg = $stop then stop()
   sleep(1000)
   wend
endfunc

func stop()
$stop=1
endfunc
Yeah right , $stop must be global :o

hotkeyset("!{f6}","stop")
global $stop = 0; <<<<<------ GLOBAL ^^
while 1
$msg = guigetmsg()
if $msg = $start  then _loop()
wend

func _loop()
    while $stop=0
;ping the machine
   if $msg = $stop then stop()
   sleep(1000)
   wend
endfunc

func stop()
$stop=1
endfunc

-jaenster

Link to comment
Share on other sites

euh

what a noob

after 7 hours of work i've forgot to declare $stop as global

thx jaenster and others !

i'm building a script that ping the servers given in a list

this list can be easily edited

i will post my script later

thx again

c u

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...