The information in this article applies to:
- Microsoft FoxPro for Windows, version 2.6a
- Microsoft FoxPro for MS-DOS, version 2.6a
- Microsoft FoxPro for Macintosh, version 2.6a
SUMMARY
If the calculator is activated while the READ generated by the Screen
Builder is in effect, it will not become the window on top and may not be
visible if the screen covers the area where the calculator was activated.
This article shows by example how to bring up the calculator on top of the
READ window, as well as how to place the value of the current GET field in
the calculator, and return the result of the calculation to the GET.
MORE INFORMATION
Step-by-Step Example
The following steps lead you through the process of incorporating this
functionality in the context of a screen set. Also shown in this example is
the ability to transfer values between the screen and the calculator.
Assumptions:
- A screen exists that contains at least one numeric field formatted with
two decimal places.
- A push button has been added to call the calculator.
- The Cycle option under the Window pad of the System menu bar is
available.
- The GET fields on the screen are referencing the database fields
directly rather than through memory variables.
- Modify the screen that will access the calculator.
- Bring up the Setup Code window, and enter the following:
* set up variable to hold name of selected field
curfld = "" && current field to copy from and paste to
* in FoxPro for Macintosh add the following line to keep the READ
* window visible in front of the FoxPro screen
#WCLAUSES IN SCREEN && FoxPro for Macintosh only
- Open the Cleanup and Procedures window, and enter the following:
IF WVISIBLE("CALCULATOR") && exiting program, so
DEACTIVATE WINDOW CALCULATOR && close the calculator
ENDIF
PROCEDURE paste
* Called when the calculation is completed
REPLACE (curfld) WITH VAL(ALLTRIM(STR(_CALCVALUE,10,2)))
SHOW GETS && update the display with the new value
DO waste && close the calculator and clean up
PROCEDURE waste
* Called to close calculator and clean up status bar
KEYBOARD CHR(23) && close window
POP KEY && restore previously saved ON KEY LABEL set
SET MESSAGE TO "" && erase message on status bar
SET MESSAGE TO && reset to default messages
- In VALID clause of each participating numeric field, enter:
curfld=VARREAD() && store the current field name
- Within the VALID clause of the Calculator push button, enter:
_CLIPTEXT=ALLTRIM( STR( EVALUATE( curfld ), 10, 2) ) &&store val
KEYBOARD "{CTRL+F1}" && cycle focus to the calculator
PUSH KEY CLEAR && store any ON KEY LABEL definitions
ON KEY LABEL F4 KEYBOARD "{CTRL+V}" && Copy GET to calc
ON KEY LABEL F5 DO paste && Paste calc to GET, exit
ON KEY LABEL F8 DO waste && Exit calculator, no paste
ON KEY LABEL ESCAPE DO waste && (same as above)
SET MESSAGE TO " F4 = Copy GET F5 = Paste, exit F8 = Exit"
ACTIVATE WINDOW CALCULATOR
- Generate the .SPR and use the DO command to execute the screen.
- To demonstrate the functionality, assume that a six percent increase
must be added to a particular field. Press the TAB key to move to one of
the numeric fields that has a Currency format [ @$ 9,999.99 ]. Enter the
value of 123. Select the Calculator button, and press the F4 key.
The field value will be inserted into the calculator. Multiply the value
by .06 (asterisk-period-zero-six-enter), which should be 7.3800. Add
this result to the original value (plus_sign-F4-enter), which should
equal 130.3800. At this point, press the F5 key to exit the calculator.
The value of $130.38 will be inserted into the field.
|