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

Dusanga

Technical User
May 17, 2023
3
0
1
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"
        lnDay = CAST(GETWORDNUM(txDateValue, 1, "/") AS I)
        lnMon = 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
 
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
 

Part and Inventory Search

Sponsor

Back
Top