QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on July 28, 2020, 03:17:08 pm

Title: Calculator
Post by: SierraKen on July 28, 2020, 03:17:08 pm
Well, I did it.. lol. It took 3 days and some help from B+ on how to add the decimal point. B+, you were right, I didn't need your Function but what you did teach me is how to keep everything as a string, and that worked out perfectly. Thank you! Tempodibasic, you helped me a lot too in realizing that my "spaghetti code" was causing a lot of frustration so I labeled almost everything in the program and made it a lot easier to understand. I made this second topic because I want people to find the calculator easier with the Subject as just "Calculator". I'll put the URL to the topic where you guys helped me below. If for some reason anyone finds an error or problem, please tell me. I've tested it quite a bit but it's possible there are one or more sequences I haven't tested yet. I'll post a picture of it below too. Thanks again! Oh, and OldMoses, I made the buttons 3D like that by using loops while changing the shade color on a bunch of rectangles. You can see it under "Buttons". Thanks again guys, I feel great!

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 28, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 3 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8.  
  9. _TITLE "Calculator"
  10. SCREEN _NEWIMAGE(400, 400, 32)
  11. 'Setup calculator
  12. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  13. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  14. 'Buttons
  15. FOR buttony = 75 TO 295 STEP 55
  16.     FOR buttonx = 50 TO 275 STEP 75
  17.         FOR bb = 0 TO 10
  18.             c = c + 10
  19.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  20.         NEXT bb
  21.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  22.         c = 0
  23.     NEXT buttonx
  24. NEXT buttony
  25. buttonx = 275: buttony = 20
  26. 'Green C Button
  27. FOR bb = 0 TO 10
  28.     c = c + 10
  29.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  30. NEXT bb
  31. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  32. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  33. c = 0
  34. 'Label Buttons
  35. _PRINTSTRING (312, 47), "C"
  36. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  37. _PRINTSTRING (87, 102), CHR$(251) 'square root
  38. _PRINTSTRING (152, 102), "sin"
  39. _PRINTSTRING (227, 102), "cos"
  40. _PRINTSTRING (302, 102), "tan"
  41. _PRINTSTRING (87, 157), "7"
  42. _PRINTSTRING (162, 157), "8"
  43. _PRINTSTRING (237, 157), "9"
  44. _PRINTSTRING (312, 157), "/"
  45. _PRINTSTRING (87, 212), "4"
  46. _PRINTSTRING (162, 212), "5"
  47. _PRINTSTRING (237, 212), "6"
  48. _PRINTSTRING (312, 212), "x"
  49. _PRINTSTRING (87, 267), "1"
  50. _PRINTSTRING (162, 267), "2"
  51. _PRINTSTRING (237, 267), "3"
  52. _PRINTSTRING (312, 267), "-"
  53. _PRINTSTRING (87, 322), "0"
  54. _PRINTSTRING (162, 322), "."
  55. _PRINTSTRING (237, 322), "="
  56. _PRINTSTRING (312, 322), "+"
  57. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  58.     _LIMIT 20
  59.         mouseX = _MOUSEX
  60.         mouseY = _MOUSEY
  61.         mouseLeftButton = _MOUSEBUTTON(1)
  62.     LOOP
  63.     IF mouseLeftButton THEN
  64.         mouseLeftButton = 0
  65.  
  66.         'Clear
  67.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  68.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  69.             _PRINTSTRING (55, 30), "                          "
  70.             buttonx = 275: buttony = 20
  71.             GOSUB zero:
  72.         END IF
  73.  
  74.         'Square Root
  75.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  76.             IF num < 0 THEN GOTO skip1:
  77.             num = VAL(num$)
  78.             num = SQR(num)
  79.             num$ = STR$(num)
  80.             skip1:
  81.             buttonx = 50: buttony = 75
  82.             GOSUB press:
  83.             GOSUB number:
  84.         END IF
  85.  
  86.         'Sine
  87.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  88.             num = VAL(num$)
  89.             num = SIN(num)
  90.             num$ = STR$(num)
  91.             buttonx = 126: buttony = 75
  92.             GOSUB press:
  93.             GOSUB number:
  94.         END IF
  95.  
  96.         'Cosine
  97.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  98.             num = VAL(num$)
  99.             num = COS(num)
  100.             num$ = STR$(num)
  101.             buttonx = 200: buttony = 75
  102.             GOSUB press:
  103.             GOSUB number:
  104.         END IF
  105.  
  106.         'Tangent
  107.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  108.             num = VAL(num$)
  109.             num = TAN(num)
  110.             num$ = STR$(num)
  111.             buttonx = 275: buttony = 75
  112.             GOSUB press:
  113.             GOSUB number:
  114.         END IF
  115.  
  116.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  117.             num$ = num$ + "7"
  118.             IF n = 1 THEN num$ = "-" + num$: n = 0
  119.             buttonx = 50: buttony = 130
  120.             GOSUB press:
  121.             GOSUB number:
  122.         END IF
  123.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  124.             num$ = num$ + "8"
  125.             IF n = 1 THEN num$ = "-" + num$: n = 0
  126.             buttonx = 126: buttony = 130
  127.             GOSUB press:
  128.             GOSUB number:
  129.         END IF
  130.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  131.             num$ = num$ + "9"
  132.             IF n = 1 THEN num$ = "-" + num$: n = 0
  133.             buttonx = 200: buttony = 130
  134.             GOSUB press:
  135.             GOSUB number:
  136.         END IF
  137.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  138.             num$ = num$ + "4"
  139.             IF n = 1 THEN num$ = "-" + num$: n = 0
  140.             buttonx = 50: buttony = 185
  141.             GOSUB press:
  142.             GOSUB number:
  143.         END IF
  144.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  145.             num$ = num$ + "5"
  146.             IF n = 1 THEN num$ = "-" + num$: n = 0
  147.             buttonx = 126: buttony = 185
  148.             GOSUB press:
  149.             GOSUB number:
  150.         END IF
  151.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  152.             num$ = num$ + "6"
  153.             IF n = 1 THEN num$ = "-" + num$: n = 0
  154.             buttonx = 200: buttony = 185
  155.             GOSUB press:
  156.             GOSUB number:
  157.         END IF
  158.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  159.             num$ = num$ + "1"
  160.             IF n = 1 THEN num$ = "-" + num$: n = 0
  161.             buttonx = 50: buttony = 240
  162.             GOSUB press:
  163.             GOSUB number:
  164.         END IF
  165.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  166.             num$ = num$ + "2"
  167.             IF n = 1 THEN num$ = "-" + num$: n = 0
  168.             buttonx = 126: buttony = 240
  169.             GOSUB press:
  170.             GOSUB number:
  171.         END IF
  172.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  173.             num$ = num$ + "3"
  174.             IF n = 1 THEN num$ = "-" + num$: n = 0
  175.             buttonx = 200: buttony = 240
  176.             GOSUB press:
  177.             GOSUB number:
  178.         END IF
  179.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  180.             num$ = num$ + "0"
  181.             IF n = 1 THEN num$ = "-" + num$: n = 0
  182.             buttonx = 50: buttony = 295
  183.             GOSUB press:
  184.             GOSUB number:
  185.         END IF
  186.  
  187.         'Decimal
  188.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  189.             buttonx = 126: buttony = 295
  190.             FOR check = 1 TO LEN(num$)
  191.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  192.             NEXT check
  193.             num$ = num$ + "."
  194.             _PRINTSTRING (55, 30), num$
  195.             skipdec:
  196.             GOSUB press:
  197.         END IF
  198.  
  199.         'Equals
  200.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  201.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  202.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  203.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  204.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  205.             buttonx = 200: buttony = 295
  206.             GOSUB press:
  207.             GOSUB number2:
  208.         END IF
  209.  
  210.         'Add
  211.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  212.             IF a = 0 THEN
  213.                 d = 0: a = 1: s = 0: t = 0
  214.                 oldnum$ = num$
  215.                 calc = 1
  216.                 _PRINTSTRING (55, 30), "                          "
  217.                 num$ = ""
  218.                 GOTO nex4:
  219.             END IF
  220.             IF a = 1 THEN
  221.                 num = VAL(oldnum$) + VAL(num$)
  222.                 a = 0
  223.             END IF
  224.             calc = 0
  225.             GOSUB number2:
  226.             nex4:
  227.             buttonx = 275: buttony = 295
  228.             GOSUB press:
  229.         END IF
  230.  
  231.         'Subtract
  232.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  233.             IF s = 0 THEN
  234.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  235.                 d = 0: a = 0: s = 1: t = 0
  236.                 oldnum$ = num$
  237.                 calc = 1
  238.                 _PRINTSTRING (55, 30), "                          "
  239.                 num$ = ""
  240.                 GOTO nex3:
  241.             END IF
  242.             IF s = 1 THEN
  243.                 num = VAL(oldnum$) - VAL(num$)
  244.                 s = 0
  245.             END IF
  246.             calc = 0
  247.             GOSUB number2:
  248.             nex3:
  249.             buttonx = 275: buttony = 240
  250.             GOSUB press:
  251.         END IF
  252.  
  253.         'Multiply
  254.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  255.             IF t = 0 THEN
  256.                 d = 0: a = 0: s = 0: t = 1
  257.                 oldnum$ = num$
  258.                 calc = 1
  259.                 _PRINTSTRING (55, 30), "                          "
  260.                 num$ = ""
  261.                 GOTO nex2:
  262.             END IF
  263.             IF t = 1 THEN
  264.                 num = VAL(oldnum$) * VAL(num$)
  265.                 t = 0
  266.             END IF
  267.             calc = 0
  268.             GOSUB number2:
  269.             nex2:
  270.             buttonx = 275: buttony = 185
  271.             GOSUB press:
  272.         END IF
  273.  
  274.         'Divide
  275.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  276.             IF d = 0 THEN
  277.                 d = 1: a = 0: s = 0: t = 0
  278.                 oldnum$ = num$
  279.                 calc = 1
  280.                 _PRINTSTRING (55, 30), "                          "
  281.                 num$ = ""
  282.                 GOTO nex1:
  283.             END IF
  284.             IF d = 1 AND num$ <> "" THEN
  285.                 num = VAL(oldnum$) / VAL(num$)
  286.                 d = 0
  287.             END IF
  288.             calc = 0
  289.             GOSUB number2:
  290.             nex1:
  291.             buttonx = 275: buttony = 130
  292.             GOSUB press:
  293.         END IF
  294.     END IF
  295. 'For Number Buttons.
  296. number:
  297. num = VAL(num$)
  298.  
  299. 'For Math
  300. number2:
  301. _PRINTSTRING (55, 30), "                          "
  302. num$ = STR$(num)
  303. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  304. _PRINTSTRING (55, 30), num$
  305.  
  306.  
  307. 'Pressing Each Button
  308. press:
  309. c = 110
  310. FOR bb = 0 TO 10
  311.     c = c - 10
  312.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  313. NEXT bb
  314. _DELAY .25
  315. FOR bb = 0 TO 10
  316.     c = c + 10
  317.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  318. NEXT bb
  319.  
  320. 'Pressing the Green C Button.
  321. zero:
  322. c = 110
  323. FOR bb = 0 TO 10
  324.     c = c - 10
  325.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  326. NEXT bb
  327. _DELAY .25
  328. FOR bb = 0 TO 10
  329.     c = c + 10
  330.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  331. NEXT bb
  332.  


Here is the forum topic of you guys helping me: https://www.qb64.org/forum/index.php?topic=2862.new (https://www.qb64.org/forum/index.php?topic=2862.new)
Title: Re: Calculator
Post by: SpriggsySpriggs on July 28, 2020, 04:00:21 pm
That looks quite good. I'll have to try it out
Title: Re: Calculator
Post by: Dav on July 28, 2020, 04:57:52 pm
Nicely done, Ken!  Works so good it almost made me cry (because I used it to calculate my income for the month).  I plan to keep this in my QB64 folder for quick calculations, so I made a quick icon for it and put it in the code.  Here that is if you would like it.  Just add it in the code (no external .ico needed)

- Dav

Code: QB64: [Select]
  1. 'Load the icon - call this somewhere near the top of your program
  2. _ICON BASIMAGE1&
  3.  
  4.  
  5. FUNCTION BASIMAGE1& 'calculatio icon data
  6.     v& = _NEWIMAGE(54, 48, 32)
  7.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  8.     A$ = ""
  9.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  10.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  11.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  12.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  13.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  14.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  15.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  16.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  17.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  18.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  19.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  20.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  21.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  22.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  23.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  24.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  25.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  26.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  27.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  28.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  29.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  30.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  31.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  32.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  33.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  34.     btemp$ = ""
  35.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  36.         IF INSTR(1, B$, "%") THEN
  37.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  38.                 IF F$ <> "%" THEN C$ = C$ + F$
  39.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  40.             IF MID$(B$, j, 1) = "#" THEN
  41.         MID$(B$, j) = "@": END IF: NEXT
  42.         FOR t% = LEN(B$) TO 1 STEP -1
  43.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  44.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  45.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  46.     NEXT: btemp$ = btemp$ + X$: NEXT
  47.     btemp$ = _INFLATE$(btemp$)
  48.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  49.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  50.  
Title: Re: Calculator
Post by: FellippeHeitor on July 28, 2020, 05:03:06 pm
Cool buttons, Ken!
Title: Re: Calculator
Post by: SierraKen on July 28, 2020, 08:34:04 pm
Thanks Dav! I just added it and will put the updated version below with that code. I guess it's only supposed to show up on the program itself when running right? Not as a Windows icon for stuff like Windows Shortcuts? But it's still really cool, thank you! I usually use the yellow star icon for my own programs for their Windows shortcuts anyway.

