Jump to content

clock timer help


Bert
 Share

Recommended Posts

  • Moderators

Does anyone have a example of a timer that starts from 00:00, but does NOT use an array? I've got Valuter's timer, but it is so array depended, I can't rip out what I need without pulling my hair out.

You could do your own time and use this UDF that I made to do the addition and or subtraction Sending it the macros @Hour/@Min/@Sec http://www.autoitscript.com/forum/index.ph...st&p=207691

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

I've spent hours trying to find a example in the forum with no luck. For some reason this is just tearing me a new one in figuring this out. all I'm looking to do is click a button, and the timer starts from 00:00. I looked at what smoke pointed out, but to twist it to what I want is too confusing for me.

I'm the first to say it, and I have no shame

:lmao:

Link to comment
Share on other sites

  • Moderators

I've spent hours trying to find a example in the forum with no luck. For some reason this is just tearing me a new one in figuring this out. all I'm looking to do is click a button, and the timer starts from 00:00. I looked at what smoke pointed out, but to twist it to what I want is too confusing for me.

I'm the first to say it, and I have no shame

:lmao:

Not quote sure how it was confusing with the explination and examples there:
Dim $Time1 = @HOUR & ':' & @MIN & ':' & @SEC, $Time2
While 1
    ToolTip('Timer Started:' & @CR & _
    _StrAddSub($Time1, @HOUR & ':' & @MIN & ':' & @SEC, 0), 0, 0)
    Sleep(100)
WEnd

Func _StrAddSub($sTime1, $sTime2, $iAdd = 1, $sDelim = ':'); $iAdd = 1 Add, $iAdd = 0 Subtract
    Local $aSplit1 = StringSplit($sTime1, $sDelim), $iSubTotal = 0
    Local $aSplit2 = StringSplit($sTime2, $sDelim)
    If $aSplit1[0] <> 3 Or $aSplit2[0] <> 3 Then Return SetError(0, 0, 0)
    Local $iTotal1 = ((Int($aSplit1[1]) * 3600) + (Int($aSplit1[2]) * 60) + (Int($aSplit1[3])))
    Local $iTotal2 = ((Int($aSplit2[1]) * 3600) + (Int($aSplit2[2]) * 60) + (Int($aSplit2[3])))
    If $iAdd Then
        $iSubTotal = $iTotal1 + $iTotal2
    ElseIf $iTotal1 >= $iTotal2 Then
        $iSubTotal = $iTotal1 - $iTotal2
    Else
        $iSubTotal = $iTotal2 - $iTotal1
    EndIf
    Local $iHour = Int(($iSubTotal / 3600))
    Local $iMin = Int(($iSubTotal - ($iHour * 3600)) / 60)
    Local $iSec = Int(($iSubTotal - $iHour * 3600) - ($iMin * 60))
    Return StringFormat('%02d', $iHour) & $sDelim & StringFormat('%02d', $iMin) & $sDelim & StringFormat('%02d', $iSec)
EndFunc

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

This was much simpler for me to understand and to make work for what I needed:

#include <GUIConstants.au3>
#include <Date.au3>
opt("TrayIconDebug",1)
Global $Secs, $Mins, $Hour, $Time
;Create GUI
GUICreate("Timer",120, 50)
GUICtrlCreateLabel("00:00:00", 10,10)
GUISetState()
;Start timer
$timer = TimerInit()
AdlibEnable("Timer", 50)
;
While 1
 ;FileWriteLine("debug.log",@min & ":" & @sec & " ==> before")
  $msg = GUIGetMsg()
 ;FileWriteLine("debug.log",@min & ":" & @sec & " ==> after")
  Select
     Case $msg = $GUI_EVENT_CLOSE
        Exit
  EndSelect
Wend
;
Func Timer()
  _TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs )
  Local $sTime = $Time  ; save current time to be able to test and avoid flicker..
  $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
  If $sTime <> $Time Then ControlSetText("Timer", "", "Static1", $Time)
EndFunc  ;==>Timer
Link to comment
Share on other sites

  • Moderators

This was much simpler for me to understand and to make work for what I needed:

That's only because you didn't see the UDF for _TicksToTime :lmao:

Edit:

Example (Imagine _StrAddSub() being in the Date.au3 and not seeing the UDF):

#include <GUIConstants.au3>
opt("TrayIconDebug",1)
;Create GUI
GUICreate("Timer",120, 50)
GUICtrlCreateLabel("00:00:00", 10,10)
GUISetState()
Global $Time1 = _TimerStartDiff();Lock current time to start timer
AdlibEnable("Timer", 100)
;
While 1
 ;FileWriteLine("debug.log",@min & ":" & @sec & " ==> before")
  $msg = GUIGetMsg()
 ;FileWriteLine("debug.log",@min & ":" & @sec & " ==> after")
  Select
     Case $msg = $GUI_EVENT_CLOSE
        Exit
  EndSelect
Wend
;
Func Timer()
    Local $Time = _StrAddSub($Time1, _TimerStartDiff(), 0)
    ControlSetText("Timer", "", "Static1", $Time)
    Return
EndFunc  ;==>Timer

Func _TimerStartDiff()
    Return @HOUR & ':' & @MIN & ':' & @SEC
EndFunc

Func _StrAddSub($sTime1, $sTime2, $iAdd = 1, $sDelim = ':'); $iAdd = 1 Add, $iAdd = 0 Subtract
    Local $aSplit1 = StringSplit($sTime1, $sDelim), $iSubTotal = 0
    Local $aSplit2 = StringSplit($sTime2, $sDelim)
    If $aSplit1[0] <> 3 Or $aSplit2[0] <> 3 Then Return SetError(0, 0, 0)
    Local $iTotal1 = ((Int($aSplit1[1]) * 3600) + (Int($aSplit1[2]) * 60) + (Int($aSplit1[3])))
    Local $iTotal2 = ((Int($aSplit2[1]) * 3600) + (Int($aSplit2[2]) * 60) + (Int($aSplit2[3])))
    If $iAdd Then
        $iSubTotal = $iTotal1 + $iTotal2
    ElseIf $iTotal1 >= $iTotal2 Then
        $iSubTotal = $iTotal1 - $iTotal2
    Else
        $iSubTotal = $iTotal2 - $iTotal1
    EndIf
    Local $iHour = Int(($iSubTotal / 3600))
    Local $iMin = Int(($iSubTotal - ($iHour * 3600)) / 60)
    Local $iSec = Int(($iSubTotal - $iHour * 3600) - ($iMin * 60))
    Return StringFormat('%02d', $iHour) & $sDelim & StringFormat('%02d', $iMin) & $sDelim & StringFormat('%02d', $iSec)
EndFunc

Edit:

Added _TimerStartDiff() so you could see what it was doing a bit better (I hope).

Edited by SmOke_N

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

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