+ Reply to Thread
Results 1 to 6 of 6

if statement with timevalue? Tracking Time.

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    8

    if statement with timevalue? Tracking Time.

    I am looking for a way to include code that will update the passage of time while a program is running.

    With the code below I can note how many 2 second increaments of time have past with the value of X.
    What I would like to know is if there is a way to do this with a IF Statement instead of a DO UNTIL?

    Dim Timer As Double
    Dim X As Integer
    X = 0
    Again:
    Timer = Now()
    Do Until Now() - Timer > TimeValue("00:00:02")
    Loop
    X = X + 1
    End Sub

    Thank You.
    WhyWhy

  2. #2
    Registered User
    Join Date
    10-01-2012
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: if statement with timevalue? Tracking Time.

    I can not figure out why this produces a RunTime Error '6':

    Dim Timer As Double
    Dim n1 As Integer

    n1 = 0

    Again:
    Timer = Now()
    Do
    n1 = n1 + 1

    Loop Until Now() - Timer > TimeValue("00:00:02")

    'line is for printing the number of times the loop cycled during 2 seconds
    Range("B6") = n1

  3. #3
    Registered User
    Join Date
    10-01-2012
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: if statement with timevalue? Tracking Time.

    I was able to figure it out with the code below.
    Now I'm searching for a way to display the time value with Milliseconds?

    Dim Timer As Double
    Dim n1 As Long
    n1 = 0

    Again:
    Timer = Now()
    Do
    n1 = n1 + 1
    Range("B6") = n1 'Displays current count in Cell
    If n1 > 1000000 Then
    Range("B9") = Now() - Timer 'Displays How Long the code ran in Cell
    GoTo Endd
    Else
    End If
    Loop
    Endd:
    End Sub

  4. #4
    Forum Contributor
    Join Date
    10-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: if statement with timevalue? Tracking Time.

    Hello WhyWhy,

    Try following code:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-01-2012
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: if statement with timevalue? Tracking Time.

    That is neat. I am working with your sample code now to become more familiar with as many ways as possible to compute the passage of time.

    Thank you
    WhyWhy

  6. #6
    Forum Contributor
    Join Date
    10-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: if statement with timevalue? Tracking Time.

    Please do not forget to mark the thread as SOLVED if you find it proper!

    Thanks,
    Tejas

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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