Sign in to follow this  
Followers 0
ReaImDown

how do I count in seconds?

6 posts in this topic

$i = 1
do
ToolTip(Int((100 - $i) / 10))
$i = $i + 1
until $i = 100

this kind of seems to work, but I think its 1/2 a second off :) lol


[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites



This is the best way to do what you are asking. Please keep in mind that the sleep() function also pauses a script for an amount of time. The sleep function pauses a script for a certain number of milliseconds. 1000 milliseconds is equal to 1 second, so if you want to pause a script for 1 second, you would simply do Sleep(1000).

The way I am doing it here utilizes the Timer functions that AutoIt has. The timer functions check to see how much time has passed since they were activated. TimerInit() creates an activation value that can be read by TimerDiff(). TimerDiff() then returns the amount of time in milliseconds since TimerInit() set a timestamp on the variable.

Dim $i_TimeStamp = TimerInit()
Dim $i_TimeToCountDownFromSeconds = 10
Dim $i_OriginalSeconds = $i_TimeToCountDownFromSeconds
While 1
    If TimerDiff($i_TimeStamp) >= 1000 Then
        ToolTip($i_TimeToCountDownFromSeconds)
        $i_TimeStamp = TimerInit()
        IF $i_TimeToCountDownFromSeconds = 0 Then Exitloop
        $i_TimeToCountDownFromSeconds -= 1
    EndIf
    sleep(10)
WEnd
Msgbox(0,"Done!","Done counting down from " & $i_OriginalSeconds  & ".")

- The Kandie Man ;-)


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

I'm wondering why don't you use Sleep?

Is this what you want?

$i = 1
do
Sleep(1000)
ToolTip(Int($i))
$i = $i + 1
until $i = 100

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

I'm wondering why don't you use Sleep?

Is this what you want?

$i = 1
do
Sleep(1000)
ToolTip(Int($i))
$i = $i + 1
until $i = 100
If you're wanting to do anything in-between the code, you wouldn't necessarily want to use sleep?

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

#5 ·  Posted (edited)

If you're wanting to do anything in-between the code, you wouldn't necessarily want to use sleep?

I would be wanting to do stuff as well as that lol

This is the best way to do what you are asking. Please keep in mind that the sleep() function also pauses a script for an amount of time. The sleep function pauses a script for a certain number of milliseconds. 1000 milliseconds is equal to 1 second, so if you want to pause a script for 1 second, you would simply do Sleep(1000).

The way I am doing it here utilizes the Timer functions that AutoIt has. The timer functions check to see how much time has passed since they were activated. TimerInit() creates an activation value that can be read by TimerDiff(). TimerDiff() then returns the amount of time in milliseconds since TimerInit() set a timestamp on the variable.

Dim $i_TimeStamp = TimerInit()
Dim $i_TimeToCountDownFromSeconds = 10
Dim $i_OriginalSeconds = $i_TimeToCountDownFromSeconds
While 1
    If TimerDiff($i_TimeStamp) >= 1000 Then
        ToolTip($i_TimeToCountDownFromSeconds)
        $i_TimeStamp = TimerInit()
        IF $i_TimeToCountDownFromSeconds = 0 Then Exitloop
        $i_TimeToCountDownFromSeconds -= 1
    EndIf
    sleep(10)
WEnd
Msgbox(0,"Done!","Done counting down from " & $i_OriginalSeconds  & ".")

- The Kandie Man ;-)

thanks! exactly what I needed :)

Edited by ReaImDown

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites

I would be wanting to do stuff as well as that lol

thanks! exactly what I needed :)

Another favorite of mine is to use AdLibEnable() to get a "set it and forget it" kind of timer running in the background:

$PulseTime = Number(InputBox("Pulse", "Enter time in msec between pulses: "))
HotKeySet("{ESC}", "_Quit")
AdlibEnable("_Pulse", $PulseTime)

; The script can go on and do anything else in the mean time:
$Pi = 3.0
$PiDigits = 0
Do 
    ; Calculate 1,000,000 digits of pi...
    Sleep(5)
    $PiDigits += 1
Until $PiDigits = 1000000

Func _Pulse()
    TrayTip("Pulse of Pi", "Pi calculated to " & $PiDigits & " places...", 5)
    Beep(2000, 100)
EndFunc

Func _Quit()
    Exit
EndFunc

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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