Jump to content
Sign in to follow this  
Mat

restarting a script

Recommended Posts

Mat

is there a simple command for me to do this? all i intend to do is have a simple button in a gui ($button) which when pressed, restarts the script - but also closes all the current dialogs - not ending the script. I've toyed around with a few ideas - including return, winclosing the boxes while opening the new script etc, but none seem to work. I haven't tried using multiple functions yet - but i'd rather not - as this could make a small script considerably harder....

thanks

Mdiesel

Share this post


Link to post
Share on other sites
Paulie

is there a simple command for me to do this? all i intend to do is have a simple button in a gui ($button) which when pressed, restarts the script - but also closes all the current dialogs - not ending the script. I've toyed around with a few ideas - including return, winclosing the boxes while opening the new script etc, but none seem to work. I haven't tried using multiple functions yet - but i'd rather not - as this could make a small script considerably harder....

thanks

Mdiesel

If by simple you mean a "RestartScript()" function, then no, there is no simple way.

However, it is possible depending on what your script does/how you wrote it.

Post your script, see what comes up.

Share this post


Link to post
Share on other sites
Mat

thanks - my internet is busy being replaced at home - so is not working (i'm in the middle of my ICT lesson at school :P )

Ill see what i can do

meanwhile...

recommendation to any developers - right a script saying Restartscript ()

thankyou

Share this post


Link to post
Share on other sites
Andreik

Example:

$Number = 0
While 1
    $Number += 1
    TrayTip("TEST",$Number,1)
    If $Number = 50 Then Restart()
    Sleep(20)
WEnd

Func Restart()
If Not @Compiled Then 
    Run(@AutoItExe & " " & FileGetShortName(@ScriptFullPath))
ElseIf @Compiled Then 
    Run(@ScriptFullPath)
EndIf
Exit
EndFunc

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Mat

here is my script:

#include <GUIConstantsEx.au3>
#Include <Clipboard.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Opt("TrayIconHide", 1)
Opt("GUICloseOnESC", 0)

_main ()

func _Main ()
   local $msg, $long, $short, $copy, $close, $retry, $GUI, $error

$long = Inputbox ("long File name", "Please give the long file name to convert.", "C:\")
   if @error = 1 then
      exit
   endif
$short = FileGetShortName ($long)

$GUI = GuiCreate("Short File Name Generator", 392, 168, -1, -1)
   GuiCtrlCreateLabel("The short file name is: " & @CRLF & "" & $short & ".", 10, 10, 370, 100)
   $Copy = GuiCtrlCreateButton("Copy", 10, 120, 110, 30)
   $Retry = GuiCtrlCreateButton("Try again", 130, 120, 110, 30)
   $close = GuiCtrlCreateButton("Close", 250, 120, 110, 30)
   
GUISetState ()

 do
      $msg = GUIGetmsg()
         select
            case $msg = $retry
               ____________________________________________________ (script to go here)
            case $msg = $copy
               ClipPut ($short)
            case $msg = $close or $msg = $GUI_Event_Close
               Exit
         Endselect
   until $msg = $GUI_Event_Close
endfunc

what happens at the moment is I click retry (where it simply directs to _main () ) and it opens a new dialog, leaving the old one there - but if i close the old one - it closes the new one becouse it is closing the script instead of the GUI...

@Andreik:

so mine would look like;

do
$msg = GUIGetmsg()
select
case $msg = $retry
Restart ()
until $msg = $GUI_Event_close
endfunc

Func Restart()
If Not @Compiled Then
    Run(@AutoItExe & " " & FileGetShortName(@ScriptFullPath))
ElseIf @Compiled Then
    Run(@ScriptFullPath)
EndIf
Exit
EndFunc

That works great!! But how? I undertand that it is running the script - but how does it close the current one before opening or get around the fact that they both close together?

Thanks again

Mdiesel

Share this post


Link to post
Share on other sites
RiCK_420_333

Sorry but all these answers seem sloppy to me.

It runs the program before closing the first one, which in some some cases will not be appropriate.

I think there should be a RestartScript() function built in, so it can close the first instance of the program, wait til it is closed, and then load it again.

Also this could be done with a Run command like, RunClose, RunWaitClose, or something like that.


Share this post


Link to post
Share on other sites
Mat

i agree with you there - it could have made my life a lot easier.... :P

is there any boards to load suggestions or do you have to pm a dev??

mdiesel

Share this post


Link to post
Share on other sites
Andreik

You can also create a BAT file and run it and them exit current script.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
BlackPhoenix

here is my script:

#include <GUIConstantsEx.au3>
#Include <Clipboard.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Opt("TrayIconHide", 1)
Opt("GUICloseOnESC", 0)

_main ()

func _Main ()
   local $msg, $long, $short, $copy, $close, $retry, $GUI, $error

$long = Inputbox ("long File name", "Please give the long file name to convert.", "C:\")
   if @error = 1 then
      exit
   endif
$short = FileGetShortName ($long)

$GUI = GuiCreate("Short File Name Generator", 392, 168, -1, -1)
   GuiCtrlCreateLabel("The short file name is: " & @CRLF & "" & $short & ".", 10, 10, 370, 100)
   $Copy = GuiCtrlCreateButton("Copy", 10, 120, 110, 30)
   $Retry = GuiCtrlCreateButton("Try again", 130, 120, 110, 30)
   $close = GuiCtrlCreateButton("Close", 250, 120, 110, 30)
   
GUISetState ()

 do
      $msg = GUIGetmsg()
         select
            case $msg = $retry
               ____________________________________________________ (script to go here)
            case $msg = $copy
               ClipPut ($short)
            case $msg = $close or $msg = $GUI_Event_Close
               Exit
         Endselect
   until $msg = $GUI_Event_Close
endfunc

what happens at the moment is I click retry (where it simply directs to _main () ) and it opens a new dialog, leaving the old one there - but if i close the old one - it closes the new one becouse it is closing the script instead of the GUI...

@Andreik:

so mine would look like;

do
$msg = GUIGetmsg()
select
case $msg = $retry
Restart ()
until $msg = $GUI_Event_close
endfunc

Func Restart()
If Not @Compiled Then
    Run(@AutoItExe & " " & FileGetShortName(@ScriptFullPath))
ElseIf @Compiled Then
    Run(@ScriptFullPath)
EndIf
Exit
EndFunc

That works great!! But how? I undertand that it is running the script - but how does it close the current one before opening or get around the fact that they both close together?

Thanks again

Mdiesel

I was having, troubles with this 2, I did this:

#include <GUIConstantsEx.au3>
#Include <Clipboard.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Opt("TrayIconHide", 1)
Opt("GUICloseOnESC", 0)

_main ()

func _Main ()
   local $msg, $long, $short, $copy, $close, $retry, $GUI, $error

$long = Inputbox ("long File name", "Please give the long file name to convert.", "C:\")
   if @error = 1 then
      exit
   endif
$short = FileGetShortName ($long)

$GUI = GuiCreate("Short File Name Generator", 392, 168, -1, -1)
   GuiCtrlCreateLabel("The short file name is: " & @CRLF & "" & $short & ".", 10, 10, 370, 100)
   $Copy = GuiCtrlCreateButton("Copy", 10, 120, 110, 30)
   $Retry = GuiCtrlCreateButton("Try again", 130, 120, 110, 30)
   $close = GuiCtrlCreateButton("Close", 250, 120, 110, 30)
   
GUISetState ()

do
      $msg = GUIGetmsg()
         select
            case $msg = $retry
               Guidelete($GUI)
     _main()
            case $msg = $copy
               ClipPut ($short)
            case $msg = $close or $msg = $GUI_Event_Close
               Exit
         Endselect
   until $msg = $GUI_Event_Close
endfunc

Note: this isn't restarting the script, but just deleting the previous GUI, it maybe not the solution if you want to restart the script completely but it gives the user to reenter the data

Edited by BlackPhoenix

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.