Thank you Felippe! The buttons came out better than I expected. :)

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 28, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 3 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8. 'Thank you Dav for the icon code!
  9.  
  10. 'Load the icon - call this somewhere near the top of your program
  11. _ICON BASIMAGE1&
  12.  
  13. _TITLE "Calculator"
  14. SCREEN _NEWIMAGE(400, 400, 32)
  15.  
  16. 'Setup calculator
  17. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  18. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  19. 'Buttons
  20. FOR buttony = 75 TO 295 STEP 55
  21.     FOR buttonx = 50 TO 275 STEP 75
  22.         FOR bb = 0 TO 10
  23.             c = c + 10
  24.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  25.         NEXT bb
  26.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  27.         c = 0
  28.     NEXT buttonx
  29. NEXT buttony
  30. buttonx = 275: buttony = 20
  31. 'Green C Button
  32. FOR bb = 0 TO 10
  33.     c = c + 10
  34.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  35. NEXT bb
  36. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  37. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  38. c = 0
  39. 'Label Buttons
  40. _PRINTSTRING (312, 47), "C"
  41. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  42. _PRINTSTRING (87, 102), CHR$(251) 'square root
  43. _PRINTSTRING (152, 102), "sin"
  44. _PRINTSTRING (227, 102), "cos"
  45. _PRINTSTRING (302, 102), "tan"
  46. _PRINTSTRING (87, 157), "7"
  47. _PRINTSTRING (162, 157), "8"
  48. _PRINTSTRING (237, 157), "9"
  49. _PRINTSTRING (312, 157), "/"
  50. _PRINTSTRING (87, 212), "4"
  51. _PRINTSTRING (162, 212), "5"
  52. _PRINTSTRING (237, 212), "6"
  53. _PRINTSTRING (312, 212), "x"
  54. _PRINTSTRING (87, 267), "1"
  55. _PRINTSTRING (162, 267), "2"
  56. _PRINTSTRING (237, 267), "3"
  57. _PRINTSTRING (312, 267), "-"
  58. _PRINTSTRING (87, 322), "0"
  59. _PRINTSTRING (162, 322), "."
  60. _PRINTSTRING (237, 322), "="
  61. _PRINTSTRING (312, 322), "+"
  62. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  63.     _LIMIT 20
  64.         mouseX = _MOUSEX
  65.         mouseY = _MOUSEY
  66.         mouseLeftButton = _MOUSEBUTTON(1)
  67.     LOOP
  68.     IF mouseLeftButton THEN
  69.         mouseLeftButton = 0
  70.  
  71.         'Clear
  72.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  73.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  74.             _PRINTSTRING (55, 30), "                          "
  75.             buttonx = 275: buttony = 20
  76.             GOSUB zero:
  77.         END IF
  78.  
  79.         'Square Root
  80.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  81.             IF num < 0 THEN GOTO skip1:
  82.             num = VAL(num$)
  83.             num = SQR(num)
  84.             num$ = STR$(num)
  85.             skip1:
  86.             buttonx = 50: buttony = 75
  87.             GOSUB press:
  88.             GOSUB number:
  89.         END IF
  90.  
  91.         'Sine
  92.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  93.             num = VAL(num$)
  94.             num = SIN(num)
  95.             num$ = STR$(num)
  96.             buttonx = 126: buttony = 75
  97.             GOSUB press:
  98.             GOSUB number:
  99.         END IF
  100.  
  101.         'Cosine
  102.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  103.             num = VAL(num$)
  104.             num = COS(num)
  105.             num$ = STR$(num)
  106.             buttonx = 200: buttony = 75
  107.             GOSUB press:
  108.             GOSUB number:
  109.         END IF
  110.  
  111.         'Tangent
  112.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  113.             num = VAL(num$)
  114.             num = TAN(num)
  115.             num$ = STR$(num)
  116.             buttonx = 275: buttony = 75
  117.             GOSUB press:
  118.             GOSUB number:
  119.         END IF
  120.  
  121.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  122.             num$ = num$ + "7"
  123.             IF n = 1 THEN num$ = "-" + num$: n = 0
  124.             buttonx = 50: buttony = 130
  125.             GOSUB press:
  126.             GOSUB number:
  127.         END IF
  128.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  129.             num$ = num$ + "8"
  130.             IF n = 1 THEN num$ = "-" + num$: n = 0
  131.             buttonx = 126: buttony = 130
  132.             GOSUB press:
  133.             GOSUB number:
  134.         END IF
  135.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  136.             num$ = num$ + "9"
  137.             IF n = 1 THEN num$ = "-" + num$: n = 0
  138.             buttonx = 200: buttony = 130
  139.             GOSUB press:
  140.             GOSUB number:
  141.         END IF
  142.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  143.             num$ = num$ + "4"
  144.             IF n = 1 THEN num$ = "-" + num$: n = 0
  145.             buttonx = 50: buttony = 185
  146.             GOSUB press:
  147.             GOSUB number:
  148.         END IF
  149.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  150.             num$ = num$ + "5"
  151.             IF n = 1 THEN num$ = "-" + num$: n = 0
  152.             buttonx = 126: buttony = 185
  153.             GOSUB press:
  154.             GOSUB number:
  155.         END IF
  156.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  157.             num$ = num$ + "6"
  158.             IF n = 1 THEN num$ = "-" + num$: n = 0
  159.             buttonx = 200: buttony = 185
  160.             GOSUB press:
  161.             GOSUB number:
  162.         END IF
  163.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  164.             num$ = num$ + "1"
  165.             IF n = 1 THEN num$ = "-" + num$: n = 0
  166.             buttonx = 50: buttony = 240
  167.             GOSUB press:
  168.             GOSUB number:
  169.         END IF
  170.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  171.             num$ = num$ + "2"
  172.             IF n = 1 THEN num$ = "-" + num$: n = 0
  173.             buttonx = 126: buttony = 240
  174.             GOSUB press:
  175.             GOSUB number:
  176.         END IF
  177.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  178.             num$ = num$ + "3"
  179.             IF n = 1 THEN num$ = "-" + num$: n = 0
  180.             buttonx = 200: buttony = 240
  181.             GOSUB press:
  182.             GOSUB number:
  183.         END IF
  184.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  185.             num$ = num$ + "0"
  186.             IF n = 1 THEN num$ = "-" + num$: n = 0
  187.             buttonx = 50: buttony = 295
  188.             GOSUB press:
  189.             GOSUB number:
  190.         END IF
  191.  
  192.         'Decimal
  193.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  194.             buttonx = 126: buttony = 295
  195.             FOR check = 1 TO LEN(num$)
  196.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  197.             NEXT check
  198.             num$ = num$ + "."
  199.             _PRINTSTRING (55, 30), num$
  200.             skipdec:
  201.             GOSUB press:
  202.         END IF
  203.  
  204.         'Equals
  205.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  206.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  207.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  208.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  209.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  210.             buttonx = 200: buttony = 295
  211.             GOSUB press:
  212.             GOSUB number2:
  213.         END IF
  214.  
  215.         'Add
  216.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  217.             IF a = 0 THEN
  218.                 d = 0: a = 1: s = 0: t = 0
  219.                 oldnum$ = num$
  220.                 calc = 1
  221.                 _PRINTSTRING (55, 30), "                          "
  222.                 num$ = ""
  223.                 GOTO nex4:
  224.             END IF
  225.             IF a = 1 THEN
  226.                 num = VAL(oldnum$) + VAL(num$)
  227.                 a = 0
  228.             END IF
  229.             calc = 0
  230.             GOSUB number2:
  231.             nex4:
  232.             buttonx = 275: buttony = 295
  233.             GOSUB press:
  234.         END IF
  235.  
  236.         'Subtract
  237.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  238.             IF s = 0 THEN
  239.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  240.                 d = 0: a = 0: s = 1: t = 0
  241.                 oldnum$ = num$
  242.                 calc = 1
  243.                 _PRINTSTRING (55, 30), "                          "
  244.                 num$ = ""
  245.                 GOTO nex3:
  246.             END IF
  247.             IF s = 1 THEN
  248.                 num = VAL(oldnum$) - VAL(num$)
  249.                 s = 0
  250.             END IF
  251.             calc = 0
  252.             GOSUB number2:
  253.             nex3:
  254.             buttonx = 275: buttony = 240
  255.             GOSUB press:
  256.         END IF
  257.  
  258.         'Multiply
  259.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  260.             IF t = 0 THEN
  261.                 d = 0: a = 0: s = 0: t = 1
  262.                 oldnum$ = num$
  263.                 calc = 1
  264.                 _PRINTSTRING (55, 30), "                          "
  265.                 num$ = ""
  266.                 GOTO nex2:
  267.             END IF
  268.             IF t = 1 THEN
  269.                 num = VAL(oldnum$) * VAL(num$)
  270.                 t = 0
  271.             END IF
  272.             calc = 0
  273.             GOSUB number2:
  274.             nex2:
  275.             buttonx = 275: buttony = 185
  276.             GOSUB press:
  277.         END IF
  278.  
  279.         'Divide
  280.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  281.             IF d = 0 THEN
  282.                 d = 1: a = 0: s = 0: t = 0
  283.                 oldnum$ = num$
  284.                 calc = 1
  285.                 _PRINTSTRING (55, 30), "                          "
  286.                 num$ = ""
  287.                 GOTO nex1:
  288.             END IF
  289.             IF d = 1 AND num$ <> "" THEN
  290.                 num = VAL(oldnum$) / VAL(num$)
  291.                 d = 0
  292.             END IF
  293.             calc = 0
  294.             GOSUB number2:
  295.             nex1:
  296.             buttonx = 275: buttony = 130
  297.             GOSUB press:
  298.         END IF
  299.     END IF
  300. 'For Number Buttons.
  301. number:
  302. num = VAL(num$)
  303.  
  304. 'For Math
  305. number2:
  306. _PRINTSTRING (55, 30), "                          "
  307. num$ = STR$(num)
  308. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  309. _PRINTSTRING (55, 30), num$
  310.  
  311.  
  312. 'Pressing Each Button
  313. press:
  314. c = 110
  315. FOR bb = 0 TO 10
  316.     c = c - 10
  317.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  318. NEXT bb
  319. _DELAY .25
  320. FOR bb = 0 TO 10
  321.     c = c + 10
  322.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  323. NEXT bb
  324.  
  325. 'Pressing the Green C Button.
  326. zero:
  327. c = 110
  328. FOR bb = 0 TO 10
  329.     c = c - 10
  330.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  331. NEXT bb
  332. _DELAY .25
  333. FOR bb = 0 TO 10
  334.     c = c + 10
  335.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  336. NEXT bb
  337.  
  338. FUNCTION BASIMAGE1& 'calculatio icon data
  339.     v& = _NEWIMAGE(54, 48, 32)
  340.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  341.     A$ = ""
  342.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  343.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  344.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  345.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  346.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  347.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  348.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  349.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  350.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  351.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  352.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  353.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  354.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  355.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  356.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  357.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  358.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  359.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  360.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  361.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  362.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  363.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  364.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  365.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  366.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  367.     btemp$ = ""
  368.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  369.         IF INSTR(1, B$, "%") THEN
  370.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  371.                 IF F$ <> "%" THEN C$ = C$ + F$
  372.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  373.             IF MID$(B$, j, 1) = "#" THEN
  374.         MID$(B$, j) = "@": END IF: NEXT
  375.         FOR t% = LEN(B$) TO 1 STEP -1
  376.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  377.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  378.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  379.     NEXT: btemp$ = btemp$ + X$: NEXT
  380.     btemp$ = _INFLATE$(btemp$)
  381.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  382.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  383.  
Title: Re: Calculator
Post by: Dav on July 28, 2020, 09:08:30 pm
That's correct - the icon won't be seen by windows and not available for shortcuts.  That's the downside.  On the plus side however you don't need external image to have an icon when the program is running.  I can attach an icon image later if you'd like have it also (I'm on another pc at the moment)..

I've been playing with animated icons using this technique.  Remember the QBV video format player a while back?  I added _ICON later on where it _ICON'ed each frame image, so a mini movie played in the task bar, even when the video was minimized.  Worked great.

I agree with Fellippe - cool buttons!

- Dav
Title: Re: Calculator
Post by: SierraKen on July 28, 2020, 09:23:34 pm
Awesome Dav. But nah, no need for an .ico. People can just choose one of the Windows ones they have on their Properties list if they want something different for Windows. :) Usually when I have a choice between 1 file or more, I pick just the 1 .bas file.
Title: Re: Calculator
Post by: Dav on July 28, 2020, 10:34:58 pm
Come to think of it - you may not need my icon stuff added at all.  Just do an _ICON _DISPLAY after drawing your calculator and that would look just as good.  Instant icon.  That would be a cool trick I suppose for showing game play in the task bar when playing games.

- Dav
Title: Re: Calculator
Post by: SierraKen on July 28, 2020, 10:48:39 pm
Yeah true. But I'm sticking with your code just so I don't need 2 files. Would be nice for people making their own icons.
Title: Re: Calculator
Post by: SierraKen on July 28, 2020, 10:50:01 pm
Unless you want me to remove it?
Title: Re: Calculator
Post by: OldMoses on July 28, 2020, 11:05:39 pm
For your trig functions, don't forget that SIN, COS & TAN work with radians natively in QB64. If you want to use degrees, you'll have to use _D2R, or _PI / 180 in the calculation.

