Jump to content
Sign in to follow this  
Christopher Blue

Best way to run a script until a MsgBox is closed?

Recommended Posts

Christopher Blue

I am looking to start a script, have to throw up a MsgBox that says it's working, and have the script work until the user clicks the "OK" button on the MsgBox. What is the best way to do this? MsgBox doesn't return until the box is gone so I am not sure how to do that.

Edited by Christopher Blue

Share this post


Link to post
Share on other sites
ezzetabi

I am afraid you have to use 2 scripts.

E.g.

Script 1

FileWrite(@tempdir & '\going.tmp','')
$sCmd = 'script2.au3'
$sFolder = 'c:\folder of script 2\'
DllCall("shell32.dll", "long", "ShellExecute", "hwnd", 0, "string", 'Open', _
        "string", $sCmd, "string", '', "string", $sFolder, "long", @SW_SHOWNORMAL)

MsgBox(0,'Going...','Script 2 is working. Click OK to stop.')
FileDelete(@tempdir & '\going.tmp')

Script 2

While FileExists(@tempdir & '\going.tmp')
  ;What you need here.
WEnd

Edit: Small fix. I forgot the 'line' argument in FileWrite.

Edited by ezzetabi

Share this post


Link to post
Share on other sites
Christopher Blue

Thanks ezzetabi, I will look into implementing your solution.

Share this post


Link to post
Share on other sites
trids

Ezzetabi is correct .. if you specifically want the trigger to be the clicking of a button on a MsgBox.

However .. :idiot:

If you simply want to terminate a script by clicking something when you're ready .. then that facility is already a default feature of AutoIt: simply rightclick the icon in the system tray, and select "exit" from the menu. :lol:

Note that a rightclick like this also pauses the script, which is why there is another entry on it for you to un-pause it if you decide to let it continue. :D

Hope this helps

Share this post


Link to post
Share on other sites
ezzetabi

Only a point is unclear to me. Do you need to ISTANT STOP when the user click OK or just stop when the while loop ends?

In my implementation the 'Script 2' will stop only when the loop finish.

If you need a instant stop you have to use something like:

Script 2

AdlibEnable('_ShouldIContinue')
Do
  ;What you need here.
Until 0

Exit
Func _ShouldIContinue()
   If Not FileExists(@tempdir & '\going.tmp') Then
      Exit;Of couse you may need OnAutoItExit func for 'just-before-leave things...'
   EndIf
EndFunc

Edit: Trids is smarter than me we know. His solution is obiously better as instant stop... :idiot:

Edited by ezzetabi

Share this post


Link to post
Share on other sites
Christopher Blue

Actually, I am going to take this opportunity to learn more about the GUI methods. I just made a rudimentary window with some text that is checked each work loop to see if it was sent a close message.

Edited by Christopher Blue

Share this post


Link to post
Share on other sites
Christopher Blue

Ezzetabi is correct .. if you specifically want the trigger to be the clicking of a button on a MsgBox.

However ..  :idiot:

If you simply want to terminate a script by clicking something when you're ready .. then that facility is already a default feature of AutoIt: simply rightclick the icon in the system tray, and select "exit" from the menu.  :lol:

Note that a rightclick like this also pauses the script, which is why there is another entry on it for you to un-pause it if you decide to let it continue.  :D

Hope this helps

<{POST_SNAPBACK}>

Aye, my first implementation had the script use a MsgBox which the user would "OK" when they wanted the script to start running. They would then stop the script using the method you describe at which point the script would call OnAutoItExit() and in that function I would take care of any other work before exiting.

Share this post


Link to post
Share on other sites
trids

[..]

Edit: Trids is smarter than me we know. His solution is obiously better as instant stop... :idiot:

<{POST_SNAPBACK}>

Not smarter .. I just believe in "less is more". Your watchdog script is very clever, and comes in handy for all sorts of applications :D

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.