Jump to content

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


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[..]

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
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...