Results 1 to 6 of 6

Thread: How to keep a running total of elapsed time in fits and starts.

  1. #1

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    How to keep a running total of elapsed time in fits and starts.

    The problem with the Timer control is that it's super-not-accurate. Especially in the code I'm writing which is basically Do Sleep Loop machine.

    So when the user starts the thing for the first time then the programs saves that as StartTime.

    Right now I'm just making a comparison between Now() and StartTime.

    But... the user can pause the thing any time they want for as long as they want.

    All I really want to save is the accumulated time that it's running. Again, I can't use a Timer set to say, 1000, for example and throw 1000 ms onto the pile of elapsed ms because the value will be very wrong if I do that.

    I also don't want to go the route of using some kind of precision timer (which I think won't defeat my sleep-loops anyway).

    I just need to figure out an algorithm that knows when the thing was paused, when it was restarted and adds that maybe to a value to subtract from Now() - StartTime?

    I don't know. All I know is that date/time stuff give me fits anyway and this just makes it even worse.

  2. #2
    Lively Member
    Join Date
    Nov 2020
    Posts
    72

    Re: How to keep a running total of elapsed time in fits and starts.

    It sounds like there is some kind of action when the user pauses and restarts. I assume there is a button / click event for this. I feel like something that functions like a punch clock would fit. If you are using a database for things already you can add a table with a few columns. One being a date time, one for an action, and an auto increment id . When the user starts you can add a row with the current time and the action "Start". When they pause or stop you can add the current time and the action "Stop". Then when you want to see total time you can just total up all the differences between start and stop times.

  3. #3
    Fanatic Member
    Join Date
    Mar 2019
    Posts
    518

    Re: How to keep a running total of elapsed time in fits and starts.

    How is your pause implemented? You could do something that looks paused but is actually just keeping track of the time or the pause time. How accurate must it be?

  4. #4

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    Re: How to keep a running total of elapsed time in fits and starts.

    Quote Originally Posted by DrBobby View Post
    It sounds like there is some kind of action when the user pauses and restarts. I assume there is a button / click event for this. I feel like something that functions like a punch clock would fit. If you are using a database for things already you can add a table with a few columns. One being a date time, one for an action, and an auto increment id . When the user starts you can add a row with the current time and the action "Start". When they pause or stop you can add the current time and the action "Stop". Then when you want to see total time you can just total up all the differences between start and stop times.

    I thought I replied but it didn't take or I clicked the wrong thing so trying again....

    This is what I think would work except the way I'm doing the date-math is wrong. It's just concept air-code. And I don't want a date anyway. I want elapsed time. But something like this so it does time, not date. Probably a Double data type or something. I'd have to play around with it and ask my friends at the googles how to convert milliseconds into years, months, days, hours, etc... I meant there's got to be an easier way than doing MOD over and over again. Or maybe not. I really don't like date math.


    Code:
    Option Explicit
    
    Private fPaused As Boolean
    Private dSavedElapsedTime As Date
    Private dStartTime As Date
    
    
    Public Property Get ElapsedTime() As Date
    
    if fPaused then
    
      ElapsedTime = SavedElapsedTime
    
    else
    
      ElapsedTime = SavedElapsedTime + (Now() - StartTime)
    
    end if
    
    End Property
    Public Sub Pause()
    
    fPaused = Not fPaused
    
    If fPaused Then
    
      SavedElapsedTime = SavedElapsedTime + (Now() - StartTime)
    
    Else
    
      StartTime = Now
    
    End If
    
    End Sub
    Public Property Get SavedElapsedTime() As Date
    
    SavedElapsedTime = dSavedElapsedTime
    
    End Property
    Private Property Let SavedElapsedTime(ByRef ElapsedTime As Date)
    
    dSavedElapsedTime = ElapsedTime
    
    End Property
    Public Property Get StartTime() As Date
    
    StartTime = dStartTime
    
    End Property
    Public Property Let StartTime(ByRef TimeStarted As Date)
    
    dStartTime = TimeStarted
    
    End Property
    Last edited by cafeenman; May 18th, 2024 at 07:00 AM.

  5. #5

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    Re: How to keep a running total of elapsed time in fits and starts.

    Quote Originally Posted by vbwins View Post
    How is your pause implemented? You could do something that looks paused but is actually just keeping track of the time or the pause time. How accurate must it be?
    It just stops game-execution. There's nothing else going on. The pause could be two seconds or two weeks or whatever. It doesn't have to be super accurate. I just don't want it to be wildly off.

    You know... you're running the game but your wife is forcing you to take a couple weeks vacationing in the Bahamas. But you don't want to miss a thing so you pause the game that your started this morning.

    When you come home, I don't want the game to tell you it's been running for two weeks when it was really only running a few hours and then paused for two weeks.

  6. #6

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    Re: How to keep a running total of elapsed time in fits and starts.

    This is where I'm at with it. It's actually been running 24 hours and 11 minutes or something. I need to fix the label at the bottom with the elapsed time to make it move over. All the other labels do that automatically when their values change but I missed this one.

    Not on the point but the "points" in the game are color-tiered with rarity. So the farthest right (black) is Diamond which is 1/4000 probability. Second from the right is Ruby with 1/2000 probability. White is 100% (if you roll to get something you get at least white). Green is 40% I think so 60% chance of getting white and 40% chance of getting anything else.

    If you hover over the color swatches it will tell you how many plus/minus instances of each color you got. If you click it, it will tell you how many plus/minus instances you got per attribute.

    http://www.airfieldmodels.com/other/..._simulator.jpg
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width