Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Just edit date portion of datetime field
Message
From
03/05/2004 10:16:42
 
 
To
02/05/2004 17:17:07
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00900240
Message ID:
00900372
Views:
17
Hi Alex.

Other than making textbox narrower, is there a way to format the input/output of a textbox so that only the date portion of a datetime field is used?

How about a date textbox class like this?
DEFINE CLASS txtdate AS txtbase
Alignment = 3
Value = {}
Format = "D"

*-- Used to store the actual DateTime ControlSource of the control so we can enter Date 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 Refresh
DODEFAULT()
This.RefreshValue()
ENDPROC

PROCEDURE Valid
IF NOT This.UpdateControlSource()
  RETURN 0
ENDIF
ENDPROC

PROCEDURE Init
DODEFAULT()

*** 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

ENDDEFINE
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform