Gui Posted February 3, 2010 Share Posted February 3, 2010 Aye guys. Let's say you want to run a script for X amount of minutes, and then close after that X amount of time has passed. Is that possible? I'd like to have a 'User Defined' set timeout for the entire script. So if let's say it's been 10 minutes, the script was to stop and GUI would close. Is it possible in any means? I'm familiar with TimerInit, and TimerDiff, like : $timer = TimerInit() While TimerDiff($timer) <= 5000 ; 5 seconds Sleep(10) WEnd but I have no idea on how to use it for an entire script. Any help is always meaningful. Thanks! Regards, GUI. Link to comment Share on other sites More sharing options...
Mison Posted February 3, 2010 Share Posted February 3, 2010 $init = TimerInit() While 1 If TimerDiff($init) > 3000 Then Exit Sleep(100) WEnd Hi ;) Link to comment Share on other sites More sharing options...
Gui Posted February 3, 2010 Author Share Posted February 3, 2010 $init = TimerInit() While 1 If TimerDiff($init) > 3000 Then Exit Sleep(100) WEnd If you have a GUI, open and running, how would that work? You'd need to put it at the end of the loop which is currently running, but if you did that the shutdown would be off. expandcollapse popup#include #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #Include <GuiEdit.au3> #include <Constants.au3> GuiCreate("Vid5",300,300,400,200) $start = GuiCtrlCreateEdit("",10,10,200,200) $oIE = _IECreateEmbedded() $Obj = GUICtrlCreateObj($oIE,5,5,200,200) GUICtrlSetState(-1,$Obj) GUISetState() While 1 $Msg = GUIGetMsg() If $Msg = $start Then start() EndIf WEnd Func start() While _IENavigate($oIE,'http://www.google.com') ;data; ;more code; ;tone more code; WEnd EndFunc You couldn't just place that anywhere. Link to comment Share on other sites More sharing options...
Mison Posted February 3, 2010 Share Posted February 3, 2010 Well, if that is the case, you can try AdlibRegister... AdlibRegister("adlib") While 1 Sleep(10) ; Idle around WEnd Func adlib() Static $init = TimerInit() If TimerDiff($init) > 10000 Then Exit EndFunc I'm using Version 3.3.2.0 Hi ;) Link to comment Share on other sites More sharing options...
Mison Posted February 3, 2010 Share Posted February 3, 2010 You couldn't just place that anywhere. Ermm... I think it could be done. AFAIK, every Autoit script must have at least 1 running loop, you can place it there. In case of nested loop, use function: $init = TimerInit() While 1 If $some_condition_is_true Then While 1 ; ; _Close() WEnd EndIf ; ; _Close() WEnd Func _Close() If TimerDiff($init) > 5000 Then Exit EndFunc Hi ;) Link to comment Share on other sites More sharing options...
Gui Posted February 3, 2010 Author Share Posted February 3, 2010 (edited) EDIT : Got it working! Sorry had a dumb moment with the function. Anyways I GREATLY appreciate all your help. : ) Edited February 3, 2010 by Gui Link to comment Share on other sites More sharing options...
Mison Posted February 3, 2010 Share Posted February 3, 2010 EDIT : Got it working! Sorry had a dumb moment with the function. Anyways I GREATLY appreciate all your help. : )No problem Hi ;) Link to comment Share on other sites More sharing options...
Minikori Posted February 3, 2010 Share Posted February 3, 2010 every Autoit script must have at least 1 running loopSince when? For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com Link to comment Share on other sites More sharing options...
Mison Posted February 3, 2010 Share Posted February 3, 2010 Since when?Errr.. I mean, to keep the script running, otherwise it will exit when it reaches the bottom.. unless one use a very long Sleep(). This is especially true if you use GUI, in which you must constantly check the GUIGetMsg.But I might be wrong. I'm glad if somebody can help me find another way to idle around without the need to use a While loop.Sorry for not making myself clear at the first place. Hi ;) Link to comment Share on other sites More sharing options...
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