DfGik Posted June 13, 2007 Posted June 13, 2007 (edited) Hi there, How can I in a loop do something like : after X minutes, go to a website for example and then when the same amount X minutes is reached go to the same website? A pseudo code I got is : $start=TimerInit() While(1) $diff = TimerDiff($sStart) if $diff = $frequency _IECreate($oIE,"http://www.somewebsite.com") EndIf WEnd But it doesn't work.. Any Ideas? Edited June 13, 2007 by DfGik
Valuater Posted June 13, 2007 Posted June 13, 2007 (edited) 1$start=TimerInit() While(1) $diff = TimerDiff($sStart) ; has 2 "s"2$frequency is not defined3might want to useif $diff >= $frequency ; as to not be exact - because it most likely will not be exact4IECreate($oIE,"http://www.somewebsite.com")$start=TimerInit() ; or 0 or something so it will not create another IEEndIf8) Edited June 13, 2007 by Valuater
DfGik Posted June 13, 2007 Author Posted June 13, 2007 Sorry The Whole function is Func AchatBat() $frequency = InputBox("Infos","Which Frequency?") $sStart = TimerInit() While(1) $diff = TimerDiff($sStart) if $diff = $frequency _IECreate($oIE,"http://www.somewebsite.com") EndIf WEnd EndFunc
DfGik Posted June 13, 2007 Author Posted June 13, 2007 (edited) Thank you very much, I'm gonna test it later and keep you tuned Ok So I test It and : - Even if I multiply the frequency by 60 in order to have a minute it considers it as a millisecond I think? - It opens indefinately IE with not the url but with only "http:///" Edited June 13, 2007 by DfGik
Moderators SmOke_N Posted June 13, 2007 Moderators Posted June 13, 2007 I'm surprised it's running at all to be honest.... If you use SciTe Editor, and run the Au3Check you'll see some errors (an example would be, when you use an "If/Then" statement, you actually need the "Then" part ) TimerInit() is in milliseconds... so how do you make the difference calculate "seconds"? $diff = TimerDiff($start) / 1000 <<< return result in seconds, then you can do * 60 for minutes, or * 60 * 60 for hours. Example: ;milliseconds only $nStart = TimerInit() Do Sleep(10) Until TimerDiff($nStart) >= 3000 MsgBox(64, 'Info', 'At least 3 seconds (3000 milliseconds) have passed since you ran this script.') ;Seconds only $nStart = TimerInit() Do Sleep(10) Until TimerDiff($nStart) / 1000 >= 3 MsgBox(64, 'Info', 'At least 3 seconds (3000 milliseconds) have passed since you ran this script.') ;Minutes only Do Sleep(10) Until (TimerDiff($nStart) / 1000) * 60 >= 1 MsgBox(64, 'Info', 'At least 1 minute has passed since you ran this script.') ;Hours only Do Sleep(10) Until ((TimerDiff($nStart) / 1000) * 60) * 60 >= 1 MsgBox(64, 'Info', 'At least 1 hour has passed since you ran this script.')Pay attention to the parenthesis as well, make sure you understand why I used them. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
DfGik Posted June 13, 2007 Author Posted June 13, 2007 It works like a charm now, thank you I'm surprised it's running at all to be honest.... If you use SciTe Editor, and run the Au3Check you'll see some errors (an example would be, when you use an "If/Then" statement, you actually need the "Then" part )Indeed,it didn't compile I needed to put the "Then" instruction after the "if" condition You put parenthesis because of the arithmetics operations order right? Until (TimerDiff($nStart) / 1000) >= 3 No? This community is really great thanks guys
Moderators SmOke_N Posted June 14, 2007 Moderators Posted June 14, 2007 It works like a charm now, thank you Indeed,it didn't compile I needed to put the "Then" instruction after the "if" condition You put parenthesis because of the arithmetics operations order right? Until (TimerDiff($nStart) / 1000) >= 3 No? This community is really great thanks guys It's not a matter of convenience... it's a matter of grouping my arithmetic the way I want it. (((bracket 1 is done first) bracket 2 is done next) bracket 3 is done last). Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Shevilie Posted June 14, 2007 Posted June 14, 2007 Why just dont use a Sleep() ?? Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit
Moderators SmOke_N Posted June 14, 2007 Moderators Posted June 14, 2007 Why just dont use a Sleep() ??I see this often... generally when people are trying to do "timed" things... they are doing other things in their scripts... if they use "sleep" then the script pauses, which makes a good "AdlibEnable" or a well thought out "TimerInit()/TimerDiff()" script more effective. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Shevilie Posted June 14, 2007 Posted June 14, 2007 Hey I'm a guy... cant multitask Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit
Moderators SmOke_N Posted June 14, 2007 Moderators Posted June 14, 2007 Hey I'm a guy... cant multitask Um... I won't go into a long drawn out discussion on how many ways this statement you gave is wrong... but... I'll say... "That's just wrong!" Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
ShminkyBoy Posted February 27, 2008 Posted February 27, 2008 (edited) Here's one that I wrote for a script i'm working on; it doesn't use do..until or any sleep and keeps track of 2 different timers at once: expandcollapse popupglobal $id_HostTimer, $n_HostAuditTime, $id_ServiceTimer, $n_ServiceAuditTime $n_HostAuditFrequency=3 ;~ timer1 interval is 3 minutes $n_ServiceAuditFrequency=5 ;~ timer2 interval is 5 minutes MsgBox(0,"Time limits",$n_HostAuditFrequency & @crlf & $n_ServiceAuditFrequency) inithosttimer() initservicetimer() ;~ Main while 1 $n_HostAuditTime = ((TimerDiff($id_HostTimer) / 1000) / 60) ;~ get the time for timer1 in minutes $n_ServiceAuditTime = ((TimerDiff($id_ServiceTimer) / 1000) / 60) ;~ get the time for timer2 in minutes If $n_HostAuditTime >= $n_HostAuditFrequency Then AuditHosts() Else EndIf If $n_ServiceAuditTime >= $n_ServiceAuditFrequency Then AuditServices() Else EndIf WEnd Exit ;~ Functions Func InitHostTimer() $n_HostAuditTime=0 $id_HostTimer=TimerInit() EndFunc Func InitServiceTimer() $n_ServiceAuditTime=0 $id_ServiceTimer=TimerInit() EndFunc Func AuditHosts() MsgBox(0,"Host Timer",$n_HostAuditTime) InitHostTimer() EndFunc Func AuditServices() MsgBox(0,"Service Timer",$n_ServiceAuditTime) InitServiceTimer() EndFunc EDIT: eek I didn't realize this post was from June... oh well, hope it helped =) Edited February 27, 2008 by ShminkyBoy Urban Terror - ioUrban Terror website Like-yea
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