+ Reply to Thread
Results 1 to 10 of 10

How to use time to increment a value

  1. #1
    Registered User
    Join Date
    05-04-2020
    Location
    Leeds, UK
    MS-Off Ver
    2017
    Posts
    51

    How to use time to increment a value

    I have no idea if this is possible or not, but here's the idea:

    1. I have a sheet that generates a list of random numbers (scores) for a pretend video gamer (aka, vPlayer)
    2. One of those scores is plucked out for a particular game
    3. That's the easy bit
    4. Now what I'd like is to have it 'increment' close to how a real game would be, for example: if the score it chooses is 500,000, it would start at 0, then after ~20 seconds it would be around 30,000, ~40 seconds 60,000, ~1 minute 90,000, etc etc
    5. This incremented score would be displayed on a separate sheet, corresponding with the time that has passed in the real world [edited for clarity]
    6. Once it reaches the chosen score, it stops incrementing (and maybe changes color)

    Is that something Excel/Sheets can do? I've looked up some time functions, but I don't see anything that matches what I'm after.

    (No sheet attached, as there isn't really anything to offer, other than a short list of numbers that it would choose from.)

    Thanks in advance! You guys are AWESOME.
    Last edited by rubsley; 01-11-2021 at 05:23 PM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,810

    Re: How to use time to increment a value

    This seems quite possible to me. Here's how I might do it:

    1-3) You seem to already know how to extract your desired random total score. Let's say it gets stored in D1.
    4) Assume we store elapsed times in column A, so enter 0 into A1. Assuming we don't want to use Excel's date/time serial number (and sexagesimal display options), we'll just have column A track seconds. A2 can then be =A1+20, and copy down.
    5) For tracking the score, we can enter 0 in B1 (assuming our game simulation will start at a score of 0), then add an appropriate increment each time. Each increment will check the total in D1 and make sure it is not exceeded. This might look like =MIN($D$1,B1+desried increment) in B2 and copied down.

    you will need some idea of what your longest possible simulation would need to be so you know how far down to copy the formulas in A and B. This approach will have column B increase until it reaches the maximum score, then repeat that number for the rest of column B.

    Will something like that work?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    05-04-2020
    Location
    Leeds, UK
    MS-Off Ver
    2017
    Posts
    51

    Re: How to use time to increment a value

    Hi MrShorty, that sounds perfect. Thanks for understanding.

    I guess the question is, where do the time functions come in? For example, let's say 3 minutes have elapsed and it's reached B10, how will Excel know that's the value to deliver?

    (I imagine it will be something like this: all the mechanics are happening on one sheet, and on another is simply the current score x seconds since pressing "start".)

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,810

    Re: How to use time to increment a value

    I don't understand what you are asking. When 160 seconds (20 seconds short of 3 minutes) the score will be whatever it has calculated up to. In the next row, the time will increment up to 180 seconds and the score will increment as well. If the result exceeds the maximum, then it returns the max score.

    Are you asking how Excel might return the score corresponding to 3 minutes/180 seconds? That should be a simple lookup function (like VLOOKUP()) =VLOOKUP(180,$A$1:$B$100,2,TRUE). Is that what you are asking?

  5. #5
    Registered User
    Join Date
    05-04-2020
    Location
    Leeds, UK
    MS-Off Ver
    2017
    Posts
    51

    Re: How to use time to increment a value

    Ah, maybe I need to clarify the top post: it's not finding the value that's the tricky bit, it's involving "real time" that I wonder is possible.

    For example, let's say I'm on the frontend sheet and I press Enter on the cell that "starts" the calculating. After 30 seconds in another cell I see the value in column B that equates to thirty seconds. Now after another thirty seconds it changes to the value in column B that equates to one minute.

    So it keeps changing as "real world" time passes.

    I was thinking maybe something to do with RAND() or NOW() - or something similar - would get involved.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,810

    Re: How to use time to increment a value

    It's not clear to me how you are "starting" the calculation or triggering "updates" to the calculation. However, if your "start" trigger will put a time stamp in a cell (see here for one idea for generating time stamps: https://chandoo.org/wp/timestamps-excel-formula-help/ ), then a formula like =VLOOKUP(CONVERT(NOW()-time stamp,"day","sec"),A1:B100,2,TRUE) will update the score for every change/calculate event.

    Using something like the timestamp formula from chandoo, I might:

    1) Enter the timestamp formula in B3 as shown in chandoo's tutorial. My "start" trigger will be entering a formula in C3.
    2) When I want to start, I will enter =VLOOKUP(CONVERT(NOW()-B3,"day","sec"),A1:B100,2,TRUE) into C3.
    3) When I want to update the score, I can trigger a calculate event by pressing F9. By repeatedly pressing F9, I can watch the score increase until it stops at the maximum. Note that, if my lookup table has entries every 20 seconds, then C3 will not change until after 20 or more seconds passes. We are far from exhausting the programming possibilities here, it all depends on exactly how we want to do the "score at time t" calculation and how we want to execute the "update score" event trigger.
    4) When we are done, simply clear C3. B3 will also go blank and wait until we re enter the formula in C3.

    Are we getting closer?

  7. #7
    Registered User
    Join Date
    05-04-2020
    Location
    Leeds, UK
    MS-Off Ver
    2017
    Posts
    51

    Re: How to use time to increment a value

    Wow, that's awesome! Just having a play with it now: everything seems to be working great.

    Only thing is, I need it to work without the manual F9 updating. Maybe that's an obstacle?

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,810

    Re: How to use time to increment a value

    It's only an obstacle if you cannot use VBA macros as part of this project. If you can use VBA, then you can program a procedure that trigger a calculate event to run at fixed intervals using the OnTime event. This discusses the use of OnTime: https://www.dummies.com/software/mic...xcel-2016-vba/

  9. #9
    Registered User
    Join Date
    05-04-2020
    Location
    Leeds, UK
    MS-Off Ver
    2017
    Posts
    51

    Re: How to use time to increment a value

    Thanks again for all your help. I have it pretty much doing what I want it to do, though because of how I want to share it with people I put it in Google Sheets, which doesn't have the UpdateClock or NextTick feature, so it's only doing 60 second updates (or press Backspace in an empty cell for every 10 seconds; works the same as F9 but easier to hit in the middle of a game).

    Here's the sheet if you want to take a look:

    https://docs.google.com/spreadsheets...5e-KYGgOi1peJw

    Your way of freezing the NOW() time was incredibly useful - I did the same for RAND() in a few places also.

    Thanks again for all your help!
    Last edited by rubsley; 01-13-2021 at 05:16 PM.

  10. #10
    Registered User
    Join Date
    05-04-2020
    Location
    Leeds, UK
    MS-Off Ver
    2017
    Posts
    51

    Re: How to use time to increment a value

    Using a trick to get it updating up to every 3 or 4 seconds, which is plenty enough for my purpose: I use IMPORTRANGE to import a RAND() from a different spreadsheet, and that spreadsheet in turn imports a RAND() from my main one. This seems to force each one to update each time the import is done, ping ponging back and forth from one another.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to get 2 loops to increment at the same time?
    By badicus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2015, 05:39 PM
  2. increment one row at a time with cmd button
    By NoWhereMan2012 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2012, 06:22 AM
  3. Need to Increment Date and Set Time
    By jimmy37 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-25-2011, 02:42 PM
  4. Add a time increment when a condition is met.
    By RunHard in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-19-2009, 06:52 AM
  5. Increment formula for time
    By Ltat42a in forum Excel General
    Replies: 4
    Last Post: 08-02-2006, 06:21 PM
  6. An uneven time-increment
    By smurray444 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-08-2006, 01:15 AM
  7. Rounding Time Intervals to the Nearest Specified Time Increment
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 08-23-2005, 12:21 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1