Jeff,
I’ve come up with a couple of ways of doing this, depending on whether you want to display more than 23 hours.
You’re right in thinking you have to bind a label to the value of the timer. However, this will only give you the number of seconds. To display it in time format you will need to bind label.text to an expression.
First off you need to configure a timer. The fields should be set as follows:
Delay: 1000
Initial delay: 1000
Running: tied to the trigger, a point that will be true when you want to time and false when you don’t
Step by: 1, if you want your time to increment every second
Bound: the maximum value the timer can reach e.g. 86,400 for 24 hours
The following code works if you want to display less than 24 hours i.e. up to 23:59:59:
dateFormat(dateArithmetic(toDate("2008-01-01 00:00:00"),{Root Container.Timer.value},"second"),"H:mm:ss")This code adds the number of seconds from the timer to an arbitrary date (we ignore the date part anyway), then display only the time part on-screen.
The following code works if you want to display more than 24 hours:
[code]numberFormat(toInteger({Root Container.Timer.value}/3600),“00”)
- “:”
- numberFormat(toInteger(({Root Container.Timer.value}%3600)/60),“00”)
- “:”
- numberFormat({Root Container.Timer.value}%60,“00”)
[/code]Remember that in this case you’ll have to set the Timer.Bound field to a suitable maximum value.
This still leaves you with the problem of when to reset the timer. The way I achieved this was by creating a new Dynamic property called ‘Trigger’ on the label, binding its value to the actual trigger point, then adding the following code to the label propertyChange event:
if event.propertyName == 'Trigger':
if event.newValue == 1:
event.source.parent.getComponent('Timer').value = 0
This resets the timer value every time the trigger goes true.
Also remember that this will only work while the window containing the timer is open. It would be best to put the timer on a window that is never closed, like a common buttonbar.
Let me know if you need any more help.
Al