Jump to content

Timers - to display in minutes and seconds


Recommended Posts

Hi all,

So after reading a few threads on timers, I haven't been able to do what I want to do.

So in this example, the time to finish is calculated based on the initial desired value ($dollarmax) and the accumulative ($dollar) to determine how much longer it has to go until $dollar = $dollarmax

It seems to work ok - but the tooltip displays the value in milliseconds.

I've tried dividing all the variables by 1000 to get seconds, but that didn't work.

Ideally, I would like the tooltip to display minutes and seconds remaining.

This will insert into my larger code and will be updated after each change in $dollar.

Thanks for your help. 

#include <Timers.au3>
HotKeySet("{ESC}", "_Quit")
Example()

Func Example()

   $dollarmax= 100000
   $dollar = 0
    Local $starttime = _Timer_Init()
    While 1
      $dollar = $dollar + 10
      $Totaltime= $dollarmax / $dollar * $starttime
      $time2go = ($totaltime - $starttime)
      $time2gom = $time2go ;tired various /1000/60 here etc
      tooltip($time2gom)
      sleep(10000)

    WEnd
EndFunc   ;==>Example

Func _Quit()
    Exit
EndFunc   ;==>_Quit
Link to comment
Share on other sites

  • Moderators

MrCheese,

Doing any kind of manipulation of timer timestamps ususally ends in tears - the returned value from an Init function should only ever be used as the parameter for the corresponding Diff function. The Help file page for TimerInit makes this quite clear and as far as I know it applies to the UDF equivalent as well. ;)

Given the number of countdown timer threads on the forum, I am surprised that you have not been able to find a suitable version to use. Here is one I have used in the past:

#include <Date.au3>

HotKeySet("{ESC}", "_Quit")

Example()

Func Example()

   $iDollarMax = 140 ; Units are seconds
   ; Determine end time
   $sEnd = _DateAdd("s", $iDollarMax, _NowCalc())
   ; Store current second
   $iSec = @SEC

    While 1
        ; Wait until second changes
        Do
            Sleep(10)
        Until $iSec <> @SEC
        ; Store new second
        $iSec = @SEC
        ; Calculate time difference
        $iTime2GoSec = _DateDiff("s", _NowCalc(), $sEnd)
        ; Convert to Min and Sec
        $iTime2GoMin = Int($iTime2GoSec / 60)
        $iTime2GoSec = Mod($iTime2GoSec, 60)
        ; Display result - adding padding 0 to Sec if required
        ToolTip($iTime2GoMin & ":" & StringFormat("%02i", $iTime2GoSec))

    WEnd

EndFunc   ;==>Example

Func _Quit()
    Exit
EndFunc   ;==>_Quit
I hope that it does what you want - please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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