Microsoft KB Archive/139953

= BUG: DATETIME Datatype Rounds Fractions of a Second =

Article ID: 139953

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q139953



SYMPTOMS
Repeatedly adding (or subtracting) a fraction of a second to (or from) a variable that contains a DATATIME data type results in an unexpected value being stored in the variable.



CAUSE
Visual FoxPro rounds the fraction of a second being added (or subtracted) up (or down) to the nearest whole second and stores the rounded value in the variable.



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Problem
  Type the following line of code in the Command window: X = {1/1/95 12:00:00PM}   Type the following line of code in the Command window: Y = X + .1   Type the following line of code in the Command window: ? Y == X                       

The return value is True (.T.) even though you added a tenth of a second to x.

Another Demonstration of the Problem
  Type the following line of code in the Command window: MODIFY COMMAND test   In the program window produced by the previous command, type the following lines of code: *-  *-- BEGIN PROGRAM TEST *-  CLEAR

LOCAL X, Y  X = {1/1/95 12:00:00pm} FOR I = 1 to 5

*-- Show which iteration you are on    DO CASE CASE I = 1 WAIT WINDOW "Iteration 1" TIMEOUT .75 CASE I = 2 WAIT WINDOW "Iteration 2" TIMEOUT.75 CASE I = 3 WAIT WINDOW "Iteration 3" TIMEOUT.75 CASE I = 4 WAIT WINDOW "Iteration 4" TIMEOUT.75 OTHERWISE WAIT WINDOW "Last Iteration" TIMEOUT.75 ENDCASE

*-- Add 1 tenth of a second to Y    Y = X + .1

*-- Display X    WAIT WINDOW "X = " + TTOC(X) TIMEOUT 1

*-- Compare Y and X    *-- One would think the following comparison would return .F.     WAIT WINDOW "Y == X is " + IIF(Y==X,".T.",".F.") + ; " <<= First Test" + CHR(13) + ; "Y has been incremented" + CHR(13) + CHR(13) +; "Press any key to continue"

*-- Add 1 tenth of a second to X    X = X + .1

*-- Compare Y and X    *-- One would think the following comparison would return .T.     WAIT WINDOW "Y == X is " + IIF(Y==X,".T.",".F.") + ; " <<= Second Test" + CHR(13) + ; "X has been incremented" + CHR(13) + CHR(13) + ; "Press any key to continue"

*-- Display Y    WAIT WINDOW "Y = " + TTOC(Y) + ; CHR(13) + ; "Y has been incremented by .1 seconds" ; TIMEOUT 2 ENDFOR *-  *-- END PROGRAM TEST *-                       </li> Run the program. A one-second increase in time is displayed after five tenths of a second have accumulated. The incremented tenths are held by the variable but are never displayed until rounding the accumulated number of tenths results in a full second. Additionally, the comparison appears to be based on the rounding of the fractions of a second, not on the actual number stored to the variable.</li></ol>

Additional query words: kbvfp300 kbvfp500 kbvfp600

Keywords: kbbug kbprogramming KB139953

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.