Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making an AM/PM spinner? 1

Status
Not open for further replies.

EMJULIAN

Programmer
Aug 14, 2002
45
US
Is it possible to create a spinner that toggles AM/PM?

Thanks,
Eve
 
Is there much point having a spinner for this? Wouldn't a combobox or option group be better?

I like work. It fascinates me. I can sit and look at it for hours...
 
A combo box would be much better.

Or an optiongroup?


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Eve,

It is possible to create a spinner that cycles from 1 to 12 and back again. The AM/PM indicator can be a label or textbox next to the spinner. Set the spinner properties as follows:

SpinnerHighValue = 13
SpinnerLowValue = 0

In the InteractiveChange event:

IF THIS.VALUE = 13
THIS.VALUE = 1
ENDIF
IF THIS.VALUE = 0
THIS.VALUE = 12
ENDIF

Place NODEFAULT in the KeyPress event to prevent keyboard entry into the spinner.

Jim
 
Hi Mike,

Yes my assumption (maybe incorrect) is that Eve wants not just AM/PM but the hour also. -Jim
 
With the spinner idea, you could make the interval 12 and then it would flip from 1 to 12 with the up arrow and from 12 to 1 with the down arrow.

However that would perhaps be unintuitive.

I would suggest a ListBox over a combo. With the combo you have to make 2 clicks to change from AM to PM, but with a list box it would be just one click.

The option group does sound the best though.


Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Eve,

Rather than using a spinner, use a text box. In the "FORMAT" property put an M and in the INPUT MASK property put AM,PM (or A,P). This is a holdover from FoxPro DOS/WINDOWS that allows the user to either press the space bar to move thru the list of values in the INPUT MASK property or to press the A / P keys.

I've created a "time entry" class that does what I think you're trying to accomplish. See below.

Code:
**************************************************
*-- Class:        txt_time (h:\vfp\gwa.vcx)
*-- ParentClass:  container
*-- BaseClass:    container
*-- Time Stamp:   08/16/04 09:17:12 AM
*
DEFINE CLASS txt_time AS container


	Width = 92
	Height = 28
	BackStyle = 0
	BorderWidth = 0
	*-- Control Source for time field
	cnt_source = "REQUIRED"
	*-- Set to .T. if CNT_SOURCE is a DateTime field, otherwise Numeric is presumed.
	ldatetime = .F.
	*-- Set to .T. if CNT_SOURCE is a memory variable.
	lismemvar = .F.
	*-- Set to .T. if time is to be displayed in Military (24-Hour) format.
	lmilitary = .F.
	Name = "txt_time"


	ADD OBJECT txt_hr AS textbox WITH ;
		Alignment = 3, ;
		Value = 12, ;
		Height = 23, ;
		InputMask = "99", ;
		Left = 2, ;
		Top = 3, ;
		Width = 25, ;
		Name = "txt_hr"


	ADD OBJECT txt_min AS textbox WITH ;
		Alignment = 3, ;
		Value = 0, ;
		Format = "L", ;
		Height = 23, ;
		InputMask = "99", ;
		Left = 31, ;
		ToolTipText = "Enter value between 0 and 59", ;
		Top = 3, ;
		Width = 25, ;
		Name = "txt_min"


	ADD OBJECT txt_ampm AS textbox WITH ;
		Value = "AM", ;
		Format = "M", ;
		Height = 23, ;
		InputMask = "AM,PM", ;
		Left = 61, ;
		ToolTipText = "Press A, P, or SPACEBAR to toggle between AM and PM", ;
		Top = 3, ;
		Width = 26, ;
		Name = "txt_ampm"


	ADD OBJECT label1 AS label WITH ;
		AutoSize = .T., ;
		FontBold = .T., ;
		FontSize = 12, ;
		BackStyle = 0, ;
		Caption = ":", ;
		Height = 22, ;
		Left = 26, ;
		Top = 3, ;
		Width = 8, ;
		Name = "Label1"


	PROCEDURE Init
		this.txt_hr.ToolTipText = "Enter value between 1 and " + IIF(this.lmilitary,"24","12")
	ENDPROC


	PROCEDURE txt_hr.Valid
		IF this.Value < 1 OR this.Value > (IIF(this.Parent.lmilitary,24,12))
			RETURN .F.
		ENDIF 
	ENDPROC


	PROCEDURE txt_min.Valid
		IF this.Value < 0 OR this.Value > 59
			RETURN .F.
		ENDIF 
	ENDPROC


ENDDEFINE
*
*-- EndDefine: txt_time
**************************************************

Steve
 
Thanks all for the replies. In the interest of time and keeping things simple I ended up using a combo box for AM/PM and a text box for the time. I appreciate all the great ideas though and will be keeping them for reference - i'm sure I'll have another project where it will come in useful.

Thanks!
Eve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top