Jump to content

After X Minutes


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • 8 months later...

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