BTW, I like those buttons so well, I incorporated a modification of your algorithm in my solar system simulator. They have a cool 3D look to them, and really make the controls 'pop'.
Title: Re: Calculator
Post by: SierraKen on July 28, 2020, 11:13:23 pm
Awesome OldMoses!! Yeah, I like the radians better for us programmers. :) Maybe someday I'll make a bigger calculator and make a button to auto-convert radians to degrees. Some people here have made incredible calculators, like the TI one I saw from a couple years ago or so. :)
Title: Re: Calculator
Post by: SierraKen on July 28, 2020, 11:28:29 pm
I'm learning new stuff every day! I just found the _CLIPBOARD$ command on the Wiki so I added that. If you left click the output number, the number will turn green for 1 second and it will put it as your Windows Clipboard where you can paste as any text on any other program that has Paste for text. If you want to see the commands I used, it's right after the Mouse commands near the start of the main loop. I also added those instructions in the _TITLE so people know.
Here is the update:

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 28, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 3 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8. 'Thank you Dav for the icon code!
  9. 'Just added Clipboard by clicking the output number.
  10.  
  11. 'Load the icon - call this somewhere near the top of your program
  12. _ICON BASIMAGE1&
  13.  
  14. _TITLE "Calculator - Click output to copy."
  15. SCREEN _NEWIMAGE(400, 400, 32)
  16.  
  17.  
  18. 'Setup calculator
  19. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  20. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  21. 'Buttons
  22. FOR buttony = 75 TO 295 STEP 55
  23.     FOR buttonx = 50 TO 275 STEP 75
  24.         FOR bb = 0 TO 10
  25.             c = c + 10
  26.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  27.         NEXT bb
  28.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  29.         c = 0
  30.     NEXT buttonx
  31. NEXT buttony
  32. buttonx = 275: buttony = 20
  33. 'Green C Button
  34. FOR bb = 0 TO 10
  35.     c = c + 10
  36.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  37. NEXT bb
  38. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  39. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  40. c = 0
  41. 'Label Buttons
  42. _PRINTSTRING (312, 47), "C"
  43. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  44. _PRINTSTRING (87, 102), CHR$(251) 'square root
  45. _PRINTSTRING (152, 102), "sin"
  46. _PRINTSTRING (227, 102), "cos"
  47. _PRINTSTRING (302, 102), "tan"
  48. _PRINTSTRING (87, 157), "7"
  49. _PRINTSTRING (162, 157), "8"
  50. _PRINTSTRING (237, 157), "9"
  51. _PRINTSTRING (312, 157), "/"
  52. _PRINTSTRING (87, 212), "4"
  53. _PRINTSTRING (162, 212), "5"
  54. _PRINTSTRING (237, 212), "6"
  55. _PRINTSTRING (312, 212), "x"
  56. _PRINTSTRING (87, 267), "1"
  57. _PRINTSTRING (162, 267), "2"
  58. _PRINTSTRING (237, 267), "3"
  59. _PRINTSTRING (312, 267), "-"
  60. _PRINTSTRING (87, 322), "0"
  61. _PRINTSTRING (162, 322), "."
  62. _PRINTSTRING (237, 322), "="
  63. _PRINTSTRING (312, 322), "+"
  64. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  65.     _LIMIT 20
  66.         mouseX = _MOUSEX
  67.         mouseY = _MOUSEY
  68.         mouseLeftButton = _MOUSEBUTTON(1)
  69.     LOOP
  70.     IF mouseLeftButton THEN
  71.         mouseLeftButton = 0
  72.  
  73.         'Clipboard
  74.         IF mouseX > 50 AND mouseX < 265 AND mouseY > 25 AND mouseY < 50 THEN
  75.             COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
  76.             _PRINTSTRING (55, 30), num$
  77.             _DELAY 1
  78.             _CLIPBOARD$ = num$
  79.             COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  80.             _PRINTSTRING (55, 30), num$
  81.         END IF
  82.  
  83.         'Clear
  84.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  85.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  86.             _PRINTSTRING (55, 30), "                          "
  87.             buttonx = 275: buttony = 20
  88.             GOSUB zero:
  89.         END IF
  90.  
  91.         'Square Root
  92.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  93.             IF num < 0 THEN GOTO skip1:
  94.             num = VAL(num$)
  95.             num = SQR(num)
  96.             num$ = STR$(num)
  97.             skip1:
  98.             buttonx = 50: buttony = 75
  99.             GOSUB press:
  100.             GOSUB number:
  101.         END IF
  102.  
  103.         'Sine
  104.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  105.             num = VAL(num$)
  106.             num = SIN(num)
  107.             num$ = STR$(num)
  108.             buttonx = 126: buttony = 75
  109.             GOSUB press:
  110.             GOSUB number:
  111.         END IF
  112.  
  113.         'Cosine
  114.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  115.             num = VAL(num$)
  116.             num = COS(num)
  117.             num$ = STR$(num)
  118.             buttonx = 200: buttony = 75
  119.             GOSUB press:
  120.             GOSUB number:
  121.         END IF
  122.  
  123.         'Tangent
  124.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  125.             num = VAL(num$)
  126.             num = TAN(num)
  127.             num$ = STR$(num)
  128.             buttonx = 275: buttony = 75
  129.             GOSUB press:
  130.             GOSUB number:
  131.         END IF
  132.  
  133.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  134.             num$ = num$ + "7"
  135.             IF n = 1 THEN num$ = "-" + num$: n = 0
  136.             buttonx = 50: buttony = 130
  137.             GOSUB press:
  138.             GOSUB number:
  139.         END IF
  140.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  141.             num$ = num$ + "8"
  142.             IF n = 1 THEN num$ = "-" + num$: n = 0
  143.             buttonx = 126: buttony = 130
  144.             GOSUB press:
  145.             GOSUB number:
  146.         END IF
  147.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  148.             num$ = num$ + "9"
  149.             IF n = 1 THEN num$ = "-" + num$: n = 0
  150.             buttonx = 200: buttony = 130
  151.             GOSUB press:
  152.             GOSUB number:
  153.         END IF
  154.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  155.             num$ = num$ + "4"
  156.             IF n = 1 THEN num$ = "-" + num$: n = 0
  157.             buttonx = 50: buttony = 185
  158.             GOSUB press:
  159.             GOSUB number:
  160.         END IF
  161.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  162.             num$ = num$ + "5"
  163.             IF n = 1 THEN num$ = "-" + num$: n = 0
  164.             buttonx = 126: buttony = 185
  165.             GOSUB press:
  166.             GOSUB number:
  167.         END IF
  168.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  169.             num$ = num$ + "6"
  170.             IF n = 1 THEN num$ = "-" + num$: n = 0
  171.             buttonx = 200: buttony = 185
  172.             GOSUB press:
  173.             GOSUB number:
  174.         END IF
  175.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  176.             num$ = num$ + "1"
  177.             IF n = 1 THEN num$ = "-" + num$: n = 0
  178.             buttonx = 50: buttony = 240
  179.             GOSUB press:
  180.             GOSUB number:
  181.         END IF
  182.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  183.             num$ = num$ + "2"
  184.             IF n = 1 THEN num$ = "-" + num$: n = 0
  185.             buttonx = 126: buttony = 240
  186.             GOSUB press:
  187.             GOSUB number:
  188.         END IF
  189.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  190.             num$ = num$ + "3"
  191.             IF n = 1 THEN num$ = "-" + num$: n = 0
  192.             buttonx = 200: buttony = 240
  193.             GOSUB press:
  194.             GOSUB number:
  195.         END IF
  196.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  197.             num$ = num$ + "0"
  198.             IF n = 1 THEN num$ = "-" + num$: n = 0
  199.             buttonx = 50: buttony = 295
  200.             GOSUB press:
  201.             GOSUB number:
  202.         END IF
  203.  
  204.         'Decimal
  205.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  206.             buttonx = 126: buttony = 295
  207.             FOR check = 1 TO LEN(num$)
  208.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  209.             NEXT check
  210.             num$ = num$ + "."
  211.             _PRINTSTRING (55, 30), num$
  212.             skipdec:
  213.             GOSUB press:
  214.         END IF
  215.  
  216.         'Equals
  217.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  218.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  219.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  220.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  221.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  222.             buttonx = 200: buttony = 295
  223.             GOSUB press:
  224.             GOSUB number2:
  225.         END IF
  226.  
  227.         'Add
  228.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  229.             IF a = 0 THEN
  230.                 d = 0: a = 1: s = 0: t = 0
  231.                 oldnum$ = num$
  232.                 calc = 1
  233.                 _PRINTSTRING (55, 30), "                          "
  234.                 num$ = ""
  235.                 GOTO nex4:
  236.             END IF
  237.             IF a = 1 THEN
  238.                 num = VAL(oldnum$) + VAL(num$)
  239.                 a = 0
  240.             END IF
  241.             calc = 0
  242.             GOSUB number2:
  243.             nex4:
  244.             buttonx = 275: buttony = 295
  245.             GOSUB press:
  246.         END IF
  247.  
  248.         'Subtract
  249.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  250.             IF s = 0 THEN
  251.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  252.                 d = 0: a = 0: s = 1: t = 0
  253.                 oldnum$ = num$
  254.                 calc = 1
  255.                 _PRINTSTRING (55, 30), "                          "
  256.                 num$ = ""
  257.                 GOTO nex3:
  258.             END IF
  259.             IF s = 1 THEN
  260.                 num = VAL(oldnum$) - VAL(num$)
  261.                 s = 0
  262.             END IF
  263.             calc = 0
  264.             GOSUB number2:
  265.             nex3:
  266.             buttonx = 275: buttony = 240
  267.             GOSUB press:
  268.         END IF
  269.  
  270.         'Multiply
  271.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  272.             IF t = 0 THEN
  273.                 d = 0: a = 0: s = 0: t = 1
  274.                 oldnum$ = num$
  275.                 calc = 1
  276.                 _PRINTSTRING (55, 30), "                          "
  277.                 num$ = ""
  278.                 GOTO nex2:
  279.             END IF
  280.             IF t = 1 THEN
  281.                 num = VAL(oldnum$) * VAL(num$)
  282.                 t = 0
  283.             END IF
  284.             calc = 0
  285.             GOSUB number2:
  286.             nex2:
  287.             buttonx = 275: buttony = 185
  288.             GOSUB press:
  289.         END IF
  290.  
  291.         'Divide
  292.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  293.             IF d = 0 THEN
  294.                 d = 1: a = 0: s = 0: t = 0
  295.                 oldnum$ = num$
  296.                 calc = 1
  297.                 _PRINTSTRING (55, 30), "                          "
  298.                 num$ = ""
  299.                 GOTO nex1:
  300.             END IF
  301.             IF d = 1 AND num$ <> "" THEN
  302.                 num = VAL(oldnum$) / VAL(num$)
  303.                 d = 0
  304.             END IF
  305.             calc = 0
  306.             GOSUB number2:
  307.             nex1:
  308.             buttonx = 275: buttony = 130
  309.             GOSUB press:
  310.         END IF
  311.     END IF
  312. 'For Number Buttons.
  313. number:
  314. num = VAL(num$)
  315.  
  316. 'For Math
  317. number2:
  318. _PRINTSTRING (55, 30), "                          "
  319. num$ = STR$(num)
  320. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  321. _PRINTSTRING (55, 30), num$
  322.  
  323.  
  324. 'Pressing Each Button
  325. press:
  326. c = 110
  327. FOR bb = 0 TO 10
  328.     c = c - 10
  329.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  330. NEXT bb
  331. _DELAY .25
  332. FOR bb = 0 TO 10
  333.     c = c + 10
  334.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  335. NEXT bb
  336.  
  337. 'Pressing the Green C Button.
  338. zero:
  339. c = 110
  340. FOR bb = 0 TO 10
  341.     c = c - 10
  342.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  343. NEXT bb
  344. _DELAY .25
  345. FOR bb = 0 TO 10
  346.     c = c + 10
  347.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  348. NEXT bb
  349.  
  350.  
  351.  
  352.  
  353. FUNCTION BASIMAGE1& 'calculatio icon data
  354.     v& = _NEWIMAGE(54, 48, 32)
  355.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  356.     A$ = ""
  357.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  358.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  359.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  360.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  361.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  362.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  363.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  364.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  365.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  366.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  367.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  368.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  369.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  370.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  371.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  372.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  373.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  374.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  375.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  376.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  377.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  378.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  379.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  380.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  381.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  382.     btemp$ = ""
  383.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  384.         IF INSTR(1, B$, "%") THEN
  385.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  386.                 IF F$ <> "%" THEN C$ = C$ + F$
  387.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  388.             IF MID$(B$, j, 1) = "#" THEN
  389.         MID$(B$, j) = "@": END IF: NEXT
  390.         FOR t% = LEN(B$) TO 1 STEP -1
  391.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  392.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  393.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  394.     NEXT: btemp$ = btemp$ + X$: NEXT
  395.     btemp$ = _INFLATE$(btemp$)
  396.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  397.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  398.  
