home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SAMPLES.EXE / T_COMPUT.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  2.2 KB  |  88 lines

  1. *****************************************************************
  2. * Test program for COMPUTE function -  FILE T_COMPUT.PRG
  3. *****************************************************************
  4.  
  5. * Copyright(c) 1991 -- James Occhiogrosso
  6.  
  7. * Computes, displays and validates totals for line items
  8.  
  9. # include 'inkey.ch'
  10.  
  11. LOCAL keypress := price1 := price2 := quantity1 := quantity2 := 0
  12.  
  13. #ifdef DEBUG
  14.    DEVELOP()
  15. #endif
  16.  
  17. INITGLOBAL()
  18. SETCOLOR(colstd)
  19. CLEAR
  20.  
  21. DO WHILE keypress != K_ESC
  22.  
  23.     * Get quantity and price of each item. Update and 
  24.     * validate the total with each entry.
  25.  
  26.     @ 5, 15 GET quantity1 PICTURE '999' VALID      ;
  27.                 COMPUTE(quantity1 * price1, 5, 30, ;
  28.                 "99999.99", "CHKTOTAL", colhelp1)
  29.  
  30.     @ 5, 22 GET price1 PICTURE '99.99' VALID       ;
  31.                 COMPUTE(quantity1 * price1, 5, 30, ;
  32.                 "99999.99", "CHKTOTAL", colhelp1)
  33.  
  34.     @ 6, 15 GET quantity2 PICTURE '999' VALID      ;
  35.                 COMPUTE(quantity2 * price2, 6, 30, ;
  36.                 "99999.99", "CHKTOTAL", colhelp1)
  37.  
  38.     @ 6, 22 GET price2 PICTURE '99.99' VALID       ;
  39.                 COMPUTE(quantity2 * price2, 6, 30, ;
  40.                 "99999.99", "CHKTOTAL", colhelp1)
  41.  
  42.     @ 7, 15 TO 7, 37 DOUBLE
  43.     READ
  44.  
  45. ENDDO
  46. RETURN
  47.  
  48.  
  49. *****************************************************************
  50. FUNCTION CHKTOTAL (ret_value)
  51. *****************************************************************
  52. * Sample user defined function called by COMPUTE
  53.  
  54. * Displays and validates total each time data
  55. * is entered into one of four quantity and price fields.
  56.  
  57. LOCAL old_color := ''
  58.  
  59. LOCAL tot_amt := (quantity1 * price1) + (quantity2 * price2)
  60.  
  61. IF tot_amt > 99999.99
  62.  
  63.      * Amount exceeds specified limit
  64.      ERRORBEEP()
  65.      CENTERON(MAXROW(), 'Entry too large. ' + hitanykey)
  66.  
  67.      * Display asterisks in total field
  68.      old_color = SETCOLOR(colbarhi)
  69.      @ 8, 30 SAY '*****.**'
  70.      SETCOLOR(old_color)
  71.  
  72.      * Wait for operator
  73.      INKEY(0)
  74.  
  75.      * Clear totals area and return to pending GET
  76.      @ 8, 30 SAY SPACE(8)
  77.      @ MAXROW(), 0
  78.      ret_value = .F.
  79.  
  80. ELSE
  81.      * Total is within defined limits
  82.      @ 8, 30 SAY tot_amt PICTURE '99999.99'
  83.  
  84. ENDIF
  85.  
  86. RETURN ret_value
  87.  
  88.