The UDF's included below provide two methods for automatically generating hour pick-lists for HTML select lists or grid/dialog dropdown lists. (I couldn't get the text file to attach, so I am including the UDF's below).
The first is get_hour_picker(), which will output a crlf-delimited list of hours and fractions of hours based on the input parameters. It is intended to be used for applications that need to select amounts of time (e.g., an attendance application, or job tracking, etc.), but you may find many other applications for it as well. The min_value and max_value parameters set the upper and lower limits for the number of hours. The minutes_apart parameter specifies the incremental step for each item in the list. The html_ready parameter determines whether the function should return an HTML-useable select list, or just a crlf-delimited list. This UDF takes three optional parameters:
The second is get_time_picker(), which will output a list of times of day based upon the input parameters. It is intended to be used for applications that need to select the time of day based over a given time-frame and incremental steps, in 12- or 24-hour format. The min_hour and max_hour parameters set the earliest and latest times in the list; the am_pm parameter sets the output format; and the minutes_apart parameter sets the incremental step for each item in the list. The html_ready parameter determines whether the function should return an HTML-useable select list, or just a crlf-delimited list. This UDF takes three optional parameters:
If you have any suggestions for improvements, please let me know.
get_hour_picker()
get_time_picker()
The first is get_hour_picker(), which will output a crlf-delimited list of hours and fractions of hours based on the input parameters. It is intended to be used for applications that need to select amounts of time (e.g., an attendance application, or job tracking, etc.), but you may find many other applications for it as well. The min_value and max_value parameters set the upper and lower limits for the number of hours. The minutes_apart parameter specifies the incremental step for each item in the list. The html_ready parameter determines whether the function should return an HTML-useable select list, or just a crlf-delimited list. This UDF takes three optional parameters:
- min_value (default = 0) -- sets the minimum number of hours
- max_value (default = 10) -- sets the maximum number of hours
- minutes_apart (default = 15) -- sets the incremental step for each line item
- html-ready (default = .f.) -- return HTML select list (.t.) or crlf-delimited list (.f.)
The second is get_time_picker(), which will output a list of times of day based upon the input parameters. It is intended to be used for applications that need to select the time of day based over a given time-frame and incremental steps, in 12- or 24-hour format. The min_hour and max_hour parameters set the earliest and latest times in the list; the am_pm parameter sets the output format; and the minutes_apart parameter sets the incremental step for each item in the list. The html_ready parameter determines whether the function should return an HTML-useable select list, or just a crlf-delimited list. This UDF takes three optional parameters:
- min_hour (default = "00:00:00") -- sets the earliest hour for the list
- max_hour (default = "23:59:59") -- sets the latest hour for the list
- am_pm (default = 12) -- sets the output format (12 = 12-hour clock; any other number = 24-hour clock)
- minutes_apart (default = 15) -- sets the incremental step for each list item (all times use this for rounding to the nearest increment)
- html-ready (default = .f.) -- return HTML select list (.t.) or crlf-delimited list (.f.)
If you have any suggestions for improvements, please let me know.
get_hour_picker()
Code:
'Date Created: 28-Nov-2012 09:02:13 AM 'Last Updated: 28-Nov-2012 10:38:45 AM 'Created By : spilon 'Updated By : spilon FUNCTION get_hour_picker AS C (min_value = 0, max_value = 10, minutes_apart = 15, html_ready = .f.) dim hourList as c dim hour_increment as n = minutes_apart / 60 for i = min_value to max_value step hour_increment hourList = hourList + ut(str(i,10,2)) + crlf() next i get_hour_picker = iif(html_ready, a5_html_list_populate(hourList), hourList) END FUNCTION
Code:
'Date Created: 28-Nov-2012 08:51:12 AM 'Last Updated: 28-Nov-2012 08:51:12 AM 'Created By : spilon 'Updated By : spilon FUNCTION Get_time_picker AS C (min_hour = "00:00:00", max_hour = "23:45:00", am_pm = 12, minutes_apart = 15, html_ready = .f.) dim hour_list as c dim min_value as n dim max_value as n dim select_value as c dim hour_value as c dim minute_value as c dim mod_denominator as n dim hour_increment as n = minutes_apart * 60 dim rounding_fraction as n = hour_increment / 2 if min_hour = "" then min_hour = "00:00:00" end if if max_hour = "" then max_hour = "23:45:00" end if min_value = int((toseconds(min_hour) + rounding_fraction) / hour_increment) max_value = int((toseconds(max_hour) + rounding_fraction) / hour_increment) mod_denominator = 3600 / hour_increment for i = min_value to max_value minute_value = ":" + padl(ut(str((mod(i,mod_denominator) * (hour_increment / 60)))),2,"0") select_value = padl(ut(str(int(i/mod_denominator),10,0)),2,"0") + minute_value hour_value = select_value if am_pm = 12 then dim midnight_hour as n = (3600 - hour_increment) / hour_increment dim before_noon as n = (3600 / hour_increment * 12) - 1 dim at_noon as n = (3600 / hour_increment * 13) - 1 if i <= midnight_hour then hour_value = "12" + minute_value + " am" else if i <= before_noon hour_value = padl(ut(str(int(i/mod_denominator),10,0)),2,"0") + minute_value + " am" else if i <= at_noon hour_value = padl(ut(str(int(i/mod_denominator),10,0)),2,"0") + minute_value + " pm" else 'after_noon hour_value = padl(ut(str(int(i/mod_denominator) - 12,10,0)),2,"0") + minute_value + " pm" end if end if hour_list = hour_list + hour_value + "|" + select_value + ":00" + crlf() next i if html_ready then hour_list = *for_each(foo,"<option value=\"" + word(foo,2,"|") + "\">" + word(foo,1,"|") + "</option>",hour_list) end if Get_time_picker = hour_list END FUNCTION
Comment