Jump to content
Sign in to follow this  
DfGik

After X Minutes

Recommended Posts

DfGik

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 by DfGik

Share this post


Link to post
Share on other sites
Valuater

1

$start=TimerInit()

While(1)

$diff = TimerDiff($sStart) ; has 2 "s"

2

$frequency is not defined

3

might want to use

if $diff >= $frequency ; as to not be exact - because it most likely will not be exact

4

IECreate($oIE,"http://www.somewebsite.com")

$start=TimerInit() ; or 0 or something so it will not create another IE

EndIf

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
DfGik

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

Share this post


Link to post
Share on other sites
Valuater

take a look at my #3 and #4

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
DfGik

Thank you very much,

I'm gonna test it later and keep you tuned :rolleyes:

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 by DfGik

Share this post


Link to post
Share on other sites
SmOke_N

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 :rolleyes: )

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.

Share this post


Link to post
Share on other sites
DfGik

It works like a charm now, thank you :rambo:

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 :x )

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 :rolleyes:

Share this post


Link to post
Share on other sites
SmOke_N

It works like a charm now, thank you :rambo:

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 :rolleyes:

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.

Share this post


Link to post
Share on other sites
Shevilie

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

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
Shevilie

Hey I'm a guy... cant multitask :rolleyes:


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites
SmOke_N

Hey I'm a guy... cant multitask :rolleyes:

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.

Share this post


Link to post
Share on other sites
ShminkyBoy

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:

global $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 by ShminkyBoy

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  

×