Microsoft KB Archive/161053

= FIX: CALCULATE SUM on Currency Field Gives Illegal Operation =

Article ID: 161053

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition

-



This article was previously published under Q161053



SYMPTOMS
Performing a comparison on a value created with the CALCULATE SUM function causes and illegal operation error. In Windows 95, the error message states the following:

This program performed an illegal operation and will be shut down.

After pressing the Details push button, the following message appears:

VFP caused and invalid pagefault in module VFP .EXE at.

In Windows NT 4.0, the following error appears:

An application error had occurred and an application error log is being generated.

VFP.EXE

Exception: access violation.

This behavior does not occur in Visual FoxPro 3.0a.



RESOLUTION
The use of the STR and VAL functions may prevent this error. The modified code example below shows the implementation of this resolution: SET TALK OFF CREATE TABLE junk (amt y)  INSERT INTO junk (amt) VALUE(1.00) INSERT INTO junk (amt) VALUE(0.20) CALCULATE SUM(amt) TO mx  mx=STR(mx)  && Converts the value from numeric to character type. mz = (VAL(mx) < 0) && Converts mx back to numeric data type. ? mz



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem has been fixed in Visual FoxPro 5.0a.



MORE INFORMATION
The following code illustrates this behavior. The use of other aggregate functions, such as AVG, in the CALCULATE function produces similar results.

Steps to Reproduce Behavior
Enter the following code in a program and execute: SET TALK OFF CREATE TABLE junk (amt y)  INSERT INTO junk (amt) VALUE(1.00) INSERT INTO junk (amt) VALUE(0.20) CALCULATE SUM(amt) TO mx  mz = (mx < 0) ? mz The error occurs during the comparison of the variable created with the CALCULATE SUM function and another value. In the example above, initially declaring the variable mx numeric does not prevent the error.

Keywords: kbbug kbfix kbvfp500afix kbprogramming KB161053

-

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

© Microsoft Corporation. All rights reserved.