Title: Re: Calculator
Post by: SierraKen on July 29, 2020, 01:40:35 am
I just improved it even more with 4 new buttons on the bottom (I made the calculator window a bit longer). The new buttons are: Rad2Deg (which changes to Deg2Rad after used, and vice-versa). This changes degrees to radians and radians to degrees. The next button is second power, which times your number to itself (by the second power). The next one is logarithm. This one uses the Base 10 logarithm (which is what most calculators use I found out). Instead of num = LOG(num) it has num = LOG(num) / LOG(10.#). The wiki page of LOG helped me with that equation. I also checked the output using Google's calculator which also uses Base 10 Log. The last new button was the easiest, it just puts _PI on the screen for anyone that needs to use Pi. You can see I clicked the Pi button in the picture attachment below.

Note: I deleted this code because of a Log error I get when trying to get the Log of a negative number, which is true in math. Go to the next post for the update.



Title: Re: Calculator
Post by: SierraKen on July 29, 2020, 01:53:49 am
Here is the update with the Log fix.

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 28, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 3 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8. 'Thank you Dav for the icon code!
  9. 'Just added Clipboard by clicking the output number.
  10. 'Just added Rad2Deg (and Deg2Rad), second power, Base 10 Logarithm, and Pi buttons.
  11.  
  12. 'Load the icon - call this somewhere near the top of your program
  13. _ICON BASIMAGE1&
  14.  
  15. _TITLE "Calculator - Click output to copy."
  16. SCREEN _NEWIMAGE(400, 450, 32)
  17.  
  18.  
  19. 'Setup calculator
  20. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  21. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  22. 'Buttons
  23. FOR buttony = 75 TO 350 STEP 55
  24.     FOR buttonx = 50 TO 275 STEP 75
  25.         FOR bb = 0 TO 10
  26.             c = c + 10
  27.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  28.         NEXT bb
  29.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  30.         c = 0
  31.     NEXT buttonx
  32. NEXT buttony
  33. buttonx = 275: buttony = 20
  34. 'Green C Button
  35. FOR bb = 0 TO 10
  36.     c = c + 10
  37.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  38. NEXT bb
  39. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  40. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  41. c = 0
  42. 'Label Buttons
  43. _PRINTSTRING (312, 47), "C"
  44. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  45. _PRINTSTRING (87, 102), CHR$(251) 'square root
  46. _PRINTSTRING (152, 102), "sin"
  47. _PRINTSTRING (227, 102), "cos"
  48. _PRINTSTRING (302, 102), "tan"
  49. _PRINTSTRING (87, 157), "7"
  50. _PRINTSTRING (162, 157), "8"
  51. _PRINTSTRING (237, 157), "9"
  52. _PRINTSTRING (312, 157), "/"
  53. _PRINTSTRING (87, 212), "4"
  54. _PRINTSTRING (162, 212), "5"
  55. _PRINTSTRING (237, 212), "6"
  56. _PRINTSTRING (312, 212), "x"
  57. _PRINTSTRING (87, 267), "1"
  58. _PRINTSTRING (162, 267), "2"
  59. _PRINTSTRING (237, 267), "3"
  60. _PRINTSTRING (312, 267), "-"
  61. _PRINTSTRING (87, 322), "0"
  62. _PRINTSTRING (162, 322), "."
  63. _PRINTSTRING (237, 322), "="
  64. _PRINTSTRING (312, 322), "+"
  65. _PRINTSTRING (60, 377), "rad2deg"
  66. _PRINTSTRING (162, 377), "x" + CHR$(253) 'second power
  67. _PRINTSTRING (227, 377), "log"
  68. _PRINTSTRING (307, 377), "Pi"
  69.  
  70. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  71.     _LIMIT 20
  72.         mouseX = _MOUSEX
  73.         mouseY = _MOUSEY
  74.         mouseLeftButton = _MOUSEBUTTON(1)
  75.     LOOP
  76.     IF mouseLeftButton THEN
  77.         mouseLeftButton = 0
  78.  
  79.         'Clipboard
  80.         IF mouseX > 50 AND mouseX < 265 AND mouseY > 25 AND mouseY < 50 THEN
  81.             COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
  82.             _PRINTSTRING (55, 30), num$
  83.             _DELAY 1
  84.             num2$ = _TRIM$(num$)
  85.             _CLIPBOARD$ = num2$
  86.             COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  87.             _PRINTSTRING (55, 30), num$
  88.         END IF
  89.  
  90.         'Clear
  91.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  92.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  93.             _PRINTSTRING (55, 30), "                          "
  94.             buttonx = 275: buttony = 20
  95.             GOSUB zero:
  96.         END IF
  97.  
  98.         'Rad2Deg and Deg2Rad
  99.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 350 AND mouseY < 405 THEN
  100.             rad = rad + 1
  101.             IF rad = 2 THEN GOTO deg2rad:
  102.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  103.             _PRINTSTRING (60, 377), "deg2rad"
  104.             num = VAL(num$)
  105.             num = _R2D(num)
  106.             num$ = STR$(num)
  107.             GOTO skipdeg2rad:
  108.             deg2rad:
  109.             rad = 0
  110.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  111.             _PRINTSTRING (60, 377), "rad2deg"
  112.             num = VAL(num$)
  113.             num = _D2R(num)
  114.             num$ = STR$(num)
  115.             skipdeg2rad:
  116.             buttonx = 50: buttony = 350
  117.             GOSUB press:
  118.             GOSUB number:
  119.         END IF
  120.  
  121.         'Second Power
  122.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 350 AND mouseY < 405 THEN
  123.             num = VAL(num$)
  124.             num = num ^ 2
  125.             num$ = STR$(num)
  126.             buttonx = 126: buttony = 350
  127.             GOSUB press:
  128.             GOSUB number:
  129.         END IF
  130.  
  131.         'logarithm
  132.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 350 AND mouseY < 405 THEN
  133.             num = VAL(num$)
  134.             IF num < 0 THEN GOTO skiplog:
  135.             num = LOG(num) / LOG(10.#)
  136.             num$ = STR$(num)
  137.             skiplog:
  138.             buttonx = 200: buttony = 350
  139.             GOSUB press:
  140.             GOSUB number:
  141.         END IF
  142.  
  143.         'Pi
  144.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 350 AND mouseY < 405 THEN
  145.             num = _PI
  146.             num$ = STR$(num)
  147.             buttonx = 275: buttony = 350
  148.             GOSUB press:
  149.             GOSUB number:
  150.         END IF
  151.  
  152.         'Square Root
  153.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  154.             IF num < 0 THEN GOTO skip1:
  155.             num = VAL(num$)
  156.             num = SQR(num)
  157.             num$ = STR$(num)
  158.             skip1:
  159.             buttonx = 50: buttony = 75
  160.             GOSUB press:
  161.             GOSUB number:
  162.         END IF
  163.  
  164.         'Sine
  165.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  166.             num = VAL(num$)
  167.             num = SIN(num)
  168.             num$ = STR$(num)
  169.             buttonx = 126: buttony = 75
  170.             GOSUB press:
  171.             GOSUB number:
  172.         END IF
  173.  
  174.         'Cosine
  175.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  176.             num = VAL(num$)
  177.             num = COS(num)
  178.             num$ = STR$(num)
  179.             buttonx = 200: buttony = 75
  180.             GOSUB press:
  181.             GOSUB number:
  182.         END IF
  183.  
  184.         'Tangent
  185.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  186.             num = VAL(num$)
  187.             num = TAN(num)
  188.             num$ = STR$(num)
  189.             buttonx = 275: buttony = 75
  190.             GOSUB press:
  191.             GOSUB number:
  192.         END IF
  193.  
  194.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  195.             num$ = num$ + "7"
  196.             IF n = 1 THEN num$ = "-" + num$: n = 0
  197.             buttonx = 50: buttony = 130
  198.             GOSUB press:
  199.             GOSUB number:
  200.         END IF
  201.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  202.             num$ = num$ + "8"
  203.             IF n = 1 THEN num$ = "-" + num$: n = 0
  204.             buttonx = 126: buttony = 130
  205.             GOSUB press:
  206.             GOSUB number:
  207.         END IF
  208.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  209.             num$ = num$ + "9"
  210.             IF n = 1 THEN num$ = "-" + num$: n = 0
  211.             buttonx = 200: buttony = 130
  212.             GOSUB press:
  213.             GOSUB number:
  214.         END IF
  215.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  216.             num$ = num$ + "4"
  217.             IF n = 1 THEN num$ = "-" + num$: n = 0
  218.             buttonx = 50: buttony = 185
  219.             GOSUB press:
  220.             GOSUB number:
  221.         END IF
  222.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  223.             num$ = num$ + "5"
  224.             IF n = 1 THEN num$ = "-" + num$: n = 0
  225.             buttonx = 126: buttony = 185
  226.             GOSUB press:
  227.             GOSUB number:
  228.         END IF
  229.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  230.             num$ = num$ + "6"
  231.             IF n = 1 THEN num$ = "-" + num$: n = 0
  232.             buttonx = 200: buttony = 185
  233.             GOSUB press:
  234.             GOSUB number:
  235.         END IF
  236.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  237.             num$ = num$ + "1"
  238.             IF n = 1 THEN num$ = "-" + num$: n = 0
  239.             buttonx = 50: buttony = 240
  240.             GOSUB press:
  241.             GOSUB number:
  242.         END IF
  243.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  244.             num$ = num$ + "2"
  245.             IF n = 1 THEN num$ = "-" + num$: n = 0
  246.             buttonx = 126: buttony = 240
  247.             GOSUB press:
  248.             GOSUB number:
  249.         END IF
  250.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  251.             num$ = num$ + "3"
  252.             IF n = 1 THEN num$ = "-" + num$: n = 0
  253.             buttonx = 200: buttony = 240
  254.             GOSUB press:
  255.             GOSUB number:
  256.         END IF
  257.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  258.             num$ = num$ + "0"
  259.             IF n = 1 THEN num$ = "-" + num$: n = 0
  260.             buttonx = 50: buttony = 295
  261.             GOSUB press:
  262.             GOSUB number:
  263.         END IF
  264.  
  265.         'Decimal
  266.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  267.             buttonx = 126: buttony = 295
  268.             FOR check = 1 TO LEN(num$)
  269.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  270.             NEXT check
  271.             num$ = num$ + "."
  272.             _PRINTSTRING (55, 30), num$
  273.             skipdec:
  274.             GOSUB press:
  275.         END IF
  276.  
  277.         'Equals
  278.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  279.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  280.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  281.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  282.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  283.             buttonx = 200: buttony = 295
  284.             GOSUB press:
  285.             GOSUB number2:
  286.         END IF
  287.  
  288.         'Add
  289.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  290.             IF a = 0 THEN
  291.                 d = 0: a = 1: s = 0: t = 0
  292.                 oldnum$ = num$
  293.                 calc = 1
  294.                 _PRINTSTRING (55, 30), "                          "
  295.                 num$ = ""
  296.                 GOTO nex4:
  297.             END IF
  298.             IF a = 1 THEN
  299.                 num = VAL(oldnum$) + VAL(num$)
  300.                 a = 0
  301.             END IF
  302.             calc = 0
  303.             GOSUB number2:
  304.             nex4:
  305.             buttonx = 275: buttony = 295
  306.             GOSUB press:
  307.         END IF
  308.  
  309.         'Subtract
  310.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  311.             IF s = 0 THEN
  312.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  313.                 d = 0: a = 0: s = 1: t = 0
  314.                 oldnum$ = num$
  315.                 calc = 1
  316.                 _PRINTSTRING (55, 30), "                          "
  317.                 num$ = ""
  318.                 GOTO nex3:
  319.             END IF
  320.             IF s = 1 THEN
  321.                 num = VAL(oldnum$) - VAL(num$)
  322.                 s = 0
  323.             END IF
  324.             calc = 0
  325.             GOSUB number2:
  326.             nex3:
  327.             buttonx = 275: buttony = 240
  328.             GOSUB press:
  329.         END IF
  330.  
  331.         'Multiply
  332.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  333.             IF t = 0 THEN
  334.                 d = 0: a = 0: s = 0: t = 1
  335.                 oldnum$ = num$
  336.                 calc = 1
  337.                 _PRINTSTRING (55, 30), "                          "
  338.                 num$ = ""
  339.                 GOTO nex2:
  340.             END IF
  341.             IF t = 1 THEN
  342.                 num = VAL(oldnum$) * VAL(num$)
  343.                 t = 0
  344.             END IF
  345.             calc = 0
  346.             GOSUB number2:
  347.             nex2:
  348.             buttonx = 275: buttony = 185
  349.             GOSUB press:
  350.         END IF
  351.  
  352.         'Divide
  353.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  354.             IF d = 0 THEN
  355.                 d = 1: a = 0: s = 0: t = 0
  356.                 oldnum$ = num$
  357.                 calc = 1
  358.                 _PRINTSTRING (55, 30), "                          "
  359.                 num$ = ""
  360.                 GOTO nex1:
  361.             END IF
  362.             IF d = 1 AND num$ <> "" THEN
  363.                 num = VAL(oldnum$) / VAL(num$)
  364.                 d = 0
  365.             END IF
  366.             calc = 0
  367.             GOSUB number2:
  368.             nex1:
  369.             buttonx = 275: buttony = 130
  370.             GOSUB press:
  371.         END IF
  372.     END IF
  373. 'For Number Buttons.
  374. number:
  375. num = VAL(num$)
  376.  
  377. 'For Math
  378. number2:
  379. COLOR _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  380. _PRINTSTRING (55, 30), "                          "
  381. num$ = STR$(num)
  382. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  383. _PRINTSTRING (55, 30), num$
  384.  
  385.  
  386. 'Pressing Each Button
  387. press:
  388. c = 110
  389. FOR bb = 0 TO 10
  390.     c = c - 10
  391.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  392. NEXT bb
  393. _DELAY .25
  394. FOR bb = 0 TO 10
  395.     c = c + 10
  396.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  397. NEXT bb
  398.  
  399. 'Pressing the Green C Button.
  400. zero:
  401. c = 110
  402. FOR bb = 0 TO 10
  403.     c = c - 10
  404.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  405. NEXT bb
  406. _DELAY .25
  407. FOR bb = 0 TO 10
  408.     c = c + 10
  409.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  410. NEXT bb
  411.  
  412.  
  413.  
  414.  
  415. FUNCTION BASIMAGE1& 'calculatio icon data
  416.     v& = _NEWIMAGE(54, 48, 32)
  417.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  418.     A$ = ""
  419.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  420.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  421.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  422.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  423.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  424.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  425.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  426.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  427.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  428.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  429.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  430.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  431.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  432.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  433.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  434.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  435.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  436.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  437.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  438.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  439.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  440.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  441.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  442.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  443.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  444.     btemp$ = ""
  445.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  446.         IF INSTR(1, B$, "%") THEN
  447.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  448.                 IF F$ <> "%" THEN C$ = C$ + F$
  449.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  450.             IF MID$(B$, j, 1) = "#" THEN
  451.         MID$(B$, j) = "@": END IF: NEXT
  452.         FOR t% = LEN(B$) TO 1 STEP -1
  453.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  454.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  455.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  456.     NEXT: btemp$ = btemp$ + X$: NEXT
  457.     btemp$ = _INFLATE$(btemp$)
  458.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  459.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  460.  
Title: Re: Calculator
Post by: bplus on July 29, 2020, 11:54:19 am
Come to think of it - you may not need my icon stuff added at all.  Just do an _ICON _DISPLAY after drawing your calculator and that would look just as good.  Instant icon.  That would be a cool trick I suppose for showing game play in the task bar when playing games.

- Dav

This is interesting idea. I've never done this but I think you draw the calculator get an image of it and use it for an icon. Maybe when playing games you can constantly update the icon?

Sounds very interesting!

Ken those are nice improvements to your calculator, EXP usually goes with LOG and yes some of these advanced math operations need checks before you attempt them. A classic one is division by 0, don't attempt to divide if the divisor is 0!
Title: Re: Calculator
Post by: SierraKen on July 29, 2020, 12:11:07 pm
Thanks B+. I can't seem to get SIN, COS, TAN to work with degrees though. Just by clicking SIN and then Rad2Deg doesn't give the right results as just SIN(degrees). I almost flunked out of Trig class, which was over 30 years ago, so does anyone have any suggestions? I keep SIN, COS, TAN though because the radians work fine. The funny part is, Rad2Deg works perfectly with Pi.
Title: Re: Calculator
Post by: bplus on July 29, 2020, 12:18:36 pm
When I use my regular calculator Radians/Degrees is a Toggle in Radians mode it put a little Radians up in corner when in Degrees mode a Degrees indication, you could do this by changing the name of button or just add the mode label in a corner so you know what mode you are in.

Anyway when you are in Radians Mode you do SIN, COS, TAN with VAL(num$) like SIN(VAL(num$))

In Degrees Mode you do SIN, COS, TAN with _D2R(VAL(num$)) so it's like SIN(_D2R(VAL(num$)))

If you decide to do ARC SIN, ARC COS, ARC TAN then you would show the result in the mode you are in (read as the Angle whose SIN = .xxxx) :

So if in Degrees mode for like ARC SIN: result =  _R2D(ARCSIN(VAL(num$)))
Title: Re: Calculator
Post by: Dav on July 29, 2020, 01:07:25 pm
Quote from: bplus
This is interesting idea. I've never done this but I think you draw the calculator get an image of it and use it for an icon. Maybe when playing games you can constantly update the icon?

By using _DISPLAY instead of an image, you can by pass getting an image at all - the _ICON will use the current program screen displayed.  Very easy to have an icon. I think I will be using this in future projects.

- Dav
Title: Re: Calculator
Post by: bplus on July 29, 2020, 01:38:47 pm
By using _DISPLAY instead of an image, you can by pass getting an image at all - the _ICON will use the current program screen displayed.  Very easy to have an icon. I think I will be using this in future projects.

- Dav

Nice, no extra files at all!
Title: Re: Calculator
Post by: SpriggsySpriggs on July 29, 2020, 01:56:17 pm
By using _DISPLAY instead of an image, you can by pass getting an image at all - the _ICON will use the current program screen displayed.  Very easy to have an icon. I think I will be using this in future projects.
I was unaware of this feature! Cool!
Title: Re: Calculator
Post by: SierraKen on July 29, 2020, 03:49:27 pm
Since B+ said I should add the EXP and showed me how to fix the SIN, COS, TAN with deg and rad modes, I decided to make 4 more buttons and change the rad2deg (and deg2rad) button to just show which mode you can change to next if you click it. B+ also mentioned that many calculators show which mode it's on up near the top, so I added that too. :) You can see the 4 new buttons on the picture below. I hope you all enjoy this as much as I have in programming it. Thanks to B+ and all of you guys for the inspiration and help. :))
Oh, one side note. I noticed QB64 uses "Inf" when you divide by 0 so I left it in there just to make it look like how calculators say similar things, like "E", etc. It also displays that when you make your exponent too high. I believe a power over 88 is too high for QB64 it said on the Wiki. So it just displays a "Inf", which stands for infinity.

Here is the update:

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 29, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 4 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8. 'Thank you Dav for the icon code!
  9. 'Added Clipboard by clicking the output number.
  10. 'Added Rad2Deg (and Deg2Rad), second power, Base 10 Logarithm, and Pi buttons.
  11. 'Added 1/x, x/2, exp, postive or negative.
  12.  
  13. 'Load the icon - call this somewhere near the top of your program
  14. _ICON BASIMAGE1&
  15.  
  16. _TITLE "Calculator - Click output to copy."
  17. SCREEN _NEWIMAGE(400, 500, 32)
  18.  
  19. 'Setup calculator
  20. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  21. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  22. 'Buttons
  23. FOR buttony = 75 TO 405 STEP 55
  24.     FOR buttonx = 50 TO 275 STEP 75
  25.         FOR bb = 0 TO 10
  26.             c = c + 10
  27.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  28.         NEXT bb
  29.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  30.         c = 0
  31.     NEXT buttonx
  32. NEXT buttony
  33. buttonx = 275: buttony = 20
  34. 'Green C Button
  35. FOR bb = 0 TO 10
  36.     c = c + 10
  37.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  38. NEXT bb
  39. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  40. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  41. _PRINTSTRING (50, 5), "Rad"
  42.  
  43. 'Label Buttons
  44. _PRINTSTRING (312, 47), "C"
  45. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  46. _PRINTSTRING (87, 102), CHR$(251) 'square root
  47. _PRINTSTRING (152, 102), "sin"
  48. _PRINTSTRING (227, 102), "cos"
  49. _PRINTSTRING (302, 102), "tan"
  50. _PRINTSTRING (87, 157), "7"
  51. _PRINTSTRING (162, 157), "8"
  52. _PRINTSTRING (237, 157), "9"
  53. _PRINTSTRING (312, 157), "/"
  54. _PRINTSTRING (87, 212), "4"
  55. _PRINTSTRING (162, 212), "5"
  56. _PRINTSTRING (237, 212), "6"
  57. _PRINTSTRING (312, 212), "x"
  58. _PRINTSTRING (87, 267), "1"
  59. _PRINTSTRING (162, 267), "2"
  60. _PRINTSTRING (237, 267), "3"
  61. _PRINTSTRING (312, 267), "-"
  62. _PRINTSTRING (87, 322), "0"
  63. _PRINTSTRING (162, 322), "."
  64. _PRINTSTRING (237, 322), "="
  65. _PRINTSTRING (312, 322), "+"
  66. _PRINTSTRING (79, 377), "deg"
  67. _PRINTSTRING (162, 377), "x" + CHR$(253) 'second power
  68. _PRINTSTRING (227, 377), "log"
  69. _PRINTSTRING (307, 377), "Pi"
  70. _PRINTSTRING (79, 432), "1/x"
  71. _PRINTSTRING (152, 432), "x/2"
  72. _PRINTSTRING (227, 432), "exp"
  73. _PRINTSTRING (312, 432), CHR$(241) 'Postive or Negative
  74.  
  75. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  76.     _LIMIT 20
  77.         mouseX = _MOUSEX
  78.         mouseY = _MOUSEY
  79.         mouseLeftButton = _MOUSEBUTTON(1)
  80.     LOOP
  81.     IF mouseLeftButton THEN
  82.         mouseLeftButton = 0
  83.  
  84.         'Clipboard
  85.         IF mouseX > 50 AND mouseX < 265 AND mouseY > 25 AND mouseY < 50 THEN
  86.             COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
  87.             _PRINTSTRING (55, 30), num$
  88.             _DELAY 1
  89.             num2$ = _TRIM$(num$)
  90.             _CLIPBOARD$ = num2$
  91.             COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  92.             _PRINTSTRING (55, 30), num$
  93.         END IF
  94.  
  95.         'Clear
  96.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  97.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  98.             _PRINTSTRING (55, 30), "                          "
  99.             buttonx = 275: buttony = 20
  100.             GOSUB zero:
  101.         END IF
  102.  
  103.         '1/x
  104.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 405 AND mouseY < 460 THEN
  105.             num = VAL(num$)
  106.             IF num = 0 THEN GOTO skipthis:
  107.             num = 1 / num
  108.             num$ = STR$(num)
  109.             skipthis:
  110.             buttonx = 50: buttony = 405
  111.             GOSUB press:
  112.             GOSUB number:
  113.         END IF
  114.  
  115.         'x/2
  116.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 405 AND mouseY < 460 THEN
  117.             num = VAL(num$)
  118.             num = num / 2
  119.             num$ = STR$(num)
  120.             buttonx = 126: buttony = 405
  121.             GOSUB press:
  122.             GOSUB number2:
  123.         END IF
  124.  
  125.         'Exponents
  126.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 405 AND mouseY < 460 THEN
  127.             ee = 1: a = 0: s = 0: t = 0: d = 0
  128.             e = e + 1
  129.             IF e = 2 THEN GOTO expo:
  130.             oldnum$ = num$
  131.             _PRINTSTRING (55, 30), "                          "
  132.             num$ = ""
  133.             GOTO nextexpo:
  134.             expo:
  135.             e = 0
  136.             num = VAL(oldnum$) ^ VAL(num$)
  137.             ee = 0
  138.             over:
  139.             GOSUB number2:
  140.             nextexpo:
  141.             buttonx = 200: buttony = 405
  142.             GOSUB press:
  143.         END IF
  144.  
  145.         'Postive or Negative
  146.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 405 AND mouseY < 460 THEN
  147.             num$ = "-" + num$
  148.             buttonx = 275: buttony = 405
  149.             GOSUB press:
  150.             GOSUB number:
  151.         END IF
  152.  
  153.         'Radians and Degrees
  154.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 350 AND mouseY < 405 THEN
  155.             deg = deg + 1
  156.             IF deg = 2 THEN GOTO deg2rad:
  157.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  158.             _PRINTSTRING (79, 377), "rad"
  159.             COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  160.             _PRINTSTRING (50, 5), "Deg"
  161.             num = VAL(num$)
  162.             num = _R2D(num)
  163.             num$ = STR$(num)
  164.             GOTO skipdeg2rad:
  165.             deg2rad:
  166.             deg = 0
  167.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  168.             _PRINTSTRING (79, 377), "deg"
  169.             COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  170.             _PRINTSTRING (50, 5), "Rad"
  171.             num = VAL(num$)
  172.             num = _D2R(num)
  173.             num$ = STR$(num)
  174.             skipdeg2rad:
  175.             buttonx = 50: buttony = 350
  176.             GOSUB press:
  177.             GOSUB number:
  178.         END IF
  179.  
  180.         'Second Power
  181.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 350 AND mouseY < 405 THEN
  182.             num = VAL(num$)
  183.             num = num ^ 2
  184.             num$ = STR$(num)
  185.             buttonx = 126: buttony = 350
  186.             GOSUB press:
  187.             GOSUB number:
  188.         END IF
  189.  
  190.         'logarithm
  191.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 350 AND mouseY < 405 THEN
  192.             num = VAL(num$)
  193.             IF num < 0 THEN GOTO skiplog:
  194.             num = LOG(num) / LOG(10.#)
  195.             num$ = STR$(num)
  196.             skiplog:
  197.             buttonx = 200: buttony = 350
  198.             GOSUB press:
  199.             GOSUB number:
  200.         END IF
  201.  
  202.         'Pi
  203.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 350 AND mouseY < 405 THEN
  204.             num = _PI
  205.             num$ = STR$(num)
  206.             buttonx = 275: buttony = 350
  207.             GOSUB press:
  208.             GOSUB number:
  209.         END IF
  210.  
  211.         'Square Root
  212.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  213.             IF num < 0 THEN GOTO skip1:
  214.             num = VAL(num$)
  215.             num = SQR(num)
  216.             num$ = STR$(num)
  217.             skip1:
  218.             buttonx = 50: buttony = 75
  219.             GOSUB press:
  220.             GOSUB number:
  221.         END IF
  222.  
  223.         'Sine
  224.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  225.             IF deg = 1 THEN num = SIN(_D2R(VAL(num$)))
  226.             IF deg = 0 THEN num = SIN(num)
  227.             num$ = STR$(num)
  228.             buttonx = 126: buttony = 75
  229.             GOSUB press:
  230.             GOSUB number:
  231.         END IF
  232.  
  233.         'Cosine
  234.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  235.             IF deg = 1 THEN num = COS(_D2R(VAL(num$)))
  236.             IF deg = 0 THEN num = COS(num)
  237.             num$ = STR$(num)
  238.             buttonx = 200: buttony = 75
  239.             GOSUB press:
  240.             GOSUB number:
  241.         END IF
  242.  
  243.         'Tangent
  244.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  245.             IF deg = 1 THEN num = TAN(_D2R(VAL(num$)))
  246.             IF deg = 0 THEN num = TAN(num)
  247.             num$ = STR$(num)
  248.             buttonx = 275: buttony = 75
  249.             GOSUB press:
  250.             GOSUB number:
  251.         END IF
  252.  
  253.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  254.             num$ = num$ + "7"
  255.             IF n = 1 THEN num$ = "-" + num$: n = 0
  256.             buttonx = 50: buttony = 130
  257.             GOSUB press:
  258.             GOSUB number:
  259.         END IF
  260.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  261.             num$ = num$ + "8"
  262.             IF n = 1 THEN num$ = "-" + num$: n = 0
  263.             buttonx = 126: buttony = 130
  264.             GOSUB press:
  265.             GOSUB number:
  266.         END IF
  267.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  268.             num$ = num$ + "9"
  269.             IF n = 1 THEN num$ = "-" + num$: n = 0
  270.             buttonx = 200: buttony = 130
  271.             GOSUB press:
  272.             GOSUB number:
  273.         END IF
  274.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  275.             num$ = num$ + "4"
  276.             IF n = 1 THEN num$ = "-" + num$: n = 0
  277.             buttonx = 50: buttony = 185
  278.             GOSUB press:
  279.             GOSUB number:
  280.         END IF
  281.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  282.             num$ = num$ + "5"
  283.             IF n = 1 THEN num$ = "-" + num$: n = 0
  284.             buttonx = 126: buttony = 185
  285.             GOSUB press:
  286.             GOSUB number:
  287.         END IF
  288.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  289.             num$ = num$ + "6"
  290.             IF n = 1 THEN num$ = "-" + num$: n = 0
  291.             buttonx = 200: buttony = 185
  292.             GOSUB press:
  293.             GOSUB number:
  294.         END IF
  295.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  296.             num$ = num$ + "1"
  297.             IF n = 1 THEN num$ = "-" + num$: n = 0
  298.             buttonx = 50: buttony = 240
  299.             GOSUB press:
  300.             GOSUB number:
  301.         END IF
  302.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  303.             num$ = num$ + "2"
  304.             IF n = 1 THEN num$ = "-" + num$: n = 0
  305.             buttonx = 126: buttony = 240
  306.             GOSUB press:
  307.             GOSUB number:
  308.         END IF
  309.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  310.             num$ = num$ + "3"
  311.             IF n = 1 THEN num$ = "-" + num$: n = 0
  312.             buttonx = 200: buttony = 240
  313.             GOSUB press:
  314.             GOSUB number:
  315.         END IF
  316.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  317.             num$ = num$ + "0"
  318.             IF n = 1 THEN num$ = "-" + num$: n = 0
  319.             buttonx = 50: buttony = 295
  320.             GOSUB press:
  321.             GOSUB number:
  322.         END IF
  323.  
  324.         'Decimal
  325.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  326.             buttonx = 126: buttony = 295
  327.             FOR check = 1 TO LEN(num$)
  328.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  329.             NEXT check
  330.             num$ = num$ + "."
  331.             _PRINTSTRING (55, 30), num$
  332.             skipdec:
  333.             GOSUB press:
  334.         END IF
  335.  
  336.         'Equals
  337.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  338.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  339.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  340.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  341.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  342.             IF ee = 1 THEN num = VAL(oldnum$) ^ VAL(num$): ee = 0
  343.             buttonx = 200: buttony = 295
  344.             GOSUB press:
  345.             GOSUB number2:
  346.         END IF
  347.  
  348.         'Add
  349.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  350.             IF a = 0 THEN
  351.                 d = 0: a = 1: s = 0: t = 0: ee = 0
  352.                 oldnum$ = num$
  353.                 _PRINTSTRING (55, 30), "                          "
  354.                 num$ = ""
  355.                 GOTO nex4:
  356.             END IF
  357.             IF a = 1 THEN
  358.                 num = VAL(oldnum$) + VAL(num$)
  359.                 a = 0
  360.             END IF
  361.             GOSUB number2:
  362.             nex4:
  363.             buttonx = 275: buttony = 295
  364.             GOSUB press:
  365.         END IF
  366.  
  367.         'Subtract
  368.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  369.             IF s = 0 THEN
  370.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  371.                 d = 0: a = 0: s = 1: t = 0: ee = 0
  372.                 oldnum$ = num$
  373.                 _PRINTSTRING (55, 30), "                          "
  374.                 num$ = ""
  375.                 GOTO nex3:
  376.             END IF
  377.             IF s = 1 THEN
  378.                 num = VAL(oldnum$) - VAL(num$)
  379.                 s = 0
  380.             END IF
  381.             GOSUB number2:
  382.             nex3:
  383.             buttonx = 275: buttony = 240
  384.             GOSUB press:
  385.         END IF
  386.  
  387.         'Multiply
  388.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  389.             IF t = 0 THEN
  390.                 d = 0: a = 0: s = 0: t = 1: ee = 0
  391.                 oldnum$ = num$
  392.                 _PRINTSTRING (55, 30), "                          "
  393.                 num$ = ""
  394.                 GOTO nex2:
  395.             END IF
  396.             IF t = 1 THEN
  397.                 num = VAL(oldnum$) * VAL(num$)
  398.                 t = 0
  399.             END IF
  400.             GOSUB number2:
  401.             nex2:
  402.             buttonx = 275: buttony = 185
  403.             GOSUB press:
  404.         END IF
  405.  
  406.         'Divide
  407.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  408.             IF d = 0 THEN
  409.                 d = 1: a = 0: s = 0: t = 0: ee = 0
  410.                 oldnum$ = num$
  411.                 _PRINTSTRING (55, 30), "                          "
  412.                 num$ = ""
  413.                 GOTO nex1:
  414.             END IF
  415.             IF d = 1 AND num$ <> "" THEN
  416.                 num = VAL(oldnum$) / VAL(num$)
  417.                 d = 0
  418.             END IF
  419.             GOSUB number2:
  420.             nex1:
  421.             buttonx = 275: buttony = 130
  422.             GOSUB press:
  423.         END IF
  424.     END IF
  425. 'For Number Buttons.
  426. number:
  427. num = VAL(num$)
  428.  
  429. 'For Math
  430. number2:
  431. COLOR _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  432. _PRINTSTRING (55, 30), "                          "
  433. num$ = STR$(num)
  434. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  435. _PRINTSTRING (55, 30), num$
  436.  
  437.  
  438. 'Pressing Each Button
  439. press:
  440. c = 110
  441. FOR bb = 0 TO 10
  442.     c = c - 10
  443.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  444. NEXT bb
  445. _DELAY .25
  446. FOR bb = 0 TO 10
  447.     c = c + 10
  448.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  449. NEXT bb
  450.  
  451. 'Pressing the Green C Button.
  452. zero:
  453. c = 110
  454. FOR bb = 0 TO 10
  455.     c = c - 10
  456.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  457. NEXT bb
  458. _DELAY .25
  459. FOR bb = 0 TO 10
  460.     c = c + 10
  461.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  462. NEXT bb
  463.  
  464.  
  465.  
  466.  
  467. FUNCTION BASIMAGE1& 'calculatio icon data
  468.     v& = _NEWIMAGE(54, 48, 32)
  469.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  470.     A$ = ""
  471.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  472.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  473.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  474.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  475.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  476.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  477.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  478.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  479.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  480.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  481.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  482.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  483.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  484.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  485.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  486.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  487.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  488.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  489.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  490.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  491.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  492.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  493.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  494.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  495.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  496.     btemp$ = ""
  497.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  498.         IF INSTR(1, B$, "%") THEN
  499.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  500.                 IF F$ <> "%" THEN C$ = C$ + F$
  501.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  502.             IF MID$(B$, j, 1) = "#" THEN
  503.         MID$(B$, j) = "@": END IF: NEXT
  504.         FOR t% = LEN(B$) TO 1 STEP -1
  505.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  506.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  507.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  508.     NEXT: btemp$ = btemp$ + X$: NEXT
  509.     btemp$ = _INFLATE$(btemp$)
  510.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  511.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  512.  
Title: Re: Calculator
Post by: bplus on July 29, 2020, 06:44:59 pm
Hi Ken,

The trig functions look OK. :)

I thought EXP was e^x, it is with QB64 but on my old calculator 1 EXP 2 = 100 and 1 (e^x) = 2.71... = e , your EXP isn't working either way.

The +- button could work better, if by toggling a minus sign next to number. When I go 12 -+ I get -12 but when I go +- again I get 0 ?

I tried _ICON _DISPLAY (after the calc was drawn before main loop) but the image is too small to make out any detail so your choice to keep Dav's image seems good.
Title: Re: Calculator
Post by: SierraKen on July 29, 2020, 06:58:56 pm
Thanks B+, I'll look more into EXP. Also I had no idea about the +/- problem, I'll try to fix that too.
Title: Re: Calculator
Post by: SierraKen on July 29, 2020, 07:30:05 pm
I'm at a roadblock with EXP. Everything I try doesn't work and Google has different outputs. I have no idea how to use it. I've tried to look at other websites but they are no help either. Do you think I should just remove LOG and EXP and put something else? I don't even know if it takes 2 numbers or 1. The wiki site says one but it also says it's the natural version. I use base 10 on my Log, which is different. Google uses 2 numbers and the wiki site just 1.
Title: Re: Calculator
Post by: SierraKen on July 29, 2020, 07:32:45 pm
But I did fix the +/- problem, which was fairly easy to fix.
Title: Re: Calculator
Post by: bplus on July 29, 2020, 08:20:53 pm
Hi Ken,

For EXP just use QB64 EXP(num$), piece of cake. It just uses 1 number like SIN or LOG.

These are natural logarithms, base e, as opposed to base 10 logarithms
Code: QB64: [Select]
  1. PRINT "This is e:"; EXP(1)
  2. PRINT "This is e squared:"; EXP(2)
  3. ' LOG reverses EXP
  4.  

Title: Re: Calculator
Post by: SierraKen on July 29, 2020, 08:43:19 pm
Awesome thanks again! I did it your way and removed the base 10 from the Log and just did num = LOG(VAL(num$)) and also the same thing with EXP with num = EXP(VAL(num$)). I did what you said and they switch back and forth almost perfectly except for like a .00000003 difference, which is no big deal lol. I think I am finished now!
Oh also, in case you missed me saying yesterday, if you left click the output number with your mouse, it copies it to the windows clipboard. :) Check it out :).

