+ Reply to Thread
Results 1 to 5 of 5

Get code runtimes via GetTickCount and format it in specific ways

  1. #1
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Get code runtimes via GetTickCount and format it in specific ways

    I'm trying to make VBA's GetTickCount work so that I can see the runtime of code, but it doesn't have to be super accurate.

    The following bit of code works good but I need a few changes and can't work out how to achieve this.

    Please Login or Register  to view this content.
    I want the runtime to be presented in the following ways.
    • If runtime under 1 second it should be presented in milliseconds. Example: 180 milliseconds
    • If runtime under 1 minute but more than 1 second it should be presented in seconds (no milliseconds). Example: 30 seconds
    • If runtime OVER 1 minute but less than 1 hour it should be presented in minute second. Example: 1 minute, 30 seconds
    • If runtime OVER 1 hour it should be presented in hours, minutes and second Example: 2 hours, 1 minute, 30 seconds

    How would I achieve this, any help would be much appreciated.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Get code runtimes via GetTickCount and format it in specific ways

    See this: http://www.excelforum.com/excel-prog...ml#post3977317

  3. #3
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Get code runtimes via GetTickCount and format it in specific ways

    Hey Kenneth, I don't see anything there that can help me with the runtime being converted into easy to read presets like I explained.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Get code runtimes via GetTickCount and format it in specific ways

    Right, just use that and then convert the result as needed. Since it returns time in milliseconds, do some math on it to get it in the format you want. Select Case will likely be the best route since you want various formats for various scenarios.

    Conversion factors would be:
    1 ms / 0.001 s or 1000 ms / 1 s
    60 s / 1 minute
    60 minutes / 1 hour
    24 hours / 1 day

    If it were me, I would just use TimeSerial() and then Format() for all but the first case. Format() can handle h, m, s but not ms.
    Last edited by Kenneth Hobson; 03-16-2015 at 11:33 AM.

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Get code runtimes via GetTickCount and format it in specific ways

    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 05-24-2013, 06:02 AM
  2. Potential ways to format binary data with a pivot table.
    By Ali2013 in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 04-17-2013, 09:10 AM
  3. [SOLVED] Ways to make my code run faster
    By JazzyBear in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-03-2013, 03:59 PM
  4. WithEvents - same code run 2 ways: one causes crash
    By Deskmanbb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-29-2011, 03:40 PM
  5. What are the good ways to write VBA code,
    By malviya_anil77 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-24-2011, 03:03 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