Timer Function like VB6

Is there some code or similar around that mimics the VB6 Timer function?

I googled it quite a bit but could not find much on it.

Thanks,

Tom

The Timer Object? Under Controllers in the Object Library

Drag it to your window, set the properties…

or are you looking for something different?

Dave beat me to it. What’s the difference, if any, from the Xojo Timer?

No Dave not that…

http://msdn.microsoft.com/en-us/library/office/gg264416(v=office.15).aspx

Actually Tom… yes that… only XOJO implements it as an object… VB as a class function.

Any suggestions for getting something similar on xojo?

Look at the Microseconds or Ticks functions.

Dim PauseTime, Start, Finish, TotalTime
If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
    timer1.period = 5*1000   ' Set duration.
    timer1.mode=timer.modesingle    ' Set start time.
 //
// below goes in the ACTION event of the timer
 //   Finish = Timer    ' Set end time.
//    TotalTime = Finish - Start    ' Calculate total time.
 //   MsgBox "Paused for " & TotalTime & " seconds"
Else
    End
End If

Oh, if you’re looking for something similar to the example given on that page, use Dave’s suggestion.

[quote=90813:@Tom Russell]Is there some code or similar around that mimics the VB6 Timer function?

[/quote]

Here is a method called Timr that works exactly like VB Timer : it returns an integer representing the number of seconds elapsed since midnight.

Function Timr() As integer dim d as new date return (d.Hour*3600)+(d.Minute*60)+d.Second End Function

You can use it to adapt VB code to Xojo. It cannot be called “Timer”, because the word is reserved for the Xojo Timer.

[quote=90997:@Michel Bujardet]Here is a method called Timr that works exactly like VB Timer : it returns an integer representing the number of seconds elapsed since midnight.

Function Timr() As integer dim d as new date return (d.Hour*3600)+(d.Minute*60)+d.Second End Function

You can use it to adapt VB code to Xojo. It cannot be called “Timer”, because the word is reserved for the Xojo Timer.[/quote]

Thanks for the code example.

Out of curiosity, the VB Timer function will show time like 40795.14. I am not sure what the .14 is but is this possible to duplicate in xojo as well?

thanks.

This version uses functions with a precision of one second.

If you need more precision, you want to look the Microseconds function http://documentation.xojo.com/index.php/Microseconds

I started out using microseconds to only find it not to be like the timer function. I am kind of lost on how I would use it with the function you have here though?

Thanks.

In “40795.14” you have the number of seconds, and 14/100th of a second.

1 second is 1,000,000 microseconds.

If you want to obtain this on top of the timer function I posted, turn Microseconds into a string with variable = str(Microseconds), and the millionth of a second are in right(variable,6), which can be converted to a number by val(string) and added to return (d.Hour*3600)+(d.Minute*60)+d.Second

You can set precisions less than 1/1000000 a second by cutting the right string again with left().

This is becoming convoluted I think. I tried this but seems the number is overly huge now.

Basically I am just needing to calculate the time it takes to do something using 100th of second. I think trying to implement what VB6 does is not the right solution with xojo as its probably less code than what I am doing now to do the same literally.

Thanks.

Measuring time in 100th of a second is different.

Use Microseconds/10000

  • Initialize a variable with Microseconds/10000 let us call it Start
  • do whatever you need to measure
  • Execution time in 100th a second is Microseconds/10000-Start

You see, your question should have been more to the point : “How do I measure execution time” instead of asking for Timer. It would have saved some … time :wink:

Got it.

Ok, sorry this is confusing on my part.

I understand what you are saying with the above example. I misstated what I am trying to get as a result.

I am calculating the elapsed time from a start to a stop. The result I am looking for though is something like 0.598. To the left of the decimal is the second(s) and to the right of it would be the 100th or 1000th of a second. The results I get with your example is something like 44.55967. So I guess I am trying to get the time elapsed but in a bit different format?

[quote=91912:@Tom Russell]Got it.

Ok, sorry this is confusing on my part.

I understand what you are saying with the above example. I misstated what I am trying to get as a result.

I am calculating the elapsed time from a start to a stop. The result I am looking for though is something like 0.598. To the left of the decimal is the second(s) and to the right of it would be the 100th or 1000th of a second. The results I get with your example is something like 44.55967. So I guess I am trying to get the time elapsed but in a bit different format?[/quote]

If you want the elapsed time in seconds, go Microseconds/1000000.

Use straight microseconds to measure and then divide it out when you’re done, using Format to, well, format the result for display.

dim msec as double
msec = Microseconds
// do the stuff
msec = Microseconds - msec
msgbox "It took " + Format(msec/1000000, "#.##") + " seconds."