Calculator, _CalcMem, _CalcValue

One of FoxPro's built-in tools plus two system memory variables that track the numbers stored in the calculator—the first stored in the calculator's memory and the second displayed.The calculator is a desk-accessory-like utility included with Visual FoxPro, similar to the Calendar/Diary. Microsoft is discouraging its use by removing it from the visual interface of Visual FoxPro and making no effort to improve its awkward appearance, interface or features. The calculator can be invoked by issuing the command ACTIVATE WINDOW CALCULATOR. You can make it available on an as-needed basis by adding the menu pad _MST_CALCU to your custom menu.The calculator can be operated completely from the keyboard. For those trivia buffs in the audience, here are the keystrokes that perform the equivalent button functions when the calculator has the focus:

Keystroke

Button Label

Effect

A

M+

Adds the current value to that stored in memory.

C

C

Press once to erase (clear) the current value displayed, twice to erase the calculation in process.

N

Reverses the sign of the current value.

Q

Returns the square root of the current calculator value.

R

MR

Recalls the value stored in memory.

Z

MC

Clears (zeroes) the value in memory.

S

M-

Subtracts the current value from that in memory.


The calculator takes advantage of a resource file, if one is in use, to store its most recent position. A "Properties" menu option is also available under the standard Edit menu that allows you to store preferences for automatically toggling the NumLock and determining the precision in which numbers are displayed.Unless Microsoft begins to show more support for these rather cool little features, we think it might be best for you to consider alternatives like ActiveX controls, or coding your own, to ensure that you have control of the object's behavior now and in future versions.

Usage

nValue = _CALCMEM
nValue = _CALCVALUE
_CALCMEM = nValue
_CALCVALUE = nValue
_CALCMEM stores the value of the calculator memory (what's been stored there), while _CALCVALUE is the current value displayed in the calculator window.

If you assign values to _CALCVALUE and _CALCMEM, they appear to take. When you activate the Calculator, however, you may find the values displayed as rounded integers—no decimal places are displayed. You can read a value with decimal places just fine from the Calculator, but you can't place one there, unless there was already a decimal place displayed before. This bug appears to be in all versions of Visual FoxPro.

_calcvalue = 123.456
? _calcvalue  && 123.46, rounded to your decimal setting
ACTIVATE WINDOW calculator && You may see "123"

If you clear the Calculator and enter ".0" as a value, and repeat the above lines of code, you should see 123.46 (or more decimals, depending on your setting). What's really interesting is that once you do this, the "setting" is stored in the FoxUser table, so that once it's stored in the FoxUser table, decimals are then always displayed. If you're going to use this feature in your apps, you might want to consider shipping a FoxUser table with your app. You'll need to "fix" your FoxUser first, then copy the record (ID = 'CALCULATOR') into the user's FoxUser table, because the Data field stores its settings in a binary format.

Example

SET DECIMALS TO 4
STORE PI() TO _CALCMEM
_CALCVALUE = 2.123
ACTIVATE WINDOW CALCULATOR  
* If you've "fixed" your FoxUser table, you'll see "2.1230" 
* displayed, and pressing MR displays "3.1416".
* If you haven't "fixed" your FoxUser table, you'll see "2" 
* and pressing MR displays "3".

See Also

Calendar/Diary, Desk Accessories, Filer, Puzzle, Set Decimals


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .