'Calculator
'By SierraKen on July 30, 2020.
'------------------------------
'This is my very first regular calculator.
'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
'This was a 4 day project and I've wanted to make this all my life. Ever since I was real little
'playing around with my parents' calculator.
'Thank you Dav for the icon code!
'Added Clipboard by clicking the output number.
'Added Rad2Deg (and Deg2Rad), second power, Base 10 Logarithm, and Pi buttons.
'Added 1/x, x/2, exp, postive or negative.
'Added keyboard control and help page.
'Load the icon - call this somewhere near the top of your program
_TITLE "Calculator - Esc for help." begin:
num$ = ""
c = 0
a = 0: s = 0: t = 0: d = 0
'Setup calculator
LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
'Buttons
c = c + 10
LINE (buttonx
+ bb
, buttony
+ bb
)-(buttonx
+ 75 - bb
, buttony
+ 55 - bb
), _RGB32(100 + c
, 100 + c
, 100 + c
), B
PAINT (buttonx
+ 12, buttony
+ 12), _RGB32(100 + c
, 100 + c
, 100 + c
) c = 0
buttonx = 275: buttony = 20
'Green C Button
c = c + 10
LINE (buttonx
+ bb
, buttony
+ bb
)-(buttonx
+ 75 - bb
, buttony
+ 55 - bb
), _RGB32(50, 100 + c
, 50), B
PAINT (buttonx
+ 12, buttony
+ 12), _RGB32(50, 100 + c
, 50) wer:
'Label Buttons
IF a$
<> "" THEN mousex
= 0: mousey
= 0: mouseLeftButton
= 0 IF a$
= CHR$(8) 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
mouseLeftButton = 0
'Clipboard
clip:
'Clear
delete:
a = 0: s = 0: t = 0: d = 0: num$ = ""
buttonx = 275: buttony = 20
'1/x
fraction:
num = 1 / num
skipthis:
buttonx = 50: buttony = 405
'x/2
half:
num = num / 2
buttonx = 126: buttony = 405
'EXP
expcommand:
buttonx = 200: buttony = 405
'Postive or Negative
posneg:
num$ = "-" + num$
skipplusnegative:
buttonx = 275: buttony = 405
'Radians and Degrees
radanddeg:
deg = deg + 1
deg2rad:
deg = 0
skipdeg2rad:
buttonx = 50: buttony = 350
'Second Power
squared:
num = num ^ 2
buttonx = 126: buttony = 350
'logarithm
logarithm:
skiplog:
buttonx = 200: buttony = 350
'Pi
pi:
buttonx = 275: buttony = 350
'Square Root
squareroot:
skip1:
buttonx = 50: buttony = 75
'Sine
sine:
buttonx = 126: buttony = 75
'Cosine
cosine:
buttonx = 200: buttony = 75
'Tangent
tangent:
buttonx = 275: buttony = 75
'Number Buttons
seven:
num$ = num$ + "7"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 50: buttony = 130
eight:
num$ = num$ + "8"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 126: buttony = 130
nine:
num$ = num$ + "9"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 200: buttony = 130
four:
num$ = num$ + "4"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 50: buttony = 185
five:
num$ = num$ + "5"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 126: buttony = 185
six:
num$ = num$ + "6"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 200: buttony = 185
one:
num$ = num$ + "1"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 50: buttony = 240
two:
num$ = num$ + "2"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 126: buttony = 240
three:
num$ = num$ + "3"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 200: buttony = 240
zero2:
num$ = num$ + "0"
IF n
= 1 THEN num$
= "-" + num$: n
= 0 buttonx = 50: buttony = 295
'Decimal
decimal:
buttonx = 126: buttony = 295
num$ = num$ + "."
skipdec:
'Equals
equals:
buttonx = 200: buttony = 295
'Add
add:
d = 0: a = 1: s = 0: t = 0
oldnum$ = num$
num$ = ""
num
= VAL(oldnum$
) + VAL(num$
) a = 0
nex4:
buttonx = 275: buttony = 295
'Subtract
subtract:
d = 0: a = 0: s = 1: t = 0
oldnum$ = num$
num$ = ""
num
= VAL(oldnum$
) - VAL(num$
) s = 0
nex3:
buttonx = 275: buttony = 240
'Multiply
multiply:
d = 0: a = 0: s = 0: t = 1
oldnum$ = num$
num$ = ""
num
= VAL(oldnum$
) * VAL(num$
) t = 0
nex2:
buttonx = 275: buttony = 185
'Divide
divide:
d = 1: a = 0: s = 0: t = 0
oldnum$ = num$
num$ = ""
num
= VAL(oldnum$
) / VAL(num$
) d = 0
nex1:
buttonx = 275: buttony = 130
'For Number Buttons.
number:
'For Math
number2:
'Pressing Each Button
press:
c = 110
c = c - 10
LINE (buttonx
+ bb
, buttony
+ bb
)-(buttonx
+ 75 - bb
, buttony
+ 55 - bb
), _RGB32(100 + c
, 100 + c
, 100 + c
), B
c = c + 10
LINE (buttonx
+ bb
, buttony
+ bb
)-(buttonx
+ 75 - bb
, buttony
+ 55 - bb
), _RGB32(100 + c
, 100 + c
, 100 + c
), B
'Pressing the Green C Button.
zero:
c = 110
c = c - 10
LINE (buttonx
+ bb
, buttony
+ bb
)-(buttonx
+ 75 - bb
, buttony
+ 55 - bb
), _RGB32(50, 100 + c
, 50), B
c = c + 10
LINE (buttonx
+ bb
, buttony
+ bb
)-(buttonx
+ 75 - bb
, buttony
+ 55 - bb
), _RGB32(50, 100 + c
, 50), B
help:
PRINT "Esc = Keyboard Help" PRINT "CTRL+C = Copies Output To Clipboard" PRINT "Left Mouse Click Output Copies To Clipboard." PRINT "Backspace = Deletes Output" PRINT "Letters can be upper or lower-case." PRINT "P or N = Positve and Negative Switch." PRINT "R or D = Radian and Degree Switch." PRINT "Below can be either Number Pad or the others." PRINT "1-9 = Number Keys" PRINT "* or X = Multiply" PRINT "Press Esc to go back to calculator." _TITLE "Calculator - Esc for help."
'This Function is from Dav which makes the icon picture. It uses code at the start of this program.
FUNCTION BASIMAGE1&
'calculatio icon data A$ = ""
A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A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