Jump to content

restarting a script


 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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