home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / GKCALC.PRG < prev    next >
Encoding:
Text File  |  1991-07-16  |  2.3 KB  |  77 lines

  1. /*
  2.     Function: GKeyCalc()
  3.     Purpose:  Alternate for GetApplyKey()
  4.               for calculator-style data entry only
  5.     Author:   Greg Lief
  6.     Copyright (c) 1991 Greg Lief
  7.     Dialect:  Clipper 5.01
  8. */
  9.  
  10. #define  MAX_DECIMAL     get:cargo[3, 1]
  11. #define  CURR_DECIMAL    get:cargo[3, 2]
  12. #define  ALREADYVISITED  get:cargo[3, 3]
  13.  
  14. #include "inkey.ch"
  15. #include "getexit.ch"
  16.  
  17. procedure gkeycalc(get, key)
  18. local cKey
  19.  
  20. //───── check for SET KEY and basic movement keys
  21. if ! GKeyBasic(get, key)
  22.    do case
  23.  
  24.       case (key == K_BS)
  25.          get:BackSpace()
  26.          if val(get:buffer) != 0 .or. CURR_DECIMAL > 0
  27.             do case
  28.                /* number is integer, kill least significant digit */
  29.                case CURR_DECIMAL == 0
  30.                   get:varPut( int( get:varGet() / 10) )
  31.                /* one decimal place: scrub decimal point */
  32.                case CURR_DECIMAL == 2
  33.                   CURR_DECIMAL := 0
  34.                   get:varPut( int( get:varGet() ) )
  35.                otherwise
  36.                   CURR_DECIMAL--
  37.                   get:varPut(val(substr(get:buffer, 1, ;
  38.                            get:decpos + CURR_DECIMAL - 1)))
  39.             endcase
  40.             get:updateBuffer()
  41.          endif
  42.  
  43.       otherwise
  44.  
  45.          if ( ckey := chr(key) ) $ '.0123456789-'
  46.             if ALREADYVISITED
  47.                ALREADYVISITED := .F.
  48.                get:varPut(0)
  49.             endif
  50.             do case
  51.  
  52.                case cKey == '-'      /* positive to negative */
  53.                   get:varPut(get:varGet() * -1)
  54.  
  55.                case cKey == '.' .and. CURR_DECIMAL == 0
  56.                   CURR_DECIMAL++
  57.  
  58.                case get:varGet() != 0 .and. CURR_DECIMAL == 0 .and. ;
  59.                                left(get:buffer, 1) == ' '
  60.                   get:varPut(get:varGet() * 10 + val(cKey) * ;
  61.                            if(get:varGet() < 0, -1, 1))
  62.  
  63.                case CURR_DECIMAL > 0 .and. ;
  64.                     CURR_DECIMAL <= MAX_DECIMAL
  65.                   get:varPut(get:varGet() + ;
  66.                         (val(cKey) / (10 ^ CURR_DECIMAL++)) * ;
  67.                         if(get:varGet() < 0, -1, 1))
  68.  
  69.                case get:varGet() == 0
  70.                   get:varPut(val(cKey))
  71.             endcase
  72.             get:updateBuffer()
  73.          endif
  74.    endcase
  75. endif
  76. return
  77.