home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP17.EXE / CHP1711.PRG < prev    next >
Encoding:
Text File  |  1991-04-30  |  2.5 KB  |  85 lines

  1. /*
  2.    Listing 17.11  Popcalc
  3.    NOTE: calls Env_Stack(), which is contained in CHP1705.PRG
  4.    Author: Joe Booth
  5.    Excerpted from "Clipper 5: A Developer's Guide"
  6.    Copyright (c) 1991 M&T Books
  7.                       501 Galveston Drive
  8.                       Redwood City, CA 94063-4728
  9.                       (415) 366-3600
  10. */
  11.  
  12. //───── NOTE: must compile with the /N option!
  13.  
  14. #include "INKEY.CH"
  15. #include "BOX.CH"
  16.  
  17. function popcalc(cProc,nLine,cVar)
  18. LOCAL back_scr := savescreen(2,5,11,25)
  19. LOCAL adding :=.T., first_time := .T.
  20. LOCAL calc_amt := 0, running := 0, calc_op := " "
  21. LOCAL getlist := {}                        // protect get stack
  22. Env_stack(.T.)
  23. /***********************************
  24. *▒▒▒ Paint calculator on screen ▒▒▒*
  25. ***********************************/
  26. @ 02,05,11,25 box B_SINGLE_DOUBLE+" "
  27. @ 02,06 say "  Calculator "
  28. @ 03,06 say "               │ C "
  29. @ 04,06 say "               │ E "
  30. @ 05,06 say "───┬───┬───┬───┼───"
  31. @ 06,06 say " 1 │ 2 │ 3 │ + │ * "
  32. @ 07,06 say "───┼───┼───┼───┼───"
  33. @ 08,06 say " 4 │ 5 │ 6 │ - │ / "
  34. @ 09,06 say "───┼───┼───┼───┼───"
  35. @ 10,06 say " 7 │ 8 │ 9 │ 0 │ = "
  36. /*****************************
  37. *▒▒▒ Main calculator loop ▒▒▒*
  38. *****************************/
  39. do while adding
  40.    @ 3,9 say running picture "99999999.99"
  41.    if !first_time
  42.       @ 4,7 get calc_op picture "!" valid calc_op$"+-/*=C X"
  43.    endif
  44.    @ 4,9 get calc_amt picture "99999999.99"
  45.    read
  46.    first_time := .f.
  47.    ******************************
  48.    *▒▒▒▒ Process key stroke ▒▒▒▒*
  49.    ******************************
  50.    if lastkey() <> K_ESC
  51.       //
  52.       do case
  53.       case calc_op == "C"                     && Clear key
  54.          store 0.0 to running,calc_amt
  55.       case calc_op == " "
  56.          running := calc_amt
  57.       case calc_op == "+"                     && Add
  58.          running += calc_amt
  59.       case calc_op == "*"                     && Multiple
  60.          running *= calc_amt
  61.       case calc_op == "-"                     && Subtraction
  62.          running -= calc_amt
  63.       case calc_op == "/"                     && Division
  64.          if calc_amt > 0
  65.             running /=  calc_amt
  66.          endif
  67.       case calc_op == "X"       //  X, = - Paste the result
  68.          if valtype(cVar) == "N"
  69.             keyboard chr(K_CTRL_Y)+str(running)+chr(K_ENTER)
  70.          endif
  71.          adding := .f.
  72.       endcase
  73.       *
  74.       calc_amt := 0.0
  75.       *
  76.    else
  77.       adding := .f.
  78.    endif
  79. enddo
  80. Env_stack(.F.)
  81. restscreen(2,5,11,25,back_scr)
  82. return NIL
  83.  
  84. // end of file CHP1711.PRG
  85.