How to Copy to and Paste from the Calculator Within a Screen

ID: Q124716

2.60a   | 2.60a  | 2.60a
WINDOWS | MS-DOS | MACINTOSH

The information in this article applies to:

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:

1. Modify the screen that will access the calculator.

2. 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

3. 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

4. In VALID clause of each participating numeric field, enter:

   curfld=VARREAD()      && store the current field name

5. 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

6. Generate the .SPR and use the DO command to execute the screen.

7. 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.

Additional reference words: FoxWin FoxDos FoxMac 2.60a SBuilder KBCategory: KBSubcategory: FxprgRead
Keywords          : kbcode FxprgRead 
Version           : 2.60a | 2.60a | 2.60a
Platform          : MACINTOSH MS-DOS WINDOWS

Last Reviewed: May 22, 1998