CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Time elapsed

  1. #1
    Join Date
    Mar 1999
    Posts
    37

    Time elapsed



    Anyone know how I can get the time elapsed of a application? I wanna know how long something took to run. I tried:


    Dim time1, time2, TimeElapsed

    time1 = time$

    'Application runs here

    time2 = time$

    TimeElapsed = (time2-time1)


    Any idea why its not working, and now I can get it to work? thanks

  2. #2
    Join Date
    Nov 1998
    Posts
    9

    Re: Time elapsed



    Use the GetTickCount API ... the declarations you need can be found in the API Viewer. It can be used like this.


    Dim time1%,time2%,elapsed%

    time1 = GetTickCount()

    'whatever process you are timing

    time2 = GetTickCount()

    elasped = time2-time1

    'elapsed will be the number of milliseconds that have elapsed

    'GetTickCount rolls over every 49 days of continuous system operation so if 'time1 is greater than time2, you have to make the necessary adjustment


    Gordito

  3. #3
    Join Date
    Apr 1999
    Posts
    16

    Re: Time elapsed



    Alex:


    You have several issues with this code:

    1. Always type your variables (Dim time1 As Date), otherwise they are variants (really slow).

    2. Putting a $ returns a string, your untyped time1 will now hold the string.

    3. You then try subtracting strings



    Try this:



    Dim x As Date

    Dim y As Date



    x = Now

    '' App runs here

    y = Now



    Call MsgBox(DateDiff("s", x, y) & " seconds have passed.", vbInformation)




    Tested in VB5.


    -Jim

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

Featured