'===========================================================================
' Subject: CALCULATOR-STYLE INPUT             Date: 06-20-97 (06:20)       
'  Author: Kurt Kuzba                         Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: TEXT.ABC
'===========================================================================
'>   I am working on a calculator program, but the biggest
'>   problem is how do I enter the numbers from right to left,
'>   instead of the normal left to right?
'   You could try something like the code below.
'   As you can see, the actual calculator code is not functional.
'   The input routine works pretty well, though! :)
'_|_|_|   CALCGET$.BAS
'_|_|_|   Example of a method to get calculator-style input.
'_|_|_|   No warrantee or guarantee is given or implied.
'_|_|_|   PUBLIC DOMAIN   by Kurt Kuzba.     (6/19/1997)
DIM CalcWin AS STRING * 16, Nm AS STRING
DIM dec AS INTEGER, clr AS INTEGER
DIM Memory AS DOUBLE, Result AS DOUBLE, Entry AS DOUBLE
clr = 1: Entry = 0: Result = 0: Memory = 0
DO
   CalcWin = RIGHT$(SPACE$(15) + STR$(Entry), 16)
   LOCATE 5, 35: PRINT CalcWin
   DO: K$ = UCASE$(INKEY$)
      K% = INSTR(" 0123456789.+-*/^%=~MRACE" + CHR$(27), K$)
   LOOP WHILE K% < 2: K% = K% - 2
   IF clr > 0 THEN
      Entry = 0: clr = 0
      CalcWin = RIGHT$(SPACE$(15) + STR$(Entry), 16)
      LOCATE 5, 35: PRINT CalcWin
   END IF
   SELECT CASE K%
      CASE IS < 10
         Nm = LTRIM$(CalcWin)
         IF dec > 0 THEN
            IF INSTR(Nm, ".") = 0 THEN Nm = Nm + "."
         END IF
         Nm = Nm + K$: Nm = RIGHT$(Nm, 16): Entry = VAL(Nm)
      CASE 10: dec = 1
      CASE 11   'add
         Result = Result + Entry: Entry = Result: clr = 1
      CASE 12: 'subtract
         Result = Result - Entry: Entry = Result: clr = 1
      CASE 13: 'multiply
      CASE 14: 'divide
      CASE 15: 'square
      CASE 16: 'percent
      CASE 17: 'equal
      CASE 18: 'square root
      CASE 19: 'to memory
      CASE 20: 'recall memory
      CASE 21: 'add to memory
      CASE 22   'Clear
         Entry = 0: Result = 0: dec = 0
      CASE 23   'Clear Entry
         Entry = 0: dec = 0
      CASE 24: EXIT DO
   END SELECT
LOOP
'_|_|_|   end   CALCGET$.BAS
