Jump to content

Display a message after a certain time has elapsed


Go to solution Solved by bladem2003,

Recommended Posts

Hello everybody, I am new to this language and I am also new as a programmer. I am not experienced enough but I keep trying. I don't know if I ask in the right place.
I have in mind to create a counter or something to measure the time so that when a certain time passes I can send a message I am looking for simple examples I put example of my code. It does not work but I want to do something similar and in case  to do this example with a counter, could you give me some examples, thank you.

 

$start=TimerInit()

If($start >= 9000) Then

    MsgBox(0,"time"," 9 seconds have passed ")

EndIf


 

Link to comment
Share on other sites

48 minutes ago, bladem2003 said:

try this.

 

$start = TimerInit()

While 1
    If TimerDiff($start) >= 9000 Then
        MsgBox(0, "time", " 9 seconds have passed ")
        Exit
    EndIf
WEnd

 

Thanks my friend, I just had to put it in a while.

I wanted to ask additionally when the 9 seconds pass how can I reset the TimerInit() to 0, is there any method?

Link to comment
Share on other sites

6 hours ago, Dsmoeg999 said:

how can I reset the TimerInit() to 0, is there any method?

Rerun another assignment $MyTime = TimerIInit().

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)

Link to comment
Share on other sites

:idea:

Global $start

TimerStart()

While 1
    If TimerDiff($start) >= 9000 Then
        $iMsgBoxAnswer = MsgBox(4, "time", "9 seconds have passed" & @CRLF & "Do you want 9 second more?")
        Select
            Case $iMsgBoxAnswer = 6 ;Yes
                TimerStart()
            Case $iMsgBoxAnswer = 7 ;No
                Exit
        EndSelect
    EndIf

    Sleep(50)
WEnd

Func TimerStart()
    $start = TimerInit()
    ConsoleWrite("- TimerStart" & @CRLF)
EndFunc   ;==>TimerStart

 

I know that I know nothing

Link to comment
Share on other sites

$start = TimerInit()

Hi guys I assume that the value of the variable initially is 0 and it is in milliseconds I am showing the value in a message and it shows me this number 6140027826074 which I    don't understand. I want to try to convert the milliseconds to seconds and then to minutes can you guide me thanks. Following the example 9 seconds would be 0.15 minutes  and be able to display it.

Link to comment
Share on other sites

Hi ioa747, I like the idea very much, thank you for your contribution.I am using your example and I need help I have changed it so that it is in a function and it does not work and it could be that after the time has elapsed the execution ends directly without asking with the dialog.

Global $start




While 1

    TimerStart()

WEnd

Func TimerStart()
    $start = TimerInit()
    If TimerDiff($start) >= 9000 Then
        $iMsgBoxAnswer = MsgBox(4, "time", "9 seconds have passed" & @CRLF & "Do you want 9 second more?")
        Select
            Case $iMsgBoxAnswer = 6 ;Yes
                TimerStart()
            Case $iMsgBoxAnswer = 7 ;No
                Exit
        EndSelect
    EndIf
EndFunc   ;==>TimerStart

 

Link to comment
Share on other sites

15 hours ago, Dsmoeg999 said:

I am using your example ...

 

Global $start

While 1
    TimerStart()
    Sleep(500)
WEnd

Func TimerStart()
    ConsoleWrite("$start=" & $start & @CRLF)
    If Not $start Then
        $start = TimerInit()
    Else
        If TimerDiff($start) >= 9000 Then
            $iMsgBoxAnswer = MsgBox(4, "time", "9 seconds have passed" & @CRLF & "Do you want 9 second more?")
            Select
                Case $iMsgBoxAnswer = 6 ;Yes
                    $start = ""
                Case $iMsgBoxAnswer = 7 ;No
                    Exit
            EndSelect
        EndIf
    EndIf
EndFunc   ;==>TimerStart

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

23 hours ago, Dsmoeg999 said:
$start = TimerInit()

Hi guys I assume that the value of the variable initially is 0 and it is in milliseconds I am showing the value in a message and it shows me this number 6140027826074

Just to answer this, read the helpfile: https://www.autoitscript.com/autoit3/docs/functions/TimerInit.htm

Quote

The return value from TimerInit() should be treated as an opaque handle and should only be used to pass to TimerDiff(). Any other usage of the return value is a potential error.

You should not be trying to read from the $start variable yourself. Only pass it into TimerDiff(), and from that the number that is returned is the milliseconds difference from when you called TimerInit() to TimerDiff().

If you really want to use the TimerInit() value yourself you can, however it's more work than it's worth:

Global $hTimer1 = TimerInit(), $hTimer2, $nTimerDiff, $nMsDifference
Sleep(1000)
$hTimer2 = TimerInit()
$nTimerDiff = TimerDiff($hTimer1)
$nMsDifference = ($hTimer2 - $hTimer1) / 10000

ConsoleWrite('TimerDiff milliseconds since first timer: ' & Round($nTimerDiff, 2) & ' ms' & @CRLF)
ConsoleWrite('Milliseconds since first timer, calculated: ' & Round($nMsDifference, 2) & ' ms' & @CRLF)

Exit

For what it's worth, TimerInit is the time the system has been up in 100 nano-second units. So dividing the value by 10,000 gets you to 1ms.

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

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