You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Extended Timer
07-06-2014, 02:35 PM (This post was last modified: 07-06-2014 03:56 PM by Waltersmind.)
Post: #1
 (Print Post)
Extended Timer
Code Snippet: [Select]
uptime&& = ExtendedTimer

DO
    _LIMIT 60
    x&& = ExtendedTimer
    ut&& = INT(ExtendedTimer - uptime&&)
    ms = ut&& MOD 100: ut&& = ut&& \ 100
    d = ut&& \ 86400
    h = (ut&& - d * 86400) \ 3600
    m = (ut&& - d * 86400 - h * 3600) \ 60
    s = ut&& - d * 86400 - h * 3600 - m * 60
    t$ = "00:00:00:00.00"
    IF d > 0 THEN
        MID$(t$, 3 - LEN(LTRIM$(STR$(d)))) = LTRIM$(STR$(d))
        MID$(t$, 6 - LEN(LTRIM$(STR$(h)))) = LTRIM$(STR$(h))
        MID$(t$, 9 - LEN(LTRIM$(STR$(m)))) = LTRIM$(STR$(m))
        MID$(t$, 12 - LEN(LTRIM$(STR$(s)))) = LTRIM$(STR$(s))
        MID$(t$, 15 - LEN(LTRIM$(STR$(ms)))) = LTRIM$(STR$(ms))
    ELSE
        t$ = RIGHT$(t$, 11)
        IF h > 0 THEN
            MID$(t$, 3 - LEN(LTRIM$(STR$(h)))) = LTRIM$(STR$(h))
            MID$(t$, 6 - LEN(LTRIM$(STR$(m)))) = LTRIM$(STR$(m))
            MID$(t$, 9 - LEN(LTRIM$(STR$(s)))) = LTRIM$(STR$(s))
            MID$(t$, 12 - LEN(LTRIM$(STR$(ms)))) = LTRIM$(STR$(ms))
        ELSE
            t$ = RIGHT$(t$, 8)
            IF m > 0 THEN
                MID$(t$, 3 - LEN(LTRIM$(STR$(m)))) = LTRIM$(STR$(m))
                MID$(t$, 6 - LEN(LTRIM$(STR$(s)))) = LTRIM$(STR$(s))
                MID$(t$, 9 - LEN(LTRIM$(STR$(ms)))) = LTRIM$(STR$(ms))
            ELSE
                t$ = RIGHT$(t$, 5)
                MID$(t$, 3 - LEN(LTRIM$(STR$(s)))) = LTRIM$(STR$(s))
                MID$(t$, 6 - LEN(LTRIM$(STR$(ms)))) = LTRIM$(STR$(ms))
            END IF
        END IF
    END IF
    LOCATE 1, 1
    PRINT "Current Timer =>"; x&&
    PRINT "Starting Timer=>"; uptime&&
    PRINT "Elapsed Time  =>"; t$; "             "
LOOP

FUNCTION ExtendedTimer~&& 'Timestamp gives us a unsigned long which is our current time to the millisecond, AFTER 1/1/2013
d$ = DATE$ '           This will keep us from having to deal with "midnight wrap-around" when used to track elapsed times.
l = INSTR(d$, "-")
l1 = INSTR(l + 1, d$, "-")
m = VAL(LEFT$(d$, l))
d = VAL(MID$(d$, l + 1))
y = VAL(MID$(d$, l1 + 1)) - 2013
FOR i = 1 TO m
    SELECT CASE i 'Add the number of days for each previous month passed
        CASE 1: d = d 'January doestn't have any carry over days.
        CASE 2, 4, 6, 8, 9, 11: d = d + 31
        CASE 3: d = d + 28
        CASE 5, 7, 10, 12: d = d + 30
    END SELECT
NEXT
FOR i = 1 TO y '2013 is the starting time of this timestamp method.
    d = d + 365 'So for each year past 2013, we need to add in another 31 days for previous years that have passed
NEXT
FOR i = 3 TO y STEP 4
    IF m > 2 THEN d = d + 1 'add an extra day for leap year every 4 years, starting in 2016
NEXT
s~&& = d * 24 * 60 * 60 'Seconds are days * 24 hours * 60 minutes * 60 seconds
ExtendedTimer~&& = (s~&& + TIMER) * 100
END FUNCTION

A quick function to get an extended Timer for us that won't reset after midnight.  This routine can faithfully track time for YEARS and never reset itself.  Smile

SCREENSHOT ADDED BY ADMINISTRATOR:

   
Find all posts by this user
Like Post
The following 2 users Like SMcNeill's post:
rickus, Waltersmind (Admin)
07-06-2014, 03:57 PM
Post: #2
 (Print Post)
RE: Extended Timer
Steve,

The really cool feature is that it will work in Windows and Linux.

Great work!


Walter Whitman
The Joyful Programmer

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
05-10-2015, 12:44 PM
Post: #3
 (Print Post)
RE: Extended Timer
Ay Steve, I've been using your ExtendedTimer in my game for a while and it works great to time my multiple events. Thanks for this valuable routine.

Rick
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Basic Dithering
QB64 Member Project - 9 Board
QB64 Member Project - Qubic
QB64 Member Project - Connect Four
QB64 Member Project - Bowditch curve
QB64 Member Project - Dakapo
QB64 Member Project - Rubix's Magic
QB64 Member Project - Swirl
QB64 Member Project - Isolation
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Quarto
QB64 Member Project - Overboard
QB64 Member Project - Full Color LED Sign
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Sabotage
QB64 Member Project - Kings Court
QB64 Member Project - Exit
QB64 Member Project - Line Thickness
QB64 Member Project - Kings Vallery version two
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Splatter
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Rotating Background
QB64 Member Project - Pivot version two
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Spiro Roses
QB64 Member Project - Algeria Weather
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Input
QB64 Member Project - Color Rotating Text
QB64 Member Project - Dreamy Clock
QB64 Member Project - Score 4
QB64 Member Project - Foursight
QB64 Member Project - Martin Fractals version one
QB64 Member Project - ARB Checkers
QB64 Member Project - Pivet version one
QB64 Member Project - Color Triangles
QB64 Member Project - Amazon
QB64 Member Project - Point Blank
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Blokus
QB64 Member Project - Inside Moves
QB64 Member Project - Touche
QB64 Member Project - Domain
QB64 Member Project - Othello