home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 17.11 Popcalc
- NOTE: calls Env_Stack(), which is contained in CHP1705.PRG
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- #include "INKEY.CH"
- #include "BOX.CH"
-
- function popcalc(cProc,nLine,cVar)
- LOCAL back_scr := savescreen(2,5,11,25)
- LOCAL adding :=.T., first_time := .T.
- LOCAL calc_amt := 0, running := 0, calc_op := " "
- LOCAL getlist := {} // protect get stack
- Env_stack(.T.)
- /***********************************
- *▒▒▒ Paint calculator on screen ▒▒▒*
- ***********************************/
- @ 02,05,11,25 box B_SINGLE_DOUBLE+" "
- @ 02,06 say " Calculator "
- @ 03,06 say " │ C "
- @ 04,06 say " │ E "
- @ 05,06 say "───┬───┬───┬───┼───"
- @ 06,06 say " 1 │ 2 │ 3 │ + │ * "
- @ 07,06 say "───┼───┼───┼───┼───"
- @ 08,06 say " 4 │ 5 │ 6 │ - │ / "
- @ 09,06 say "───┼───┼───┼───┼───"
- @ 10,06 say " 7 │ 8 │ 9 │ 0 │ = "
- /*****************************
- *▒▒▒ Main calculator loop ▒▒▒*
- *****************************/
- do while adding
- @ 3,9 say running picture "99999999.99"
- if !first_time
- @ 4,7 get calc_op picture "!" valid calc_op$"+-/*=C X"
- endif
- @ 4,9 get calc_amt picture "99999999.99"
- read
- first_time := .f.
- ******************************
- *▒▒▒▒ Process key stroke ▒▒▒▒*
- ******************************
- if lastkey() <> K_ESC
- //
- do case
- case calc_op == "C" && Clear key
- store 0.0 to running,calc_amt
- case calc_op == " "
- running := calc_amt
- case calc_op == "+" && Add
- running += calc_amt
- case calc_op == "*" && Multiple
- running *= calc_amt
- case calc_op == "-" && Subtraction
- running -= calc_amt
- case calc_op == "/" && Division
- if calc_amt > 0
- running /= calc_amt
- endif
- case calc_op == "X" // X, = - Paste the result
- if valtype(cVar) == "N"
- keyboard chr(K_CTRL_Y)+str(running)+chr(K_ENTER)
- endif
- adding := .f.
- endcase
- *
- calc_amt := 0.0
- *
- else
- adding := .f.
- endif
- enddo
- Env_stack(.F.)
- restscreen(2,5,11,25,back_scr)
- return NIL
-
- // end of file CHP1711.PRG
-