Mat Posted March 5, 2009 Posted March 5, 2009 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 AutoIt Project Listing
Paulie Posted March 5, 2009 Posted March 5, 2009 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 MdieselIf 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.
Mat Posted March 5, 2009 Author Posted March 5, 2009 thanks - my internet is busy being replaced at home - so is not working (i'm in the middle of my ICT lesson at school ) Ill see what i can do meanwhile... recommendation to any developers - right a script saying Restartscript () thankyou AutoIt Project Listing
Andreik Posted March 5, 2009 Posted March 5, 2009 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
Mat Posted March 5, 2009 Author Posted March 5, 2009 here is my script: expandcollapse popup#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 AutoIt Project Listing
RiCK_420_333 Posted March 6, 2009 Posted March 6, 2009 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.
Mat Posted March 6, 2009 Author Posted March 6, 2009 i agree with you there - it could have made my life a lot easier.... is there any boards to load suggestions or do you have to pm a dev?? mdiesel AutoIt Project Listing
Andreik Posted March 6, 2009 Posted March 6, 2009 You can also create a BAT file and run it and them exit current script.
BlackPhoenix Posted March 6, 2009 Posted March 6, 2009 (edited) here is my script: expandcollapse popup#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: expandcollapse popup#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 March 6, 2009 by BlackPhoenix
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now