AndrewMozley
Programmer
I have a data-entry text box. When it has focus it shows the date in dd-mm-yy format
So the user can perhaps key in new values
And when it does not have focus it shows as :
To that end it has a PUBLIC variable - zValueD - of type DATE, (which is not itself the value of the control). So the application can perhaps assign a value to this variable; this causes the textbox to be refreshed with the new date.
The code for the class looks more or less like this.
Any suggestions for improvement? Thanks - Andrew
So the user can perhaps key in new values
And when it does not have focus it shows as :
To that end it has a PUBLIC variable - zValueD - of type DATE, (which is not itself the value of the control). So the application can perhaps assign a value to this variable; this causes the textbox to be refreshed with the new date.
The code for the class looks more or less like this.
Code:
DEFINE CLASS amdate AS amtxt && a subclass of Textbox
Alignment = 3
Value = {}
zvalued = .F.
Name = "amdate"
PROCEDURE zvalued_assign
LPARAMETERS vNewVal
THIS.zvalued = m.vNewVal
This.Value = FormatDate(This.zValueD)
ENDPROC
PROCEDURE Valid
LOCAL lValue
WITH This
lValue = This.Value
.zvalueD = CTOD(lValue)
This.Value = lValue
IF EMPTY(.zValueD)
MESSAGEBOX("Invalid date")
RETURN .F.
ENDIF
ENDWITH
RETURN DODEFAULT()
ENDPROC
PROCEDURE LostFocus
WITH This
.InputMask = "XXXXXXXXX"
.zvalueD = CTOD(.Value)
.Value = FormatDate(.zValueD) && so : 17-Jul-22
ENDWITH
ENDPROC
PROCEDURE GotFocus
WITH This
.Value = DTOC(.zValueD)
.InputMask = "99-99-99"
ENDWITH
ENDPROC
PROCEDURE Init
IF EMPTY(This.zValueD)
This.zValueD = DATE()
ENDIF
RETURN DODEFAULT()
ENDPROC
ENDDEFINE
Any suggestions for improvement? Thanks - Andrew