Sign in to follow this  
Followers 0
c4mpi

TimerInit() help and find words

7 posts in this topic

Hi, I am new to autoit and want to do a sleep without stopping the script. I saw on another forum that I can do this using TimerInit() and TimerDiff. But I dont understand how to use it, I need it to wait 1 hour then run a part of my script.

I also need a way to find words on a site. Like search it up.

I appreciate all help (sorry for my bad english)

Share this post


Link to post
Share on other sites



Welcome to the AutoIt forum!

Sleep() will pause (but not terminate) the script. While sleeping, no significant CPU is consumed until timeout and execution resumes on the next instruction after Sleep.

So Sleep() is for you, AFAICS. Timer* functions are what they're called: timing functions. Execution continues after TimerInit and you may call TimerDiff anytime to know the elapsed time from TimerInit.

To grab text from a source html, you may use _IE* or Inet* functions. E.g. _IEAttach and _IEDocReadHTML, or _InetGetSource or InetRead or InetGet then use StringRegexp or whatever String* functions suits your need to dissect things.

Anyway, your best friend here is no more Google: when it relates to AutoIt, your best friend by far is the help file! Almost everything you can find on the forum comes from there.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Welcome to the forums.

I'm a big fan of you learning how to do it by thinking it through yourself. So lets go through the logic process and see if you can get an answer.

So if you look at the functions in the help file you will see that TimerInit() will start the timer. If we look at what TimerDiff() does we can see that it returns the time (in milliseconds) from when you initiated it with TimerInit(). So with a conditional statement we can find out when TimerDiff is equal to an hour. But what if the script works out the difference at 1 hour and 1ms? Instead of using just = in our conditional statement we should use >=. If TIMER is GREATER or EQUAL to 1 HOUR (in milliseconds).

So we can check it once but how do we check it more than one time? The simplest way will be with a While...Wend loop. Remember you don't want to keep initiating your timer, so keep TimerInit out of the loop.

I think I've given you enough information and hints to work this out. Give it a go and post back if you have any problems. Remember to post your code :mellow:

Cheers,

Brett

Share this post


Link to post
Share on other sites

Hi, I am new to autoit and want to do a sleep without stopping the script. I saw on another forum that I can do this using TimerInit() and TimerDiff. But I dont understand how to use it, I need it to wait 1 hour then run a part of my script.

I also need a way to find words on a site. Like search it up.

I appreciate all help (sorry for my bad english)

Thanks for the help, I understand how you can find a text using source code now.

Share this post


Link to post
Share on other sites

Welcome to the forums.

I'm a big fan of you learning how to do it by thinking it through yourself. So lets go through the logic process and see if you can get an answer.

So if you look at the functions in the help file you will see that TimerInit() will start the timer. If we look at what TimerDiff() does we can see that it returns the time (in milliseconds) from when you initiated it with TimerInit(). So with a conditional statement we can find out when TimerDiff is equal to an hour. But what if the script works out the difference at 1 hour and 1ms? Instead of using just = in our conditional statement we should use >=. If TIMER is GREATER or EQUAL to 1 HOUR (in milliseconds).

So we can check it once but how do we check it more than one time? The simplest way will be with a While...Wend loop. Remember you don't want to keep initiating your timer, so keep TimerInit out of the loop.

I think I've given you enough information and hints to work this out. Give it a go and post back if you have any problems. Remember to post your code :mellow:

Cheers,

Brett

Thanks for the hints and help, I will think trough this and post a reply if I cant find a solution

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks for the hints and help, I will think trough this and post a reply if I cant find a solution

Okey so I made a quick script out of what you said

$timer = TimerInit() ; this marks the start

While 1
    $timed = TimerDiff($timer)
    If $timed > 3000 Then 
        MYSCRIPT HERE
        $timer = TimerInit()
    EndIf
WEnd

Would this be able to run in the "background", what I mean with this is; will this pause the script? And may I somehow set the timer to one hour in a easier way then writing it in ms?

thanks

Edited by c4mpi

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  
Followers 0