Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Formatting a TextBox DateTime
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00933862
Message ID:
01024131
Views:
34
Marcia - this is a VERY handy class - especially for those times when you don't want to have to use cursorschema on a complicated cursor just to get the date formatted correctly.

Many thanks!

>Hello Ricardo.
>
>I have a TextBox with a DATETIME ControlSource column.
>Particularly I'm not interested for this case that the user can see the HOUR neither type it.
>How can I do to format this field, that the user only see and type the DATE ?

>
>
>DEFINE CLASS txtdate AS textbox
>  Alignment = 3
>  Value = {}
>
>  *-- Used to store the actual DateTime ControlSource of the control so we can enter Data Values and update the "real" datetinme controlsource manually behind the scenes
>  ccontrolsource = ""
>  Name = "txtdate"
>
>  *-- Called from the Valid to update the field specified in the cControlSource property from the control's value. It expects the specified field to of data type datetime.
>  PROCEDURE updatecontrolsource
>    LOCAL ldValue, lcField, lcAlias
>
>    ldValue = IIF( VARTYPE( This.Value ) = 'T', TTOD( This.Value ), This.Value )
>    lcField = JUSTEXT( This.cControlSource )
>    lcAlias = JUSTSTEM( This.cControlSource )
>
>    *** Update cControlSource from the Control's Value
>    IF NOT EMPTY( This.cControlSource )
>      IF EMPTY( NVL( ldValue, {} ) )
>        *** Check to see if we are updating a form property
>        IF UPPER( LEFT( This.cControlSource, 4 ) ) == 'THIS'
>          lcControlSource = This.cControlSource
>          &lcControlSource = {/:}
>	ELSE
> 	  REPLACE ( lcField ) WITH .NULL. IN ( lcAlias )
>  	ENDIF
>      ELSE
>  	*** make sure we have a valid date
>  	*** so we do not get datetime overflow errors
>  	*** in sql server when we attempt an update
>  	IF NOT( UPPER( LEFT( This.cControlSource, 4 ) ) == 'THIS'	)
>	  IF BETWEEN( ldValue, {^1900-01-01}, {^3000-01-01} )
>            REPLACE ( lcField ) WITH DTOT( ldValue ) IN ( lcAlias )
>	  ELSE
>	    MESSAGEBOX( 'Invalid Date', 16, 'Please Fix Your Input' )
>	    RETURN .F.
>	  ENDIF
>  	ELSE
> 	  lcControlSource = This.cControlSource
>	  &lcControlSource = DTOT( ldValue )
>  	ENDIF
>      ENDIF
>    ENDIF
>  ENDPROC
>
>
>  *-- Refreshes the control's (DATE) value from the datetime value conained in the field specified in its cControlSource property
>  PROCEDURE refreshvalue
>    LOCAL ltValue
>
>    IF NOT EMPTY( This.cControlSource )
>      ltValue = EVALUATE( This.cControlSource )
>		
>      *** Update the control's value from its cControlSource
>      IF EMPTY( NVL( ltValue, {/:} ) )
>        This.Value = {}
>      ELSE
>        IF VARTYPE( ltValue ) = 'T'
>          This.Value = TTOD( ltValue )
>	ELSE
>          This.Value = ltValue
>        ENDIF
>      ENDIF
>    ELSE
>      This.Value = {}
>    ENDIF
>  ENDPROC
>
>  PROCEDURE Init
>    *** Unbind the control and save the controlsource to a special property
>    IF NOT EMPTY( This.ControlSource )
>      This.cControlSource = This.ControlSource
>      This.ControlSource = ''
>    ENDIF
>    This.Format = 'D'
>    This.Value = {}
>  ENDPROC
>
>  PROCEDURE Valid
>    IF NOT This.UpdateControlSource()
>      RETURN 0
>    ENDIF
>  ENDPROC
>
>  PROCEDURE Refresh
>    This.RefreshValue()
>  ENDPROC
>
>ENDDEFINE
>
____________________________________

Don't Tread on Me

Overthrow the federal government NOW!
____________________________________
Previous
Reply
Map
View

Click here to load this message in the networking platform