Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Sep 15, 2019 11:06 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Adding a time-elapsed indicator.
PostPosted: Wed Jan 13, 2010 5:27 pm 
Offline

Joined: Sat Dec 30, 2006 6:52 pm
Posts: 130
Location: New York City
I want to add a field that will display the time in minutes/seconds that has elapsed once I've started my program. Can anyone supply the code please?


Top
 Profile  
Reply with quote  
 Post subject: Re: Adding a time-elapsed indicator.
PostPosted: Wed Jan 13, 2010 5:33 pm 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
Look in the Language reference for the entry on Ticks

Add a timer to your window, set to mode 2 (repeat)
Every time the timer fires, use the example code from the LR to display the time on your window , probably in a static text.


Top
 Profile  
Reply with quote  
 Post subject: Re: Adding a time-elapsed indicator.
PostPosted: Thu Jan 14, 2010 7:35 am 
Offline
User avatar

Joined: Fri Jun 05, 2009 11:50 am
Posts: 348
Location: Hamburg, Germany
jeffs tipp is good, but be aware, that ticks returns the computer uptime. To make this into the uptime of your app you need to do the following:

first you need to add a new property to your app

e.g begin as integer

in the open event of your app, you set begin to the current ticks

Sub Open()
begin=ticks
End Sub


Add a timer to your window, set to mode 2 (repeat), period 1000

add a statictext to your window

In the action event of the timer you place the following code
Sub Action()
dim totalseconds as integer
dim totalminutes as integer
dim totalhours as integer


totalseconds = ((ticks-app.begin) / 60) mod 60
totalminutes = ((ticks-app.begin) / 3600) mod 60
totalhours = ((ticks-app.begin) / 216000)


self.StaticText1.text= "Uptime: " +str(totalhours) + " hrs " + str(totalminutes) + " min " + str(totalseconds) + " sec"

End Sub

_________________
Best regards

Stefan

Mac OSX Mountain Lion (latest Release) on a MacBook Pro 2.66 GHz Intel Core i7/ RB Professional 2011 Release 3


Top
 Profile  
Reply with quote  
 Post subject: Re: Adding a time-elapsed indicator.
PostPosted: Thu Jan 14, 2010 8:52 am 
Offline

Joined: Sat Dec 30, 2006 6:52 pm
Posts: 130
Location: New York City
Thanks Jeff & Stefan. I put your suggestions to work and got what I was looking for. Great help!

One more thing though... could I add a start/stop button to control the timer?
When I bring up my program's window I may not want to set the timer in motion until a bit later, when I am actually doing what I want the timer to indicate.


Top
 Profile  
Reply with quote  
 Post subject: Re: Adding a time-elapsed indicator.
PostPosted: Thu Jan 14, 2010 9:23 am 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
Now you're into sums.

Instead of (ticks - begin) , you need to accumulate the number of ticks.

Put the suggested code from the Open event into the Start button action event.
In the Stop button event, add (ticks-begin) to the current value of a new variable sumofticks

The timer control event should then use sumofticks instead of (ticks - begin)


Top
 Profile  
Reply with quote  
 Post subject: Re: Adding a time-elapsed indicator.
PostPosted: Thu Jan 14, 2010 10:14 am 
Offline

Joined: Fri Jan 23, 2009 9:18 am
Posts: 104
Location: Summerfield, Florida
If you only need accuracy to the second you could use a date object.

In the action event of the start timer button put

Dim startTime as new Date

Then use the timer as shown above and in the action event place
dim currentTime as new date
statictext1.text = Str(currentTime.totalseconds - startTime.totalSeconds)


Jim


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group