Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
After January 1st
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
FoxPro 2.x
Divers
Thread ID:
00308678
Message ID:
00317033
Vues:
49
>In that situation
llIsLeap = NOT EMPTY(CTOD("2/29/" + STR(YEAR(tdate), 4, 0)))
>works, but the format would have to be adjusted for date formats
>other than MDY or AMERICAN.

Here's a routine that handles any SET DATE option and allows you to pass a numeric, character, or date parameter. The syntax has been remediated for FoxPro 2.x but works in VFP too.
*------------------
FUNCTION IsLeapYear
*------------------
Parameters txParm
*
*  Returns .T. if year is a leap year, otherwise returns .F.
*
*  This syntax is for FoxPro 2.x
*
private lcYear, lcSetDate, lcCentury, llLeapYear
lcSetDate = set("date")
lcCentury = set("century")
set date american    && so CTOD will work as expected.
set century on       && ditto.
do case
   case type( "txParm") = "C"
      lcYear = ALLTRIM( txParm)
   case type( "txParm") = "N"
      lcYear = ALLTRIM( STR( txParm))
   case type( "txParm") = "D"
      if !empty( YEAR( txParm))   && If we got a valid date
         lcYear = ALLTRIM( STR( YEAR( txParm)))   && then capture its year.
      else   && Otherwise if we got an invalid date then force
         lcYear = "X"  && '!empty( CTOD( "02/29/" + lcYear))' to be .F.
      endif
endcase
if type("lcYear") = "C"    && .T. if parameter was type C, N, or D
   llLeapYear = !empty( CTOD( "02/29/" + lcYear))
else    && if parameter was not type C, N, or D
   ??chr(7)
   wait window nowait ;
      "Parameter must be character, numeric, or date."
   llLeapYear = .F.
endif
set date &lcSetDate
set century &lcCentury
RETURN llLeapYear
*ENDFUNC IsLeapYear()
Rick Borup, MCSD

recursion (rE-kur'-shun) n.
  see recursion.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform