07-29-2022, 01:00 AM
This should address the backspace issue.
Things to note. I had to add this line to the NUMBER2: sub-routine:
_PRINTSTRING (55, 30), SPACE$(40)
It is absolutely needed to clear the field before the number is printed when backspacing, but also when any result has fewer digits than the previous shown result. Now you may want to use something other than SPACE$(40) that will clear the field.
Next, I also had to make a different way to handle not accepting more than one leading zero in a non-decimal entry.
IMPORTANT: You need to revisit the CLIPBOARD routine. I could easily paste a sequence of like 0000...0.0 and it would be accepted. It would also screw up any attempted calculation.
Anyway, there will probaly be other athings to consider with the other math functions. I'm only checking +-*/.
Pete
Code: (Select All)
'Calculator
'By SierraKen on July 30, 2020.
'Updated on July 24, 2022 with Copy and Paste Buttons.
'Updated on July 26, 2022 with Back Space Button and RND (Random) Button
'-----------------------------------------------------------------------
'This is my very first regular calculator.
'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
'Thank you Dav for the icon code!
_ICON BASIMAGE1&
_TITLE "Calculator - Esc for help."
DIM num AS DOUBLE
SCREEN _NEWIMAGE(400, 525, 32)
f& = _LOADFONT("Arial.ttf", 18)
begin:
_FONT f&
num$ = ""
c = 0
a = 0: s = 0: t = 0: d = 0
'Setup calculator
LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
'Buttons
FOR buttony = 75 TO 405 STEP 55
FOR buttonx = 50 TO 275 STEP 75
FOR bb = 0 TO 10
c = c + 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
NEXT buttonx
NEXT buttony
'Copy Button
buttonx = 50: buttony = 460
FOR bb = 0 TO 10
c = c + 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Paste Button
buttonx = 125: buttony = 460
FOR bb = 0 TO 10
c = c + 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Back Space Button
buttonx = 200: buttony = 460
FOR bb = 0 TO 10
c = c + 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Time Button
buttonx = 275: buttony = 460
FOR bb = 0 TO 10
c = c + 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Green C Button
buttonx = 275: buttony = 20
FOR bb = 0 TO 10
c = c + 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
_PRINTSTRING (50, 5), "Rad"
wer:
'Label Buttons
_PRINTSTRING (306, 47), "C"
COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
_PRINTSTRING (87, 102), CHR$(251) 'square root
_PRINTSTRING (152, 102), "sin"
_PRINTSTRING (227, 102), "cos"
_PRINTSTRING (302, 102), "tan"
_PRINTSTRING (87, 157), "7"
_PRINTSTRING (162, 157), "8"
_PRINTSTRING (237, 157), "9"
_PRINTSTRING (312, 157), "/"
_PRINTSTRING (87, 212), "4"
_PRINTSTRING (162, 212), "5"
_PRINTSTRING (237, 212), "6"
_PRINTSTRING (312, 212), "x"
_PRINTSTRING (87, 267), "1"
_PRINTSTRING (162, 267), "2"
_PRINTSTRING (237, 267), "3"
_PRINTSTRING (312, 267), "-"
_PRINTSTRING (87, 322), "0"
_PRINTSTRING (162, 322), "."
_PRINTSTRING (237, 322), "="
_PRINTSTRING (312, 322), "+"
_PRINTSTRING (79, 377), " "
_PRINTSTRING (79, 377), "deg"
_PRINTSTRING (162, 377), "x" + CHR$(253) 'second power
_PRINTSTRING (227, 377), "log"
_PRINTSTRING (307, 377), "Pi"
_PRINTSTRING (79, 432), "1/x"
_PRINTSTRING (152, 432), "x/2"
_PRINTSTRING (227, 432), "exp"
_PRINTSTRING (312, 432), CHR$(241) 'Postive or Negative
_PRINTSTRING (68, 487), "Copy"
_PRINTSTRING (141, 487), "Paste"
_PRINTSTRING (210, 487), "<Back"
_PRINTSTRING (293, 487), "RND"
COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
DO
_LIMIT 30
a$ = INKEY$
IF a$ <> "" THEN mousex = 0: mousey = 0: mouseLeftButton = 0
IF a$ = CHR$(27) THEN GOTO help:
IF a$ = CHR$(3) THEN a$ = "": GOTO clip: 'Ctrl+C copies to clipboard.
IF a$ = "C" OR a$ = "c" THEN a$ = "": GOTO delete: 'Back Space deletes output.
IF a$ = "p" OR a$ = "P" OR a$ = "n" OR a$ = "N" THEN a$ = "": GOTO posneg: 'Positive or Negative
IF a$ = "f" OR a$ = "F" THEN a$ = "": GOTO fraction:
IF a$ = "h" OR a$ = "H" THEN a$ = "": GOTO half:
IF a$ = "e" OR a$ = "E" THEN a$ = "": GOTO expcommand:
IF a$ = "r" OR a$ = "R" OR a$ = "d" OR a$ = "D" THEN a$ = "": GOTO radanddeg:
IF a$ = "u" OR a$ = "U" THEN a$ = "": GOTO squared:
IF a$ = "l" OR a$ = "L" THEN a$ = "": GOTO logarithm:
IF a$ = "i" OR a$ = "I" THEN a$ = "": GOTO pi:
IF a$ = "q" OR a$ = "Q" THEN a$ = "": GOTO squareroot:
IF a$ = "s" OR a$ = "S" THEN a$ = "": GOTO sine:
IF a$ = "o" OR a$ = "O" THEN a$ = "": GOTO cosine:
IF a$ = "t" OR a$ = "T" THEN a$ = "": GOTO tangent:
IF a$ = "1" THEN a$ = "": GOTO one:
IF a$ = "2" THEN a$ = "": GOTO two:
IF a$ = "3" THEN a$ = "": GOTO three:
IF a$ = "4" THEN a$ = "": GOTO four:
IF a$ = "5" THEN a$ = "": GOTO five:
IF a$ = "6" THEN a$ = "": GOTO six:
IF a$ = "7" THEN a$ = "": GOTO seven:
IF a$ = "8" THEN a$ = "": GOTO eight:
IF a$ = "9" THEN a$ = "": GOTO nine:
IF a$ = "0" THEN a$ = "": GOTO zero2:
IF a$ = "." THEN a$ = "": GOTO decimal:
IF a$ = "=" THEN a$ = "": GOTO equals:
IF a$ = "+" THEN a$ = "": GOTO add:
IF a$ = "-" THEN a$ = "": GOTO subtract:
IF a$ = "*" OR a$ = "x" OR a$ = "X" THEN a$ = "": GOTO multiply:
IF a$ = "/" THEN a$ = "": GOTO divide:
IF a$ = CHR$(8) THEN a$ = "": GOTO backbutton:
WHILE _MOUSEINPUT: WEND
mousex = _MOUSEX
mousey = _MOUSEY
mouseLeftButton = _MOUSEBUTTON(1)
IF mouseLeftButton THEN
Clear_MB 1
'Clipboard
IF mousex > 50 AND mousex < 265 AND mousey > 25 AND mousey < 50 THEN
clip:
COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
_PRINTSTRING (55, 30), num$
_DELAY .5
num2$ = _TRIM$(num$)
_CLIPBOARD$ = num2$
COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
_PRINTSTRING (55, 30), num$
END IF
'Clipboard Button
IF mousex > 50 AND mousex < 125 AND mousey > 460 AND mousey < 515 THEN
clip2:
COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
_PRINTSTRING (55, 30), num$
buttonx = 50: buttony = 460
GOSUB press:
_DELAY .5
num2$ = _TRIM$(num$)
_CLIPBOARD$ = num2$
COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
_PRINTSTRING (55, 30), num$
END IF
'Paste Button
IF mousex > 125 AND mousex < 200 AND mousey > 460 AND mousey < 515 THEN
paste:
buttonx = 125: buttony = 460
GOSUB press:
num$ = _CLIPBOARD$
IF LEN(num$) > 19 THEN num$ = "0"
_PRINTSTRING (55, 30), num$
num = VAL(num$)
GOSUB number:
END IF
'Back Space Button
IF mousex > 200 AND mousex < 275 AND mousey > 460 AND mousey < 515 THEN
backbutton:
buttonx = 200: buttony = 460
GOSUB press:
num$ = LEFT$(num$, LEN(num$) - 1)
GOSUB number2
END IF
'Random Button
IF mousex > 275 AND mousex < 350 AND mousey > 460 AND mousey < 515 THEN
timebutton:
buttonx = 275: buttony = 460
GOSUB press:
num$ = STR$(RND)
_PRINTSTRING (55, 30), num$
num = VAL(num$)
GOSUB number:
END IF
'Clear
IF mousex > 275 AND mousex < 350 AND mousey > 20 AND mousey < 75 THEN
delete:
a = 0: s = 0: t = 0: d = 0: num$ = ""
_PRINTSTRING (55, 30), " "
buttonx = 275: buttony = 20
GOSUB zero:
END IF
'1/x
IF mousex > 50 AND mousex < 125 AND mousey > 405 AND mousey < 460 THEN
fraction:
num = VAL(num$)
IF num = 0 THEN GOTO skipthis:
num = 1 / num
num$ = STR$(num)
skipthis:
buttonx = 50: buttony = 405
GOSUB press:
GOSUB number:
END IF
'x/2
IF mousex > 126 AND mousex < 200 AND mousey > 405 AND mousey < 460 THEN
half:
num = VAL(num$)
num = num / 2
num$ = STR$(num)
buttonx = 126: buttony = 405
GOSUB press:
GOSUB number2:
END IF
'EXP
IF mousex > 200 AND mousex < 275 AND mousey > 405 AND mousey < 460 THEN
expcommand:
_PRINTSTRING (55, 30), " "
num = EXP(VAL(num$))
num$ = STR$(num)
buttonx = 200: buttony = 405
GOSUB number2:
GOSUB press:
END IF
'Postive or Negative
IF mousex > 275 AND mousex < 350 AND mousey > 405 AND mousey < 460 THEN
posneg:
IF VAL(num$) < 0 THEN
num = -VAL(num$)
num$ = STR$(num)
GOTO skipplusnegative:
END IF
num$ = "-" + num$
skipplusnegative:
buttonx = 275: buttony = 405
GOSUB press:
GOSUB number:
END IF
'Radians and Degrees
IF mousex > 50 AND mousex < 125 AND mousey > 350 AND mousey < 405 THEN
radanddeg:
deg = deg + 1
IF deg = 2 THEN GOTO deg2rad:
COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
_PRINTSTRING (79, 377), " "
_PRINTSTRING (79, 377), "rad"
COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
_PRINTSTRING (50, 5), "Deg"
num = VAL(num$)
num = _R2D(num)
num$ = STR$(num)
GOTO skipdeg2rad:
deg2rad:
deg = 0
COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
_PRINTSTRING (79, 377), " "
_PRINTSTRING (79, 377), "deg"
COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
_PRINTSTRING (50, 5), "Rad"
num = VAL(num$)
num = _D2R(num)
num$ = STR$(num)
skipdeg2rad:
buttonx = 50: buttony = 350
GOSUB press:
GOSUB number:
END IF
'Second Power
IF mousex > 126 AND mousex < 200 AND mousey > 350 AND mousey < 405 THEN
squared:
num = VAL(num$)
num = num ^ 2
num$ = STR$(num)
buttonx = 126: buttony = 350
GOSUB press:
GOSUB number2:
END IF
'logarithm
IF mousex > 200 AND mousex < 275 AND mousey > 350 AND mousey < 405 THEN
logarithm:
num = VAL(num$)
IF num = 0 THEN GOTO skiplog:
IF num < 0 THEN GOTO skiplog:
num = LOG(num)
num$ = STR$(num)
skiplog:
buttonx = 200: buttony = 350
GOSUB press:
GOSUB number:
END IF
'Pi
IF mousex > 275 AND mousex < 350 AND mousey > 350 AND mousey < 405 THEN
pi:
'num = 3.14159265359
num = _PI
num$ = STR$(num)
buttonx = 275: buttony = 350
GOSUB press:
GOSUB number:
END IF
'Square Root
IF mousex > 50 AND mousex < 125 AND mousey > 75 AND mousey < 130 THEN
squareroot:
IF num < 0 THEN GOTO skip1:
num = VAL(num$)
num = SQR(num)
num$ = STR$(num)
skip1:
buttonx = 50: buttony = 75
GOSUB press:
GOSUB number:
END IF
'Sine
IF mousex > 126 AND mousex < 200 AND mousey > 75 AND mousey < 130 THEN
sine:
IF deg = 1 THEN num = SIN(_D2R(VAL(num$)))
IF deg = 0 THEN num = SIN(num)
num$ = STR$(num)
buttonx = 126: buttony = 75
GOSUB press:
GOSUB number:
END IF
'Cosine
IF mousex > 200 AND mousex < 275 AND mousey > 75 AND mousey < 130 THEN
cosine:
IF deg = 1 THEN num = COS(_D2R(VAL(num$)))
IF deg = 0 THEN num = COS(num)
num$ = STR$(num)
buttonx = 200: buttony = 75
GOSUB press:
GOSUB number:
END IF
'Tangent
IF mousex > 275 AND mousex < 350 AND mousey > 75 AND mousey < 130 THEN
tangent:
IF deg = 1 THEN num = TAN(_D2R(VAL(num$)))
IF deg = 0 THEN num = TAN(num)
num$ = STR$(num)
buttonx = 275: buttony = 75
GOSUB press:
GOSUB number:
END IF
'Number Buttons
IF mousex > 50 AND mousex < 125 AND mousey > 130 AND mousey < 185 THEN
seven:
num$ = num$ + "7"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 50: buttony = 130
GOSUB press:
GOSUB number:
END IF
IF mousex > 126 AND mousex < 200 AND mousey > 130 AND mousey < 185 THEN
eight:
num$ = num$ + "8"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 126: buttony = 130
GOSUB press:
GOSUB number:
END IF
IF mousex > 200 AND mousex < 275 AND mousey > 130 AND mousey < 185 THEN
nine:
num$ = num$ + "9"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 200: buttony = 130
GOSUB press:
GOSUB number:
END IF
IF mousex > 50 AND mousex < 125 AND mousey > 185 AND mousey < 240 THEN
four:
num$ = num$ + "4"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 50: buttony = 185
GOSUB press:
GOSUB number:
END IF
IF mousex > 126 AND mousex < 200 AND mousey > 185 AND mousey < 240 THEN
five:
num$ = num$ + "5"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 126: buttony = 185
GOSUB press:
GOSUB number:
END IF
IF mousex > 200 AND mousex < 275 AND mousey > 185 AND mousey < 240 THEN
six:
num$ = num$ + "6"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 200: buttony = 185
GOSUB press:
GOSUB number:
END IF
IF mousex > 50 AND mousex < 125 AND mousey > 240 AND mousey < 295 THEN
one:
num$ = num$ + "1"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 50: buttony = 240
GOSUB press:
GOSUB number:
END IF
IF mousex > 126 AND mousex < 200 AND mousey > 240 AND mousey < 295 THEN
two:
num$ = num$ + "2"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 126: buttony = 240
GOSUB press:
GOSUB number:
END IF
IF mousex > 200 AND mousex < 275 AND mousey > 240 AND mousey < 295 THEN
three:
num$ = num$ + "3"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 200: buttony = 240
GOSUB press:
GOSUB number:
END IF
IF mousex > 50 AND mousex < 125 AND mousey > 295 AND mousey < 350 THEN
zero2:
IF num$ <> "0" THEN ' Prevents more than one leading zero input.
num$ = num$ + "0"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 50: buttony = 295
GOSUB press:
GOSUB number:
END IF
END IF
'Decimal
IF mousex > 126 AND mousex < 200 AND mousey > 295 AND mousey < 350 THEN
decimal:
buttonx = 126: buttony = 295
FOR check = 1 TO LEN(num$)
IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
NEXT check
num$ = num$ + "."
_PRINTSTRING (55, 30), num$
skipdec:
GOSUB press:
END IF
'Equals
IF mousex > 200 AND mousex < 275 AND mousey > 295 AND mousey < 350 THEN
equals:
IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
'----------------------------------------------------
num$ = LTRIM$(STR$(num))
'----------------------------------------------------
buttonx = 200: buttony = 295
GOSUB press:
GOSUB number2:
END IF
'Add
IF mousex > 275 AND mousex < 350 AND mousey > 295 AND mousey < 350 THEN
add:
IF a = 0 THEN
d = 0: a = 1: s = 0: t = 0
GOSUB convert: oldnum$ = num$
_PRINTSTRING (55, 30), " "
num$ = ""
GOTO nex4:
END IF
IF a = 1 THEN
num = VAL(oldnum$) + VAL(num$)
a = 0
END IF
GOSUB number2:
nex4:
buttonx = 275: buttony = 295
GOSUB press:
END IF
'Subtract
IF mousex > 275 AND mousex < 350 AND mousey > 240 AND mousey < 295 THEN
subtract:
IF s = 0 THEN
IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
d = 0: a = 0: s = 1: t = 0
GOSUB convert: oldnum$ = num$
_PRINTSTRING (55, 30), " "
num$ = ""
GOTO nex3:
END IF
IF s = 1 THEN
num = VAL(oldnum$) - VAL(num$)
s = 0
END IF
GOSUB number2:
nex3:
buttonx = 275: buttony = 240
GOSUB press:
END IF
'Multiply
IF mousex > 275 AND mousex < 350 AND mousey > 185 AND mousey < 240 THEN
multiply:
IF t = 0 THEN
d = 0: a = 0: s = 0: t = 1
GOSUB convert: oldnum$ = num$
_PRINTSTRING (55, 30), " "
num$ = ""
GOTO nex2:
END IF
IF t = 1 THEN
num = VAL(oldnum$) * VAL(num$)
t = 0
END IF
GOSUB number2:
nex2:
buttonx = 275: buttony = 185
GOSUB press:
END IF
'Divide
IF mousex > 275 AND mousex < 350 AND mousey > 130 AND mousey < 185 THEN
divide:
IF d = 0 THEN
d = 1: a = 0: s = 0: t = 0
GOSUB convert: oldnum$ = num$
_PRINTSTRING (55, 30), " "
num$ = ""
GOTO nex1:
END IF
IF d = 1 AND num$ <> "" THEN
num = VAL(oldnum$) / VAL(num$)
d = 0
END IF
GOSUB number2:
nex1:
buttonx = 275: buttony = 130
GOSUB press:
END IF
END IF
LOOP
'For Number Buttons.
convert:
IF VAL(num$) > 9999999999999999 OR LEN(num$) > 19 THEN
num$ = LEFT$(num$, 19)
END IF
num = VAL(num$)
RETURN
number:
IF VAL(num$) > 9999999999999999 OR LEN(num$) > 19 THEN
num$ = LEFT$(num$, 19)
END IF
'For Math
number2:
COLOR _RGB32(0, 0, 0), _RGB32(0, 0, 0)
_PRINTSTRING (55, 30), SPACE$(40)
IF VAL(num$) > 9999999999999999 OR LEN(num$) > 19 THEN
num$ = LEFT$(num$, 19)
END IF
COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
_PRINTSTRING (55, 30), num$
RETURN
'Pressing Each Button
press:
c = 110
FOR bb = 0 TO 10
c = c - 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
_DELAY .03
FOR bb = 0 TO 10
c = c + 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
RETURN
'Pressing the Green C Button.
zero:
c = 110
FOR bb = 0 TO 10
c = c - 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
NEXT bb
_DELAY .25
FOR bb = 0 TO 10
c = c + 10
LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
NEXT bb
RETURN
help:
_FONT 14
CLS
_TITLE "Calculator Help"
PRINT "Esc = Keyboard Help"
PRINT "CTRL+C = Copies To Clipboard"
PRINT "Left Mouse Click Copies To Clipboard."
PRINT "Copy Button Copies To Clipboard"
PRINT "Paste Button Pastes Clipboard To Screen"
PRINT "Backspace = Deletes Last Output Digit"
PRINT "RND = Makes a random number from 0 to 1."
PRINT "Letters can be upper or lower-case."
PRINT "P or N = Positve and Negative Switch."
PRINT "F = 1 / x"
PRINT "H = x / 2"
PRINT "E = EXP"
PRINT "R or D = Radian and Degree Switch."
PRINT "U = X ^ 2"
PRINT "L = Logarithm"
PRINT "I = Pi"
PRINT "Q = Square Root"
PRINT "s = Sine"
PRINT "o = Cosine"
PRINT "t = Tangent"
PRINT
PRINT "Below can be either Number Pad or the others."
PRINT "1-9 = Number Keys"
PRINT ". = Decimal"
PRINT "= = Equals"
PRINT "+ = Add"
PRINT "- = Subtract"
PRINT "* or X = Multiply"
PRINT "/ = Divide"
PRINT
PRINT "Press Esc to go back to calculator."
DO: LOOP UNTIL INKEY$ = CHR$(27)
CLS
_TITLE "Calculator - Esc for help."
GOTO begin:
'This Function is from Dav which makes the icon picture. It uses code at the start of this program.
FUNCTION BASIMAGE1& 'calculatio icon data
v& = _NEWIMAGE(54, 48, 32)
DIM m AS _MEM: m = _MEMIMAGE(v&)
A$ = ""
A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
btemp$ = ""
FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
IF INSTR(1, B$, "%") THEN
FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
IF F$ <> "%" THEN C$ = C$ + F$
NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
IF MID$(B$, j, 1) = "#" THEN
MID$(B$, j) = "@": END IF: NEXT
FOR t% = LEN(B$) TO 1 STEP -1
B& = B& * 64 + ASC(MID$(B$, t%)) - 48
NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
NEXT: btemp$ = btemp$ + X$: NEXT
btemp$ = _INFLATE$(btemp$)
_MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
END FUNCTION
SUB Clear_MB (var AS INTEGER)
DO UNTIL NOT _MOUSEBUTTON(var)
WHILE _MOUSEINPUT: WEND
LOOP
END SUB 'Clear_MB
Things to note. I had to add this line to the NUMBER2: sub-routine:
_PRINTSTRING (55, 30), SPACE$(40)
It is absolutely needed to clear the field before the number is printed when backspacing, but also when any result has fewer digits than the previous shown result. Now you may want to use something other than SPACE$(40) that will clear the field.
Next, I also had to make a different way to handle not accepting more than one leading zero in a non-decimal entry.
IMPORTANT: You need to revisit the CLIPBOARD routine. I could easily paste a sequence of like 0000...0.0 and it would be accepted. It would also screw up any attempted calculation.
Anyway, there will probaly be other athings to consider with the other math functions. I'm only checking +-*/.
Pete