Here is the update:

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 29, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 4 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8. 'Thank you Dav for the icon code!
  9. 'Added Clipboard by clicking the output number.
  10. 'Added Rad2Deg (and Deg2Rad), second power, Logarithm, and Pi buttons.
  11. 'Added 1/x, x/2, exp, postive or negative.
  12.  
  13. 'Load the icon - call this somewhere near the top of your program
  14. _ICON BASIMAGE1&
  15.  
  16. _TITLE "Calculator - Click output to copy."
  17. SCREEN _NEWIMAGE(400, 500, 32)
  18.  
  19. 'Setup calculator
  20. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  21. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  22. 'Buttons
  23. FOR buttony = 75 TO 405 STEP 55
  24.     FOR buttonx = 50 TO 275 STEP 75
  25.         FOR bb = 0 TO 10
  26.             c = c + 10
  27.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  28.         NEXT bb
  29.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  30.         c = 0
  31.     NEXT buttonx
  32. NEXT buttony
  33. buttonx = 275: buttony = 20
  34. 'Green C Button
  35. FOR bb = 0 TO 10
  36.     c = c + 10
  37.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  38. NEXT bb
  39. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  40. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  41. _PRINTSTRING (50, 5), "Rad"
  42.  
  43. 'Label Buttons
  44. _PRINTSTRING (312, 47), "C"
  45. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  46. _PRINTSTRING (87, 102), CHR$(251) 'square root
  47. _PRINTSTRING (152, 102), "sin"
  48. _PRINTSTRING (227, 102), "cos"
  49. _PRINTSTRING (302, 102), "tan"
  50. _PRINTSTRING (87, 157), "7"
  51. _PRINTSTRING (162, 157), "8"
  52. _PRINTSTRING (237, 157), "9"
  53. _PRINTSTRING (312, 157), "/"
  54. _PRINTSTRING (87, 212), "4"
  55. _PRINTSTRING (162, 212), "5"
  56. _PRINTSTRING (237, 212), "6"
  57. _PRINTSTRING (312, 212), "x"
  58. _PRINTSTRING (87, 267), "1"
  59. _PRINTSTRING (162, 267), "2"
  60. _PRINTSTRING (237, 267), "3"
  61. _PRINTSTRING (312, 267), "-"
  62. _PRINTSTRING (87, 322), "0"
  63. _PRINTSTRING (162, 322), "."
  64. _PRINTSTRING (237, 322), "="
  65. _PRINTSTRING (312, 322), "+"
  66. _PRINTSTRING (79, 377), "deg"
  67. _PRINTSTRING (162, 377), "x" + CHR$(253) 'second power
  68. _PRINTSTRING (227, 377), "log"
  69. _PRINTSTRING (307, 377), "Pi"
  70. _PRINTSTRING (79, 432), "1/x"
  71. _PRINTSTRING (152, 432), "x/2"
  72. _PRINTSTRING (227, 432), "exp"
  73. _PRINTSTRING (312, 432), CHR$(241) 'Postive or Negative
  74.  
  75. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  76.     _LIMIT 20
  77.         mouseX = _MOUSEX
  78.         mouseY = _MOUSEY
  79.         mouseLeftButton = _MOUSEBUTTON(1)
  80.     LOOP
  81.     IF mouseLeftButton THEN
  82.         mouseLeftButton = 0
  83.  
  84.         'Clipboard
  85.         IF mouseX > 50 AND mouseX < 265 AND mouseY > 25 AND mouseY < 50 THEN
  86.             COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
  87.             _PRINTSTRING (55, 30), num$
  88.             _DELAY 1
  89.             num2$ = _TRIM$(num$)
  90.             _CLIPBOARD$ = num2$
  91.             COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  92.             _PRINTSTRING (55, 30), num$
  93.         END IF
  94.  
  95.         'Clear
  96.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 20 AND mouseY < 75 THEN
  97.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  98.             _PRINTSTRING (55, 30), "                          "
  99.             buttonx = 275: buttony = 20
  100.             GOSUB zero:
  101.         END IF
  102.  
  103.         '1/x
  104.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 405 AND mouseY < 460 THEN
  105.             num = VAL(num$)
  106.             IF num = 0 THEN GOTO skipthis:
  107.             num = 1 / num
  108.             num$ = STR$(num)
  109.             skipthis:
  110.             buttonx = 50: buttony = 405
  111.             GOSUB press:
  112.             GOSUB number:
  113.         END IF
  114.  
  115.         'x/2
  116.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 405 AND mouseY < 460 THEN
  117.             num = VAL(num$)
  118.             num = num / 2
  119.             num$ = STR$(num)
  120.             buttonx = 126: buttony = 405
  121.             GOSUB press:
  122.             GOSUB number2:
  123.         END IF
  124.  
  125.         'EXP
  126.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 405 AND mouseY < 460 THEN
  127.             _PRINTSTRING (55, 30), "                          "
  128.             num = EXP(VAL(num$))
  129.             num$ = STR$(num)
  130.             buttonx = 200: buttony = 405
  131.             GOSUB number2:
  132.             GOSUB press:
  133.         END IF
  134.  
  135.         'Postive or Negative
  136.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 405 AND mouseY < 460 THEN
  137.             IF VAL(num$) < 0 THEN
  138.                 num = -VAL(num$)
  139.                 num$ = STR$(num)
  140.                 GOTO skipplusnegative:
  141.             END IF
  142.             num$ = "-" + num$
  143.             skipplusnegative:
  144.             buttonx = 275: buttony = 405
  145.             GOSUB press:
  146.             GOSUB number:
  147.         END IF
  148.  
  149.         'Radians and Degrees
  150.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 350 AND mouseY < 405 THEN
  151.             deg = deg + 1
  152.             IF deg = 2 THEN GOTO deg2rad:
  153.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  154.             _PRINTSTRING (79, 377), "rad"
  155.             COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  156.             _PRINTSTRING (50, 5), "Deg"
  157.             num = VAL(num$)
  158.             num = _R2D(num)
  159.             num$ = STR$(num)
  160.             GOTO skipdeg2rad:
  161.             deg2rad:
  162.             deg = 0
  163.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  164.             _PRINTSTRING (79, 377), "deg"
  165.             COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  166.             _PRINTSTRING (50, 5), "Rad"
  167.             num = VAL(num$)
  168.             num = _D2R(num)
  169.             num$ = STR$(num)
  170.             skipdeg2rad:
  171.             buttonx = 50: buttony = 350
  172.             GOSUB press:
  173.             GOSUB number:
  174.         END IF
  175.  
  176.         'Second Power
  177.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 350 AND mouseY < 405 THEN
  178.             num = VAL(num$)
  179.             num = num ^ 2
  180.             num$ = STR$(num)
  181.             buttonx = 126: buttony = 350
  182.             GOSUB press:
  183.             GOSUB number:
  184.         END IF
  185.  
  186.         'logarithm
  187.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 350 AND mouseY < 405 THEN
  188.             num = VAL(num$)
  189.             IF num = 0 THEN GOTO skiplog:
  190.             IF num < 0 THEN GOTO skiplog:
  191.             num = LOG(num)
  192.             num$ = STR$(num)
  193.             skiplog:
  194.             buttonx = 200: buttony = 350
  195.             GOSUB press:
  196.             GOSUB number:
  197.         END IF
  198.  
  199.         'Pi
  200.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 350 AND mouseY < 405 THEN
  201.             num = _PI
  202.             num$ = STR$(num)
  203.             buttonx = 275: buttony = 350
  204.             GOSUB press:
  205.             GOSUB number:
  206.         END IF
  207.  
  208.         'Square Root
  209.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 75 AND mouseY < 130 THEN
  210.             IF num < 0 THEN GOTO skip1:
  211.             num = VAL(num$)
  212.             num = SQR(num)
  213.             num$ = STR$(num)
  214.             skip1:
  215.             buttonx = 50: buttony = 75
  216.             GOSUB press:
  217.             GOSUB number:
  218.         END IF
  219.  
  220.         'Sine
  221.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 75 AND mouseY < 130 THEN
  222.             IF deg = 1 THEN num = SIN(_D2R(VAL(num$)))
  223.             IF deg = 0 THEN num = SIN(num)
  224.             num$ = STR$(num)
  225.             buttonx = 126: buttony = 75
  226.             GOSUB press:
  227.             GOSUB number:
  228.         END IF
  229.  
  230.         'Cosine
  231.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 75 AND mouseY < 130 THEN
  232.             IF deg = 1 THEN num = COS(_D2R(VAL(num$)))
  233.             IF deg = 0 THEN num = COS(num)
  234.             num$ = STR$(num)
  235.             buttonx = 200: buttony = 75
  236.             GOSUB press:
  237.             GOSUB number:
  238.         END IF
  239.  
  240.         'Tangent
  241.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 75 AND mouseY < 130 THEN
  242.             IF deg = 1 THEN num = TAN(_D2R(VAL(num$)))
  243.             IF deg = 0 THEN num = TAN(num)
  244.             num$ = STR$(num)
  245.             buttonx = 275: buttony = 75
  246.             GOSUB press:
  247.             GOSUB number:
  248.         END IF
  249.  
  250.         'Number Buttons
  251.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 130 AND mouseY < 185 THEN
  252.             num$ = num$ + "7"
  253.             IF n = 1 THEN num$ = "-" + num$: n = 0
  254.             buttonx = 50: buttony = 130
  255.             GOSUB press:
  256.             GOSUB number:
  257.         END IF
  258.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 130 AND mouseY < 185 THEN
  259.             num$ = num$ + "8"
  260.             IF n = 1 THEN num$ = "-" + num$: n = 0
  261.             buttonx = 126: buttony = 130
  262.             GOSUB press:
  263.             GOSUB number:
  264.         END IF
  265.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 130 AND mouseY < 185 THEN
  266.             num$ = num$ + "9"
  267.             IF n = 1 THEN num$ = "-" + num$: n = 0
  268.             buttonx = 200: buttony = 130
  269.             GOSUB press:
  270.             GOSUB number:
  271.         END IF
  272.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 185 AND mouseY < 240 THEN
  273.             num$ = num$ + "4"
  274.             IF n = 1 THEN num$ = "-" + num$: n = 0
  275.             buttonx = 50: buttony = 185
  276.             GOSUB press:
  277.             GOSUB number:
  278.         END IF
  279.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 185 AND mouseY < 240 THEN
  280.             num$ = num$ + "5"
  281.             IF n = 1 THEN num$ = "-" + num$: n = 0
  282.             buttonx = 126: buttony = 185
  283.             GOSUB press:
  284.             GOSUB number:
  285.         END IF
  286.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 185 AND mouseY < 240 THEN
  287.             num$ = num$ + "6"
  288.             IF n = 1 THEN num$ = "-" + num$: n = 0
  289.             buttonx = 200: buttony = 185
  290.             GOSUB press:
  291.             GOSUB number:
  292.         END IF
  293.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 240 AND mouseY < 295 THEN
  294.             num$ = num$ + "1"
  295.             IF n = 1 THEN num$ = "-" + num$: n = 0
  296.             buttonx = 50: buttony = 240
  297.             GOSUB press:
  298.             GOSUB number:
  299.         END IF
  300.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 240 AND mouseY < 295 THEN
  301.             num$ = num$ + "2"
  302.             IF n = 1 THEN num$ = "-" + num$: n = 0
  303.             buttonx = 126: buttony = 240
  304.             GOSUB press:
  305.             GOSUB number:
  306.         END IF
  307.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 240 AND mouseY < 295 THEN
  308.             num$ = num$ + "3"
  309.             IF n = 1 THEN num$ = "-" + num$: n = 0
  310.             buttonx = 200: buttony = 240
  311.             GOSUB press:
  312.             GOSUB number:
  313.         END IF
  314.         IF mouseX > 50 AND mouseX < 125 AND mouseY > 295 AND mouseY < 350 THEN
  315.             num$ = num$ + "0"
  316.             IF n = 1 THEN num$ = "-" + num$: n = 0
  317.             buttonx = 50: buttony = 295
  318.             GOSUB press:
  319.             GOSUB number:
  320.         END IF
  321.  
  322.         'Decimal
  323.         IF mouseX > 126 AND mouseX < 200 AND mouseY > 295 AND mouseY < 350 THEN
  324.             buttonx = 126: buttony = 295
  325.             FOR check = 1 TO LEN(num$)
  326.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  327.             NEXT check
  328.             num$ = num$ + "."
  329.             _PRINTSTRING (55, 30), num$
  330.             skipdec:
  331.             GOSUB press:
  332.         END IF
  333.  
  334.         'Equals
  335.         IF mouseX > 200 AND mouseX < 275 AND mouseY > 295 AND mouseY < 350 THEN
  336.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  337.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  338.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  339.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  340.             buttonx = 200: buttony = 295
  341.             GOSUB press:
  342.             GOSUB number2:
  343.         END IF
  344.  
  345.         'Add
  346.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 295 AND mouseY < 350 THEN
  347.             IF a = 0 THEN
  348.                 d = 0: a = 1: s = 0: t = 0
  349.                 oldnum$ = num$
  350.                 _PRINTSTRING (55, 30), "                          "
  351.                 num$ = ""
  352.                 GOTO nex4:
  353.             END IF
  354.             IF a = 1 THEN
  355.                 num = VAL(oldnum$) + VAL(num$)
  356.                 a = 0
  357.             END IF
  358.             GOSUB number2:
  359.             nex4:
  360.             buttonx = 275: buttony = 295
  361.             GOSUB press:
  362.         END IF
  363.  
  364.         'Subtract
  365.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 240 AND mouseY < 295 THEN
  366.             IF s = 0 THEN
  367.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  368.                 d = 0: a = 0: s = 1: t = 0
  369.                 oldnum$ = num$
  370.                 _PRINTSTRING (55, 30), "                          "
  371.                 num$ = ""
  372.                 GOTO nex3:
  373.             END IF
  374.             IF s = 1 THEN
  375.                 num = VAL(oldnum$) - VAL(num$)
  376.                 s = 0
  377.             END IF
  378.             GOSUB number2:
  379.             nex3:
  380.             buttonx = 275: buttony = 240
  381.             GOSUB press:
  382.         END IF
  383.  
  384.         'Multiply
  385.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 185 AND mouseY < 240 THEN
  386.             IF t = 0 THEN
  387.                 d = 0: a = 0: s = 0: t = 1
  388.                 oldnum$ = num$
  389.                 _PRINTSTRING (55, 30), "                          "
  390.                 num$ = ""
  391.                 GOTO nex2:
  392.             END IF
  393.             IF t = 1 THEN
  394.                 num = VAL(oldnum$) * VAL(num$)
  395.                 t = 0
  396.             END IF
  397.             GOSUB number2:
  398.             nex2:
  399.             buttonx = 275: buttony = 185
  400.             GOSUB press:
  401.         END IF
  402.  
  403.         'Divide
  404.         IF mouseX > 275 AND mouseX < 350 AND mouseY > 130 AND mouseY < 185 THEN
  405.             IF d = 0 THEN
  406.                 d = 1: a = 0: s = 0: t = 0
  407.                 oldnum$ = num$
  408.                 _PRINTSTRING (55, 30), "                          "
  409.                 num$ = ""
  410.                 GOTO nex1:
  411.             END IF
  412.             IF d = 1 AND num$ <> "" THEN
  413.                 num = VAL(oldnum$) / VAL(num$)
  414.                 d = 0
  415.             END IF
  416.             GOSUB number2:
  417.             nex1:
  418.             buttonx = 275: buttony = 130
  419.             GOSUB press:
  420.         END IF
  421.     END IF
  422. 'For Number Buttons.
  423. number:
  424. num = VAL(num$)
  425.  
  426. 'For Math
  427. number2:
  428. COLOR _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  429. _PRINTSTRING (55, 30), "                          "
  430. num$ = STR$(num)
  431. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  432. _PRINTSTRING (55, 30), num$
  433.  
  434.  
  435. 'Pressing Each Button
  436. press:
  437. c = 110
  438. FOR bb = 0 TO 10
  439.     c = c - 10
  440.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  441. NEXT bb
  442. _DELAY .25
  443. FOR bb = 0 TO 10
  444.     c = c + 10
  445.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  446. NEXT bb
  447.  
  448. 'Pressing the Green C Button.
  449. zero:
  450. c = 110
  451. FOR bb = 0 TO 10
  452.     c = c - 10
  453.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  454. NEXT bb
  455. _DELAY .25
  456. FOR bb = 0 TO 10
  457.     c = c + 10
  458.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  459. NEXT bb
  460.  
  461. 'This Function is from Dav which makes the icon picture. It uses code at the start of this program.
  462. FUNCTION BASIMAGE1& 'calculatio icon data
  463.     v& = _NEWIMAGE(54, 48, 32)
  464.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  465.     A$ = ""
  466.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  467.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  468.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  469.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  470.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  471.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  472.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  473.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  474.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  475.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  476.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  477.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  478.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  479.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  480.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  481.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  482.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  483.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  484.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  485.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  486.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  487.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  488.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  489.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  490.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  491.     btemp$ = ""
  492.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  493.         IF INSTR(1, B$, "%") THEN
  494.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  495.                 IF F$ <> "%" THEN C$ = C$ + F$
  496.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  497.             IF MID$(B$, j, 1) = "#" THEN
  498.         MID$(B$, j) = "@": END IF: NEXT
  499.         FOR t% = LEN(B$) TO 1 STEP -1
  500.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  501.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  502.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  503.     NEXT: btemp$ = btemp$ + X$: NEXT
  504.     btemp$ = _INFLATE$(btemp$)
  505.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  506.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  507.  
