Alpha Video Training
Results 1 to 4 of 4

Thread: Hour Pickers for Select Lists

  1. #1
    Member StephenP's Avatar
    Real Name
    Stephen Pilon
    Join Date
    Apr 2000
    Location
    Front Royal, Virginia
    Posts
    491

    Default Hour Pickers for Select Lists

    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:


    • 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
    get_time_picker()
    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
    Last edited by StephenP; 11-28-2012 at 03:42 PM. Reason: Added HTML/Non-HTML pararmeters
    Stephen Pilon
    Associate Librarian
    Christendom College

  2. #2
    Member StephenP's Avatar
    Real Name
    Stephen Pilon
    Join Date
    Apr 2000
    Location
    Front Royal, Virginia
    Posts
    491

    Default Re: Hour Pickers for Select Lists

    In order to use this in a grid (for example), just add this code to the OnGridInitialize event in the Server-side Events:

    Code:
    e.rtc.time_dropdown = get_time_picker()
    Then for the dropdown field, under DropDownBox Properties, set the choices to a variable, and enter time_dropdown.
    Stephen Pilon
    Associate Librarian
    Christendom College

  3. #3
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Hour Pickers for Select Lists

    Stephen,

    Would that be the same for a Dialog?
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

  4. #4
    Member StephenP's Avatar
    Real Name
    Stephen Pilon
    Join Date
    Apr 2000
    Location
    Front Royal, Virginia
    Posts
    491

    Default Re: Hour Pickers for Select Lists

    Keith,

    I haven't used dialogs much yet, but I'll check it out.

    ... checking ...

    Well, it seems to work the same way in a dialog.
    Last edited by StephenP; 11-28-2012 at 07:38 PM. Reason: testing the process for dialogs
    Stephen Pilon
    Associate Librarian
    Christendom College

Similar Threads

  1. Select all items in multi-select list box by default
    By Jay Talbott in forum Alpha Five Version 8
    Replies: 10
    Last Post: 02-02-2012, 07:27 PM
  2. new date and date time pickers in v11
    By Richard Rabins in forum Announcements
    Replies: 0
    Last Post: 08-12-2011, 07:16 PM
  3. Pre-Select Options in a Multi-Select DropDown
    By roberto in forum Application Server Version 9 - Web/Browser Applications
    Replies: 2
    Last Post: 05-21-2009, 05:37 PM
  4. Pre-Select Options in a Multi-Select DropDown
    By roberto in forum Alpha Five Version 9 - Desktop Applications
    Replies: 1
    Last Post: 05-19-2009, 02:53 PM
  5. Less Than An Hour To Go
    By forskare in forum Alpha Five Version 4
    Replies: 4
    Last Post: 10-04-2001, 01:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •