Getting the Current Time from the Operating System

Sometimes you would like to have the current time displayed in a time field when the form is displayed. To get the time from the operating system, call the time_get() function:

int time_get(time_stp, format_stp)

UCHAR *time_stp;                /* Pointer to string to store time in    */

UCHAR *format_stp;            /* Pointer to format string            */

Caution: You must allocate memory for time_stp before calling this function.

The specifics for using a time field are summarized below:

Field Type F_TIME
Header File vv_time.h
Data Variable UCHAR *data or UCHAR data[ ]

The data variable must be allocated and initialized. The variable must be long enough to hold the time string entered in the field, including separators and a null terminator, or memory will be corrupted.

Picture Control You can create a picture that has controlled format entry or one that allows free-format entry.

When defining a picture string for controlled time entry, the picture string must match the time format. The picture control characters 9, U, A, *, and ! are allowed in the picture. For instance, if the time format is "HH:MM:SS am", the picture should be "UU:UU:UU AA".

For free-format time entry, specify a string of Xs for the picture string. Users can then enter the time using their choice of separators. The only limitation is that the user must enter the hours, minutes, and seconds in the order specified in the format string. The system will attempt to convert the entered time into the format specified for the field.

Code Example UCHAR *time, *my_format;
DFIELDPTR fldp;

time = mem_stblank(8);

my_format = "HH:MM am";

time_get(time, my_format);

fldp = fld_def(5, 1, "Order Time: ", FBELOW,
"UU:UU AA", F_TIME, time, dfmp);

sf_timefmt(my_format, fldp);


Home Contents Previous Next