Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Formatting a TextBox DateTime
Message
De
22/08/2004 12:02:56
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00933862
Message ID:
00935320
Vues:
26
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform