You may create various applications such as stopwatches, appointment calendars, and action games that need to keep track of time. There are three component types to make this possible. You will use one or more of them depending on what you need:
Structures are types made from other types. The following structures are used to represent dates and times of day:
STRUCT TimeOfDay
DIM hour AS integer
DIM minute AS integer
DIM second AS integer
END STRUCT
STRUCT Date
DIM year AS integer
DIM months AS integer
DIM day AS integer
END STRUCT
The components that use these structures require that they represent valid times/dates. For example, if you tell an Alarm to set its alarm for 25:00, it raises an error.
Use a TimeDate component for utility actions when dealing with dates. The GetDaysInMonth() action is useful for validating dates. The GetDayOfWeek() action returns a number corresponding to the day of week for a date.
The CALENDAR.BAS sample application shows how you might use these utility actions to complete a simple calendar application.
A TimeDate component returns the system time whenever you ask; and that time will be accurate to the second. It lets you know when the system time changes, but the most often it does this is once a minute. If you wish to provide a clock that is accurate to the second, you need two components:
For an example of this, see the ACLOCK.BAS sample application. This application is a clock with a second hand, minute hand, and hour hand. The minute and hour hands are re-drawn in handlers of a TimeDate's _timeChanged() event, while the second hand is re-drawn in the Timer's _ring() event handler.