Results 1 to 5 of 5

Thread: timing operations

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    19

    timing operations

    So here I am trying to time a form's load and I'm not quite sure how to go about it.
    In vb6 I'd do this:

    dim start as double
    dim lapsed as double

    start = timer
    lapsed = timer - start

    and it actually worked for a console application in .net but not when I've tried it in a form. I've looked at the Timer property in MSDN and it doesn't specify what context the example its used in.
    Any ideas?

  2. #2
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    Try this

    VB Code:
    1. dim intStartTime as int32
    2. dim intEndTime as int32
    3. dim dblElapseTime as Double
    4. dim strTime as String
    5.  
    6. intStartTime = System.Environment.TickCount
    7. ...
    8. intEndTime = System.Environment.TickCount
    9. dblElapseTime = (mintEndTime – mintStartTime) / 1000
    10. strTime = dblElapseTime.Tostring & " Seconds"

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    19
    Thank you.
    It works well.

  4. #4
    New Member
    Join Date
    Jan 2003
    Posts
    15
    I believe this is the method you are after:

    VB Code:
    1. Dim Start As Double = DateAndTime.Timer()
    2.  
    3.         Code…
    4.  
    5.         Dim Finish As Double = DateAndTime.Timer()
    6.         Me.Text = CStr(Start & " : " & Finish & " :: " & Finish - Start)

  5. #5
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Try this:
    VB Code:
    1. Dim TimeNow As New DateTime()
    2.  
    3. TimeNow = Now
    4. Now.Subtract(TimeNow).TotalSeconds ' This is the elapsed time

    There are also other properties:
    .TotalDays
    .TotalHours
    .TotalMinutes
    .TotalSeconds <---- the one I used in the above example
    .TotalMilliseconds
    They all convert the value of the time from ticks to their respective units. They have whole and fractional part.
    Learn, this is the Keyword...

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