Top
PowerCOBOL V11.0 User's Guide
FUJITSU Software

11.3 Developing the Initial Clock Control

The initial clock control that you are going will be a simple numeric display of the current hours, minutes and seconds on a small form.

You will make use of a PowerCOBOL timer control, which will repeatedly generate an event at a given interval based upon how often you specify to generate the event.

The timer control is an example of a useful feature not found in traditional COBOL. In order to implement a ticking clock, your COBOL program needs to constantly check the system time and move it to the clock's display. About the only way to write such an application in traditional COBOL would be to code an infinitely running loop that accepts the current time and moves it to the clock's display.

This would be a very inefficient program and would attempt to drag down system resources by having an infinite loop in it. Instead, we need some way to put our application to sleep to release resources back to the operating system, but to have the operating system wake it back up less than each second so it can update the time.

A timer control provides a perfect solution to this need. It is one of the simplest of all controls. It contains only two properties that you will typically use. One of these properties is named Interval, which sets how often the timer will wake the application up in milliseconds. The second property is named Active and when true, the timer is active and will wake the application up at the set Interval. When inactive, the timer is not functioning. This allows us to turn the timer on and off when needed.

Because we want the clock to run (tick) constantly, we will make the timer active from the moment the application starts. You will want to generate this event much faster than at one second intervals to ensure that the application is given control and has time to query the system time and update it in the display before the next second occurs. This means we want to set the Interval property to a value less than one full second in length.

The timer control actually wakes our application up by generating an event, and we simply code an event procedure for this timer event to update the clock. It thus becomes a very simple and straightforward application.