Title: Re: Calculator
Post by: bplus on July 30, 2020, 11:26:53 am
What is really handy for calculators is an extra Memory key to hold a value and modify it, also this not being a real calculator you could show the previous value and the operation button. In fact, if you aren't a big fan of Ln(x) or e^(x) you might rearrange buttons for extra memory value. Also more handy than Ln and e is X^Y so you could do 2^8 or 3^5...
Title: Re: Calculator
Post by: SpriggsySpriggs on July 30, 2020, 12:10:50 pm
That's a good-looking calculator. Works quite well. Have you thought about adding keyboard functionality?
Title: Re: Calculator
Post by: SierraKen on July 30, 2020, 12:42:36 pm
B+, X^Y is what I made EXP to begin with because I thought that's what the EXP button does lol. But I changed it to how you wanted me to yesterday. As for the rest of the stuff, I personally don't have a need for them. I never use the memory buttons or anything else actually. As for the X^Y, probably sometime. Today I'm probably going to take a break on it. I hurt my wrist the other day when I fell down outside and today it's not doing too great.
Thanks for the suggestions though. If I really want to dive into all those things sometime, I might.

Spriggs, yes I've thought about adding keyboard use to it, like everything on the number pad. And maybe S = Sine, C = Cosine, T = Tangent, etc. It shouldn't be too hard with just INKEY$ so I probably will soon. Thanks for the suggestion.

