Microsoft KB Archive/75720

= Differences in Coprocessor Error in QuickBasic 4.5 vs. 4.0 =

Article ID: 75720

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b

-



This article was previously published under Q75720



SUMMARY
There is a fundamental difference in the way that QuickBasic version 4.5 and version 4.0/4.0b handle coprocessor errors. If any coprocessor error occurs during a statement that includes an assignment to a variable, that assignment does NOT take place in version 4.0/4.0b. However, the assignment does occur in version 4.5. This difference between the two versions can cause major variations in the results of numerical calculations.

The difference between the versions is not the result of a problem with either version, but rather is due to a design change in QuickBasic version 4.5.



MORE INFORMATION
If a math coprocessor error is trapped using an ON ERROR GOTO statement and the error handler uses a RESUME NEXT statement to recover from the error, the result of the calculation that caused the error is different depending on which version of QuickBasic you are using. Under QuickBasic 4.0/4.0b, the variable containing the result is unchanged and preserves the value held before the assignment was attempted. Under QuickBasic 4.5, the assignment is made even though a RESUME NEXT statement is used to recover from the error.

The difference in the way the two products handle coprocessor errors is due to a design change between QuickBasic versions 4.0/4.0b and 4.5. The math routines in QuickBasic 4.5 were optimized to give better performance over version 4.0/4.0b. The behavior described in this article is a result of this change.

Code Example
ON ERROR GOTO 100 X = 0 Y = 0 RESULTS = 10 RESULTS = X / Y PRINT RESULTS END 100 RESUME NEXT Below is a table based on the output of the above sample program run under different versions of QuickBasic with and without a math coprocessor.

Results
  Product                    With Coprocessor    Without Coprocessor ---                       ---

QuickBasic 4.0 or 4.0b           10                   10 QuickBasic 4.5                -1.#IND                 10 Under QuickBasic 4.5 with a math coprocessor present, if the value of X in the above example is positive, then the value of RESULTS will be 1.#INF.

The symbols IND and INF stand for indeterminate and infinite, respectively. Zero divided by zero gives an indeterminate result. Any nonzero value divided by zero gives an infinite result.

Note: If the variable RESULTS in the above sample code is of any numeric type other than SINGLE, the result will be 0 (zero), not -1.#IND, when run under QuickBasic 4.5 with a math coprocessor.

In order to cause consistent behavior under all versions of QuickBasic, it is best to use an IF...THEN statement to check the divisor before attempting the division. For example, the following code fragment, when added in place of the RESULTS = X / Y statement in the sample program above, will give consistent results when run under all versions of QuickBasic with or without a math coprocessor. IF Y <> 0 THEN RESULTS = X / Y END IF

Additional query words: QuickBas 4.00 4.00b 4.50

Keywords: KB75720

-

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

© Microsoft Corporation. All rights reserved.