Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DATE BUG ????
Message
 
 
À
10/02/2000 08:04:39
Amit Abhangrao
Charmi Software Exports
Mumbai, Inde
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00329861
Message ID:
00330096
Vues:
24
>Try to create an exe file and run the program. You will find that one of the date result is showing wrong.

Yes, this is because VFP works as Jim explained. Date literals are evaluated at compile time, not at run time. Your code contains literals. The value of SET DATE in effect at compile time determines how those literals are evaluated. As Jim said, any SET DATE commands in your code are NOT evaluated at compile time, therefore the date literal in British format is invalid when you compile with SET DATE AMERICAN, and vice versa.

SET DATE commands are evaluated at run time. To see the difference, change your code to use date variables instead of literals. The code below illustrates this: you can compile and run it with SET DATE AMERICAN or SET DATE BRITISH and it works both ways for both date formats.
clear
set strictdate to 0
set century on
set talk off

local lcMsg, lcMonth, lcDay, lcYear, lcDate, ldDate
lcMonth = "02"
lcDay = "15"
lcYear = "2000"

set date american
?Set("Date")
lcDate = lcMonth + "/" + lcDay + "/" + lcYear
?"lcDate is " + lcDate
ldDate = CTOD( lcDate)
lcMsg = "Date is " + iif( empty( ldDate), "empty", DTOC( ldDate))
?lcMsg
?

Set Date British
?Set("Date")
lcDate = lcDay + "/" + lcMonth + "/" + lcYear
?"lcDate is " + lcDate
ldDate = CTOD( lcDate)
lcMsg = "Date is " + iif( empty( ldDate), "empty", DTOC( ldDate))
?lcMsg
?

*  Restore default settings (yours may be different)
set strictdate to 1
set date american
RETURN
BTW this example also illustrates that you can still use CTOD and DTOC successfully as long as you explicitly control the values of SET CENTURY and SET DATE before doing so.
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