If any of you want to tinker with this for yourself on your own mods, go right ahead. It's for all of us.
 

Title: Re: Calculator
Post by: SierraKen on July 30, 2020, 03:19:34 pm
I just added keyboard control to everything. :) I also made a Help page that describes what all the keys do. Press Esc to get to the Help page. It says this in the _TITLE as well. It's pretty neat how when you press a key on the keyboard for something, it shows the key on the calculator being pressed. When using the Number Pad (which you can use that or the others), make sure you have Num Lock turned on.

Code: QB64: [Select]
  1. 'Calculator
  2. 'By SierraKen on July 30, 2020.
  3. '------------------------------
  4. 'This is my very first regular calculator.
  5. 'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
  6. 'This was a 4 day project and I've wanted to make this all my life. Ever since I was real little
  7. 'playing around with my parents' calculator.
  8. 'Thank you Dav for the icon code!
  9. 'Added Clipboard by clicking the output number.
  10. 'Added Rad2Deg (and Deg2Rad), second power, Base 10 Logarithm, and Pi buttons.
  11. 'Added 1/x, x/2, exp, postive or negative.
  12. 'Added keyboard control and help page.
  13.  
  14. 'Load the icon - call this somewhere near the top of your program
  15. _ICON BASIMAGE1&
  16.  
  17. _TITLE "Calculator - Esc for help."
  18. SCREEN _NEWIMAGE(400, 500, 32)
  19. begin:
  20. num$ = ""
  21. c = 0
  22. a = 0: s = 0: t = 0: d = 0
  23. 'Setup calculator
  24. LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
  25. LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
  26. 'Buttons
  27. FOR buttony = 75 TO 405 STEP 55
  28.     FOR buttonx = 50 TO 275 STEP 75
  29.         FOR bb = 0 TO 10
  30.             c = c + 10
  31.             LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  32.         NEXT bb
  33.         PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
  34.         c = 0
  35.     NEXT buttonx
  36. NEXT buttony
  37. buttonx = 275: buttony = 20
  38. 'Green C Button
  39. FOR bb = 0 TO 10
  40.     c = c + 10
  41.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  42. NEXT bb
  43. PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
  44. COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  45. _PRINTSTRING (50, 5), "Rad"
  46. wer:
  47. 'Label Buttons
  48. _PRINTSTRING (312, 47), "C"
  49. COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  50. _PRINTSTRING (87, 102), CHR$(251) 'square root
  51. _PRINTSTRING (152, 102), "sin"
  52. _PRINTSTRING (227, 102), "cos"
  53. _PRINTSTRING (302, 102), "tan"
  54. _PRINTSTRING (87, 157), "7"
  55. _PRINTSTRING (162, 157), "8"
  56. _PRINTSTRING (237, 157), "9"
  57. _PRINTSTRING (312, 157), "/"
  58. _PRINTSTRING (87, 212), "4"
  59. _PRINTSTRING (162, 212), "5"
  60. _PRINTSTRING (237, 212), "6"
  61. _PRINTSTRING (312, 212), "x"
  62. _PRINTSTRING (87, 267), "1"
  63. _PRINTSTRING (162, 267), "2"
  64. _PRINTSTRING (237, 267), "3"
  65. _PRINTSTRING (312, 267), "-"
  66. _PRINTSTRING (87, 322), "0"
  67. _PRINTSTRING (162, 322), "."
  68. _PRINTSTRING (237, 322), "="
  69. _PRINTSTRING (312, 322), "+"
  70. _PRINTSTRING (79, 377), "deg"
  71. _PRINTSTRING (162, 377), "x" + CHR$(253) 'second power
  72. _PRINTSTRING (227, 377), "log"
  73. _PRINTSTRING (307, 377), "Pi"
  74. _PRINTSTRING (79, 432), "1/x"
  75. _PRINTSTRING (152, 432), "x/2"
  76. _PRINTSTRING (227, 432), "exp"
  77. _PRINTSTRING (312, 432), CHR$(241) 'Postive or Negative
  78.  
  79. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  80.     _LIMIT 20
  81.     a$ = INKEY$
  82.     IF a$ <> "" THEN mousex = 0: mousey = 0: mouseLeftButton = 0
  83.     IF a$ = CHR$(27) THEN GOTO help:
  84.     IF a$ = CHR$(3) THEN a$ = "": GOTO clip: 'Ctrl+C copies to clipboard.
  85.     IF a$ = CHR$(8) THEN a$ = "": GOTO delete: 'Back Space deletes output.
  86.     IF a$ = "p" OR a$ = "P" OR a$ = "n" OR a$ = "N" THEN a$ = "": GOTO posneg: 'Positive or Negative
  87.     IF a$ = "f" OR a$ = "F" THEN a$ = "": GOTO fraction:
  88.     IF a$ = "h" OR a$ = "H" THEN a$ = "": GOTO half:
  89.     IF a$ = "e" OR a$ = "E" THEN a$ = "": GOTO expcommand:
  90.     IF a$ = "r" OR a$ = "R" OR a$ = "d" OR a$ = "D" THEN a$ = "": GOTO radanddeg:
  91.     IF a$ = "u" OR a$ = "U" THEN a$ = "": GOTO squared:
  92.     IF a$ = "l" OR a$ = "L" THEN a$ = "": GOTO logarithm:
  93.     IF a$ = "i" OR a$ = "I" THEN a$ = "": GOTO pi:
  94.     IF a$ = "q" OR a$ = "Q" THEN a$ = "": GOTO squareroot:
  95.     IF a$ = "s" OR a$ = "S" THEN a$ = "": GOTO sine:
  96.     IF a$ = "c" OR a$ = "C" THEN a$ = "": GOTO cosine:
  97.     IF a$ = "t" OR a$ = "T" THEN a$ = "": GOTO tangent:
  98.     IF a$ = "1" THEN a$ = "": GOTO one:
  99.     IF a$ = "2" THEN a$ = "": GOTO two:
  100.     IF a$ = "3" THEN a$ = "": GOTO three:
  101.     IF a$ = "4" THEN a$ = "": GOTO four:
  102.     IF a$ = "5" THEN a$ = "": GOTO five:
  103.     IF a$ = "6" THEN a$ = "": GOTO six:
  104.     IF a$ = "7" THEN a$ = "": GOTO seven:
  105.     IF a$ = "8" THEN a$ = "": GOTO eight:
  106.     IF a$ = "9" THEN a$ = "": GOTO nine:
  107.     IF a$ = "0" THEN a$ = "": GOTO zero2:
  108.     IF a$ = "." THEN a$ = "": GOTO decimal:
  109.     IF a$ = "=" THEN a$ = "": GOTO equals:
  110.     IF a$ = "+" THEN a$ = "": GOTO add:
  111.     IF a$ = "-" THEN a$ = "": GOTO subtract:
  112.     IF a$ = "*" OR a$ = "x" OR a$ = "X" THEN a$ = "": GOTO multiply:
  113.     IF a$ = "/" THEN a$ = "": GOTO divide:
  114.  
  115.         mousex = _MOUSEX
  116.         mousey = _MOUSEY
  117.         mouseLeftButton = _MOUSEBUTTON(1)
  118.     LOOP
  119.     IF mouseLeftButton THEN
  120.         mouseLeftButton = 0
  121.  
  122.         'Clipboard
  123.         IF mousex > 50 AND mousex < 265 AND mousey > 25 AND mousey < 50 THEN
  124.             clip:
  125.             COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
  126.             _PRINTSTRING (55, 30), num$
  127.             _DELAY 1
  128.             num2$ = _TRIM$(num$)
  129.             _CLIPBOARD$ = num2$
  130.             COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  131.             _PRINTSTRING (55, 30), num$
  132.         END IF
  133.  
  134.         'Clear
  135.         IF mousex > 275 AND mousex < 350 AND mousey > 20 AND mousey < 75 THEN
  136.             delete:
  137.             a = 0: s = 0: t = 0: d = 0: num$ = ""
  138.             _PRINTSTRING (55, 30), "                          "
  139.             buttonx = 275: buttony = 20
  140.             GOSUB zero:
  141.         END IF
  142.  
  143.         '1/x
  144.         IF mousex > 50 AND mousex < 125 AND mousey > 405 AND mousey < 460 THEN
  145.             fraction:
  146.             num = VAL(num$)
  147.             IF num = 0 THEN GOTO skipthis:
  148.             num = 1 / num
  149.             num$ = STR$(num)
  150.             skipthis:
  151.             buttonx = 50: buttony = 405
  152.             GOSUB press:
  153.             GOSUB number:
  154.         END IF
  155.  
  156.         'x/2
  157.         IF mousex > 126 AND mousex < 200 AND mousey > 405 AND mousey < 460 THEN
  158.             half:
  159.             num = VAL(num$)
  160.             num = num / 2
  161.             num$ = STR$(num)
  162.             buttonx = 126: buttony = 405
  163.             GOSUB press:
  164.             GOSUB number2:
  165.         END IF
  166.  
  167.         'EXP
  168.         IF mousex > 200 AND mousex < 275 AND mousey > 405 AND mousey < 460 THEN
  169.             expcommand:
  170.             _PRINTSTRING (55, 30), "                          "
  171.             num = EXP(VAL(num$))
  172.             num$ = STR$(num)
  173.             buttonx = 200: buttony = 405
  174.             GOSUB number2:
  175.             GOSUB press:
  176.         END IF
  177.  
  178.         'Postive or Negative
  179.         IF mousex > 275 AND mousex < 350 AND mousey > 405 AND mousey < 460 THEN
  180.             posneg:
  181.             IF VAL(num$) < 0 THEN
  182.                 num = -VAL(num$)
  183.                 num$ = STR$(num)
  184.                 GOTO skipplusnegative:
  185.             END IF
  186.             num$ = "-" + num$
  187.             skipplusnegative:
  188.             buttonx = 275: buttony = 405
  189.             GOSUB press:
  190.             GOSUB number:
  191.         END IF
  192.  
  193.         'Radians and Degrees
  194.         IF mousex > 50 AND mousex < 125 AND mousey > 350 AND mousey < 405 THEN
  195.             radanddeg:
  196.             deg = deg + 1
  197.             IF deg = 2 THEN GOTO deg2rad:
  198.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  199.             _PRINTSTRING (79, 377), "rad"
  200.             COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  201.             _PRINTSTRING (50, 5), "Deg"
  202.             num = VAL(num$)
  203.             num = _R2D(num)
  204.             num$ = STR$(num)
  205.             GOTO skipdeg2rad:
  206.             deg2rad:
  207.             deg = 0
  208.             COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
  209.             _PRINTSTRING (79, 377), "deg"
  210.             COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
  211.             _PRINTSTRING (50, 5), "Rad"
  212.             num = VAL(num$)
  213.             num = _D2R(num)
  214.             num$ = STR$(num)
  215.             skipdeg2rad:
  216.             buttonx = 50: buttony = 350
  217.             GOSUB press:
  218.             GOSUB number:
  219.         END IF
  220.  
  221.         'Second Power
  222.         IF mousex > 126 AND mousex < 200 AND mousey > 350 AND mousey < 405 THEN
  223.             squared:
  224.             num = VAL(num$)
  225.             num = num ^ 2
  226.             num$ = STR$(num)
  227.             buttonx = 126: buttony = 350
  228.             GOSUB press:
  229.             GOSUB number:
  230.         END IF
  231.  
  232.         'logarithm
  233.         IF mousex > 200 AND mousex < 275 AND mousey > 350 AND mousey < 405 THEN
  234.             logarithm:
  235.             num = VAL(num$)
  236.             IF num = 0 THEN GOTO skiplog:
  237.             IF num < 0 THEN GOTO skiplog:
  238.             num = LOG(num)
  239.             num$ = STR$(num)
  240.             skiplog:
  241.             buttonx = 200: buttony = 350
  242.             GOSUB press:
  243.             GOSUB number:
  244.         END IF
  245.  
  246.         'Pi
  247.         IF mousex > 275 AND mousex < 350 AND mousey > 350 AND mousey < 405 THEN
  248.             pi:
  249.             num = _PI
  250.             num$ = STR$(num)
  251.             buttonx = 275: buttony = 350
  252.             GOSUB press:
  253.             GOSUB number:
  254.         END IF
  255.  
  256.         'Square Root
  257.         IF mousex > 50 AND mousex < 125 AND mousey > 75 AND mousey < 130 THEN
  258.             squareroot:
  259.             IF num < 0 THEN GOTO skip1:
  260.             num = VAL(num$)
  261.             num = SQR(num)
  262.             num$ = STR$(num)
  263.             skip1:
  264.             buttonx = 50: buttony = 75
  265.             GOSUB press:
  266.             GOSUB number:
  267.         END IF
  268.  
  269.         'Sine
  270.         IF mousex > 126 AND mousex < 200 AND mousey > 75 AND mousey < 130 THEN
  271.             sine:
  272.             IF deg = 1 THEN num = SIN(_D2R(VAL(num$)))
  273.             IF deg = 0 THEN num = SIN(num)
  274.             num$ = STR$(num)
  275.             buttonx = 126: buttony = 75
  276.             GOSUB press:
  277.             GOSUB number:
  278.         END IF
  279.  
  280.         'Cosine
  281.         IF mousex > 200 AND mousex < 275 AND mousey > 75 AND mousey < 130 THEN
  282.             cosine:
  283.             IF deg = 1 THEN num = COS(_D2R(VAL(num$)))
  284.             IF deg = 0 THEN num = COS(num)
  285.             num$ = STR$(num)
  286.             buttonx = 200: buttony = 75
  287.             GOSUB press:
  288.             GOSUB number:
  289.         END IF
  290.  
  291.         'Tangent
  292.         IF mousex > 275 AND mousex < 350 AND mousey > 75 AND mousey < 130 THEN
  293.             tangent:
  294.             IF deg = 1 THEN num = TAN(_D2R(VAL(num$)))
  295.             IF deg = 0 THEN num = TAN(num)
  296.             num$ = STR$(num)
  297.             buttonx = 275: buttony = 75
  298.             GOSUB press:
  299.             GOSUB number:
  300.         END IF
  301.  
  302.         'Number Buttons
  303.         IF mousex > 50 AND mousex < 125 AND mousey > 130 AND mousey < 185 THEN
  304.             seven:
  305.             num$ = num$ + "7"
  306.             IF n = 1 THEN num$ = "-" + num$: n = 0
  307.             buttonx = 50: buttony = 130
  308.             GOSUB press:
  309.             GOSUB number:
  310.         END IF
  311.         IF mousex > 126 AND mousex < 200 AND mousey > 130 AND mousey < 185 THEN
  312.             eight:
  313.             num$ = num$ + "8"
  314.             IF n = 1 THEN num$ = "-" + num$: n = 0
  315.             buttonx = 126: buttony = 130
  316.             GOSUB press:
  317.             GOSUB number:
  318.         END IF
  319.         IF mousex > 200 AND mousex < 275 AND mousey > 130 AND mousey < 185 THEN
  320.             nine:
  321.             num$ = num$ + "9"
  322.             IF n = 1 THEN num$ = "-" + num$: n = 0
  323.             buttonx = 200: buttony = 130
  324.             GOSUB press:
  325.             GOSUB number:
  326.         END IF
  327.         IF mousex > 50 AND mousex < 125 AND mousey > 185 AND mousey < 240 THEN
  328.             four:
  329.             num$ = num$ + "4"
  330.             IF n = 1 THEN num$ = "-" + num$: n = 0
  331.             buttonx = 50: buttony = 185
  332.             GOSUB press:
  333.             GOSUB number:
  334.         END IF
  335.         IF mousex > 126 AND mousex < 200 AND mousey > 185 AND mousey < 240 THEN
  336.             five:
  337.             num$ = num$ + "5"
  338.             IF n = 1 THEN num$ = "-" + num$: n = 0
  339.             buttonx = 126: buttony = 185
  340.             GOSUB press:
  341.             GOSUB number:
  342.         END IF
  343.         IF mousex > 200 AND mousex < 275 AND mousey > 185 AND mousey < 240 THEN
  344.             six:
  345.             num$ = num$ + "6"
  346.             IF n = 1 THEN num$ = "-" + num$: n = 0
  347.             buttonx = 200: buttony = 185
  348.             GOSUB press:
  349.             GOSUB number:
  350.         END IF
  351.         IF mousex > 50 AND mousex < 125 AND mousey > 240 AND mousey < 295 THEN
  352.             one:
  353.             num$ = num$ + "1"
  354.             IF n = 1 THEN num$ = "-" + num$: n = 0
  355.             buttonx = 50: buttony = 240
  356.             GOSUB press:
  357.             GOSUB number:
  358.         END IF
  359.         IF mousex > 126 AND mousex < 200 AND mousey > 240 AND mousey < 295 THEN
  360.             two:
  361.             num$ = num$ + "2"
  362.             IF n = 1 THEN num$ = "-" + num$: n = 0
  363.             buttonx = 126: buttony = 240
  364.             GOSUB press:
  365.             GOSUB number:
  366.         END IF
  367.         IF mousex > 200 AND mousex < 275 AND mousey > 240 AND mousey < 295 THEN
  368.             three:
  369.             num$ = num$ + "3"
  370.             IF n = 1 THEN num$ = "-" + num$: n = 0
  371.             buttonx = 200: buttony = 240
  372.             GOSUB press:
  373.             GOSUB number:
  374.         END IF
  375.         IF mousex > 50 AND mousex < 125 AND mousey > 295 AND mousey < 350 THEN
  376.             zero2:
  377.             num$ = num$ + "0"
  378.             IF n = 1 THEN num$ = "-" + num$: n = 0
  379.             buttonx = 50: buttony = 295
  380.             GOSUB press:
  381.             GOSUB number:
  382.         END IF
  383.  
  384.         'Decimal
  385.         IF mousex > 126 AND mousex < 200 AND mousey > 295 AND mousey < 350 THEN
  386.             decimal:
  387.             buttonx = 126: buttony = 295
  388.             FOR check = 1 TO LEN(num$)
  389.                 IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
  390.             NEXT check
  391.             num$ = num$ + "."
  392.             _PRINTSTRING (55, 30), num$
  393.             skipdec:
  394.             GOSUB press:
  395.         END IF
  396.  
  397.         'Equals
  398.         IF mousex > 200 AND mousex < 275 AND mousey > 295 AND mousey < 350 THEN
  399.             equals:
  400.             IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
  401.             IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
  402.             IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
  403.             IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0
  404.             buttonx = 200: buttony = 295
  405.             GOSUB press:
  406.             GOSUB number2:
  407.         END IF
  408.  
  409.         'Add
  410.         IF mousex > 275 AND mousex < 350 AND mousey > 295 AND mousey < 350 THEN
  411.             add:
  412.             IF a = 0 THEN
  413.                 d = 0: a = 1: s = 0: t = 0
  414.                 oldnum$ = num$
  415.                 _PRINTSTRING (55, 30), "                          "
  416.                 num$ = ""
  417.                 GOTO nex4:
  418.             END IF
  419.             IF a = 1 THEN
  420.                 num = VAL(oldnum$) + VAL(num$)
  421.                 a = 0
  422.             END IF
  423.             GOSUB number2:
  424.             nex4:
  425.             buttonx = 275: buttony = 295
  426.             GOSUB press:
  427.         END IF
  428.  
  429.         'Subtract
  430.         IF mousex > 275 AND mousex < 350 AND mousey > 240 AND mousey < 295 THEN
  431.             subtract:
  432.             IF s = 0 THEN
  433.                 IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
  434.                 d = 0: a = 0: s = 1: t = 0
  435.                 oldnum$ = num$
  436.                 _PRINTSTRING (55, 30), "                          "
  437.                 num$ = ""
  438.                 GOTO nex3:
  439.             END IF
  440.             IF s = 1 THEN
  441.                 num = VAL(oldnum$) - VAL(num$)
  442.                 s = 0
  443.             END IF
  444.             GOSUB number2:
  445.             nex3:
  446.             buttonx = 275: buttony = 240
  447.             GOSUB press:
  448.         END IF
  449.  
  450.         'Multiply
  451.         IF mousex > 275 AND mousex < 350 AND mousey > 185 AND mousey < 240 THEN
  452.             multiply:
  453.             IF t = 0 THEN
  454.                 d = 0: a = 0: s = 0: t = 1
  455.                 oldnum$ = num$
  456.                 _PRINTSTRING (55, 30), "                          "
  457.                 num$ = ""
  458.                 GOTO nex2:
  459.             END IF
  460.             IF t = 1 THEN
  461.                 num = VAL(oldnum$) * VAL(num$)
  462.                 t = 0
  463.             END IF
  464.             GOSUB number2:
  465.             nex2:
  466.             buttonx = 275: buttony = 185
  467.             GOSUB press:
  468.         END IF
  469.  
  470.         'Divide
  471.         IF mousex > 275 AND mousex < 350 AND mousey > 130 AND mousey < 185 THEN
  472.             divide:
  473.             IF d = 0 THEN
  474.                 d = 1: a = 0: s = 0: t = 0
  475.                 oldnum$ = num$
  476.                 _PRINTSTRING (55, 30), "                          "
  477.                 num$ = ""
  478.                 GOTO nex1:
  479.             END IF
  480.             IF d = 1 AND num$ <> "" THEN
  481.                 num = VAL(oldnum$) / VAL(num$)
  482.                 d = 0
  483.             END IF
  484.             GOSUB number2:
  485.             nex1:
  486.             buttonx = 275: buttony = 130
  487.             GOSUB press:
  488.         END IF
  489.     END IF
  490. 'For Number Buttons.
  491. number:
  492. num = VAL(num$)
  493.  
  494. 'For Math
  495. number2:
  496. COLOR _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  497. _PRINTSTRING (55, 30), "                          "
  498. num$ = STR$(num)
  499. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  500. _PRINTSTRING (55, 30), num$
  501.  
  502.  
  503. 'Pressing Each Button
  504. press:
  505. c = 110
  506. FOR bb = 0 TO 10
  507.     c = c - 10
  508.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  509. NEXT bb
  510. _DELAY .25
  511. FOR bb = 0 TO 10
  512.     c = c + 10
  513.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
  514. NEXT bb
  515.  
  516. 'Pressing the Green C Button.
  517. zero:
  518. c = 110
  519. FOR bb = 0 TO 10
  520.     c = c - 10
  521.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  522. NEXT bb
  523. _DELAY .25
  524. FOR bb = 0 TO 10
  525.     c = c + 10
  526.     LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
  527. NEXT bb
  528.  
  529. help:
  530. _TITLE "Calculator Help"
  531. PRINT "Esc = Keyboard Help"
  532. PRINT "CTRL+C = Copies Output To Clipboard"
  533. PRINT "Left Mouse Click Output Copies To Clipboard."
  534. PRINT "Backspace = Deletes Output"
  535. PRINT "Letters can be upper or lower-case."
  536. PRINT "P or N = Positve and Negative Switch."
  537. PRINT "F = 1 / x"
  538. PRINT "H = x / 2"
  539. PRINT "E = EXP"
  540. PRINT "R or D = Radian and Degree Switch."
  541. PRINT "U = X ^ 2"
  542. PRINT "L = Logarithm"
  543. PRINT "I = Pi"
  544. PRINT "Q = Square Root"
  545. PRINT "s = Sine"
  546. PRINT "c = Cosine"
  547. PRINT "t = Tangent"
  548. PRINT "Below can be either Number Pad or the others."
  549. PRINT "1-9 = Number Keys"
  550. PRINT ". = Decimal"
  551. PRINT "= = Equals"
  552. PRINT "+ = Add"
  553. PRINT "- = Subtract"
  554. PRINT "* or X = Multiply"
  555. PRINT "/ = Divide"
  556. PRINT "Press Esc to go back to calculator."
  557. _TITLE "Calculator - Esc for help."
  558. GOTO begin:
  559.  
  560.  
  561. 'This Function is from Dav which makes the icon picture. It uses code at the start of this program.
  562. FUNCTION BASIMAGE1& 'calculatio icon data
  563.     v& = _NEWIMAGE(54, 48, 32)
  564.     DIM m AS _MEM: m = _MEMIMAGE(v&)
  565.     A$ = ""
  566.     A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
  567.     A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
  568.     A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
  569.     A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
  570.     A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
  571.     A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
  572.     A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
  573.     A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
  574.     A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
  575.     A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
  576.     A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
  577.     A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
  578.     A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
  579.     A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
  580.     A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
  581.     A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
  582.     A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
  583.     A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
  584.     A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
  585.     A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
  586.     A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
  587.     A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
  588.     A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
  589.     A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
  590.     A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
  591.     btemp$ = ""
  592.     FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  593.         IF INSTR(1, B$, "%") THEN
  594.             FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  595.                 IF F$ <> "%" THEN C$ = C$ + F$
  596.             NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  597.             IF MID$(B$, j, 1) = "#" THEN
  598.         MID$(B$, j) = "@": END IF: NEXT
  599.         FOR t% = LEN(B$) TO 1 STEP -1
  600.             B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  601.             NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  602.             X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  603.     NEXT: btemp$ = btemp$ + X$: NEXT
  604.     btemp$ = _INFLATE$(btemp$)
  605.     _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
  606.     BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
  607.