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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic date completion

Status
Not open for further replies.

Dusanga

Technical User
May 17, 2023
4
SK
When entering a date, for example in a table, VFP automatically adds the year after entering the day and month.
Is it possible to automatically fill in the month and year after entering the day?
 
it depends on your application.
You could pre-fill with today's date and just press Enter without the need to even enter the day value.
 
As you noted, VFP does automatically add the current year to the date value. However, VFP does not automatically add the current month too. You would have to create a custom function to do this. Something like:

Code:
LPARAMETERS txDateValue
IF PCOUNT() = 0
   RETURN DATE()
ENDIF
DO CASE
    CASE VARTYPE(txDateValue) = "D"
        RETURN txDateValue

    CASE VARTYPE(txDateValue) = "C"       && I am assuming date format "mm/dd/yyyy"
        lnMon = CAST(GETWORDNUM(txDateValue, 1, "/") AS I)
        lnDay = CAST(GETWORDNUM(txDateValue, 2, "/") AS I)
        lnYr  = CAST(GETWORDNUM(txDateValue, 3, "/") AS I)
        DO CASE
            CASE lnDay > 0 .AND. lnMon > 0 .AND. lnYr > 0
                RETURN DATE(lnYr, lnMon, lnDay)

            CASE lnDay > 0 .AND. lnMon > 0 .AND. lnYr = 0
                RETURN DATE(YEAR(DATE()), lnMon, lnDay)
           
            CASE lnDay > 0 .AND. lnMon = 0 .AND. lnYr = 0
                RETURN DATE(YEAR(DATE()), MONTH(DATE()), lnDay)
       
            OTHERWISE
                RETURN DATE()
    ENDCASE
ENDCASE
 
Last edited:
How about prefilling with the current date? Then changing just the day you're at your goal without programming anything.
 
In the date field you can intercept the key that has been pressed in the keypress event. For instance you can check for a "T" or a "t" being pressed and set the value to DATE(). Similarly, you can catch the keypress and if the "+" or "-" keys are pressed you can add or subtract a day from the controls current value.

Mark
 
Thank you all for your help. I placed the code in the attachment in the Keypress event of the Textbox.
LPARAMETERS nKeyCode, nShiftAltCtrl
*!* Ak pri zadavani datumu nie su vyplnene vsetky hodnoty , tak procedura doplni
*!* nezadane hodnoty z aktualneho datumu.
* Procedura sa vykona len pri type DATUM
IF VARTYPE(this.Value) = 'D'
*Procedura sa vykona len po stlaceni klavesy ENTER
IF nKeyCode = 13

*!* VFP automaticky kontroluje korektnost vlozenych udajov. Pocas tejto kontroly
*!* sa vytvori objekt ActiveControl, kde vo vlastnosti Text je ulozena hodnota objektu.
*toto su hodnoty zadaneko datumu, den, mesiac rok
nlInputDay = val(SUBSTR(thisform.ActiveControl.Text,1,2))
nlInputMonth = val(SUBSTR(thisform.ActiveControl.Text,4,2))
nlInputYear = val(SUBSTR(thisform.ActiveControl.Text,7,4))

*toto su hodnoty aktualneho datumu
nlDateDay = DAY(DATE())
nlDateMonth = MONTH(DATE())
nlDateYear = YEAR(DATE())


DO case
CASE nlInputYear = 0 .and. nlInputMonth = 0 .and. nlInputDay = 0
dlDatum = DATE()
CASE nlInputMonth = 0 .and. nlInputDay = 0
dlDatum = DATE(nlInputYear,nlDateMonth,nlDateDay)
CASE nlInputYear = 0 .and. nlInputMonth = 0
dlDatum = DATE(nlDateYear,nlDateMonth,nlInputDay)
CASE nlInputYear = 0 .and. nlInputDay = 0
dlDatum = DATE(nlDateYear,nlInputMonth,nlDateDay)
CASE nlInputYear = 0
dlDatum = DATE(nlDateYear,nlInputMonth,nlInputDay)
CASE nlInputMonth = 0
dlDatum = DATE(nlInputYear,nlDateMonth,nlInputDay)
CASE nlInputDay = 0
dlDatum = DATE(nlInputYear,nlInputMonth,nlDateDay)
OTHERWISE
dlDatum = this.value
ENDCASE
this.Value = dlDatum


ENDIF
ENDIF
 
Thank you all for your help. I placed the code in the attachment in the Keypress event of the Textbox.
Why?!?
Code:
 * textbox keypress event
IF NOT PEMSTATUS(_Screen, "oDT", 5)
*SET PROCEDURE TO (m.lcPath+"..\src\DTCLASS.prg")
_Screen.AddProperty( "oDT", CREATEOBJECT("_DATE"))
_Screen.oDT.AutoFillDate=1
ENDIF
This.Value=_Screen.oDT.ToDate(This, This.Text)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top