Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculator
#41
This should address the backspace issue.

Code: (Select All)
'Calculator
'By SierraKen on July 30, 2020.
'Updated on July 24, 2022 with Copy and Paste Buttons.
'Updated on July 26, 2022 with Back Space Button and RND (Random) Button
'-----------------------------------------------------------------------
'This is my very first regular calculator.
'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
'Thank you Dav for the icon code!

_ICON BASIMAGE1&

_TITLE "Calculator - Esc for help."
DIM num AS DOUBLE
SCREEN _NEWIMAGE(400, 525, 32)
f& = _LOADFONT("Arial.ttf", 18)
begin:
_FONT f&
num$ = ""
c = 0
a = 0: s = 0: t = 0: d = 0
'Setup calculator
LINE (50, 25)-(265, 50), _RGB32(255, 255, 255), B
LINE (50, 75)-(350, 350), _RGB32(255, 255, 255), B
'Buttons
FOR buttony = 75 TO 405 STEP 55
    FOR buttonx = 50 TO 275 STEP 75
        FOR bb = 0 TO 10
            c = c + 10
            LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
        NEXT bb
        PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
        c = 0
    NEXT buttonx
NEXT buttony
'Copy Button
buttonx = 50: buttony = 460
FOR bb = 0 TO 10
    c = c + 10
    LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Paste Button
buttonx = 125: buttony = 460
FOR bb = 0 TO 10
    c = c + 10
    LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Back Space Button
buttonx = 200: buttony = 460
FOR bb = 0 TO 10
    c = c + 10
    LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Time Button
buttonx = 275: buttony = 460
FOR bb = 0 TO 10
    c = c + 10
    LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Green C Button
buttonx = 275: buttony = 20
FOR bb = 0 TO 10
    c = c + 10
    LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
NEXT bb
PAINT (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
_PRINTSTRING (50, 5), "Rad"
wer:
'Label Buttons
_PRINTSTRING (306, 47), "C"
COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
_PRINTSTRING (87, 102), CHR$(251) 'square root
_PRINTSTRING (152, 102), "sin"
_PRINTSTRING (227, 102), "cos"
_PRINTSTRING (302, 102), "tan"
_PRINTSTRING (87, 157), "7"
_PRINTSTRING (162, 157), "8"
_PRINTSTRING (237, 157), "9"
_PRINTSTRING (312, 157), "/"
_PRINTSTRING (87, 212), "4"
_PRINTSTRING (162, 212), "5"
_PRINTSTRING (237, 212), "6"
_PRINTSTRING (312, 212), "x"
_PRINTSTRING (87, 267), "1"
_PRINTSTRING (162, 267), "2"
_PRINTSTRING (237, 267), "3"
_PRINTSTRING (312, 267), "-"
_PRINTSTRING (87, 322), "0"
_PRINTSTRING (162, 322), "."
_PRINTSTRING (237, 322), "="
_PRINTSTRING (312, 322), "+"
_PRINTSTRING (79, 377), "     "
_PRINTSTRING (79, 377), "deg"
_PRINTSTRING (162, 377), "x" + CHR$(253) 'second power
_PRINTSTRING (227, 377), "log"
_PRINTSTRING (307, 377), "Pi"
_PRINTSTRING (79, 432), "1/x"
_PRINTSTRING (152, 432), "x/2"
_PRINTSTRING (227, 432), "exp"
_PRINTSTRING (312, 432), CHR$(241) 'Postive or Negative
_PRINTSTRING (68, 487), "Copy"
_PRINTSTRING (141, 487), "Paste"
_PRINTSTRING (210, 487), "<Back"
_PRINTSTRING (293, 487), "RND"
COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
DO
    _LIMIT 30
    a$ = INKEY$
    IF a$ <> "" THEN mousex = 0: mousey = 0: mouseLeftButton = 0
    IF a$ = CHR$(27) THEN GOTO help:
    IF a$ = CHR$(3) THEN a$ = "": GOTO clip: 'Ctrl+C copies to clipboard.
    IF a$ = "C" OR a$ = "c" THEN a$ = "": GOTO delete: 'Back Space deletes output.
    IF a$ = "p" OR a$ = "P" OR a$ = "n" OR a$ = "N" THEN a$ = "": GOTO posneg: 'Positive or Negative
    IF a$ = "f" OR a$ = "F" THEN a$ = "": GOTO fraction:
    IF a$ = "h" OR a$ = "H" THEN a$ = "": GOTO half:
    IF a$ = "e" OR a$ = "E" THEN a$ = "": GOTO expcommand:
    IF a$ = "r" OR a$ = "R" OR a$ = "d" OR a$ = "D" THEN a$ = "": GOTO radanddeg:
    IF a$ = "u" OR a$ = "U" THEN a$ = "": GOTO squared:
    IF a$ = "l" OR a$ = "L" THEN a$ = "": GOTO logarithm:
    IF a$ = "i" OR a$ = "I" THEN a$ = "": GOTO pi:
    IF a$ = "q" OR a$ = "Q" THEN a$ = "": GOTO squareroot:
    IF a$ = "s" OR a$ = "S" THEN a$ = "": GOTO sine:
    IF a$ = "o" OR a$ = "O" THEN a$ = "": GOTO cosine:
    IF a$ = "t" OR a$ = "T" THEN a$ = "": GOTO tangent:
    IF a$ = "1" THEN a$ = "": GOTO one:
    IF a$ = "2" THEN a$ = "": GOTO two:
    IF a$ = "3" THEN a$ = "": GOTO three:
    IF a$ = "4" THEN a$ = "": GOTO four:
    IF a$ = "5" THEN a$ = "": GOTO five:
    IF a$ = "6" THEN a$ = "": GOTO six:
    IF a$ = "7" THEN a$ = "": GOTO seven:
    IF a$ = "8" THEN a$ = "": GOTO eight:
    IF a$ = "9" THEN a$ = "": GOTO nine:
    IF a$ = "0" THEN a$ = "": GOTO zero2:
    IF a$ = "." THEN a$ = "": GOTO decimal:
    IF a$ = "=" THEN a$ = "": GOTO equals:
    IF a$ = "+" THEN a$ = "": GOTO add:
    IF a$ = "-" THEN a$ = "": GOTO subtract:
    IF a$ = "*" OR a$ = "x" OR a$ = "X" THEN a$ = "": GOTO multiply:
    IF a$ = "/" THEN a$ = "": GOTO divide:
    IF a$ = CHR$(8) THEN a$ = "": GOTO backbutton:

    WHILE _MOUSEINPUT: WEND
    mousex = _MOUSEX
    mousey = _MOUSEY
    mouseLeftButton = _MOUSEBUTTON(1)

    IF mouseLeftButton THEN
        Clear_MB 1
        'Clipboard
        IF mousex > 50 AND mousex < 265 AND mousey > 25 AND mousey < 50 THEN
            clip:
            COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
            _PRINTSTRING (55, 30), num$
            _DELAY .5
            num2$ = _TRIM$(num$)
            _CLIPBOARD$ = num2$
            COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
            _PRINTSTRING (55, 30), num$
        END IF

        'Clipboard Button
        IF mousex > 50 AND mousex < 125 AND mousey > 460 AND mousey < 515 THEN
            clip2:
            COLOR _RGB32(0, 255, 0), _RGB32(0, 0, 0)
            _PRINTSTRING (55, 30), num$
            buttonx = 50: buttony = 460
            GOSUB press:
            _DELAY .5
            num2$ = _TRIM$(num$)
            _CLIPBOARD$ = num2$
            COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
            _PRINTSTRING (55, 30), num$
        END IF

        'Paste Button
        IF mousex > 125 AND mousex < 200 AND mousey > 460 AND mousey < 515 THEN
            paste:
            buttonx = 125: buttony = 460
            GOSUB press:
            num$ = _CLIPBOARD$
            IF LEN(num$) > 19 THEN num$ = "0"
            _PRINTSTRING (55, 30), num$
            num = VAL(num$)
            GOSUB number:
        END IF

        'Back Space Button
        IF mousex > 200 AND mousex < 275 AND mousey > 460 AND mousey < 515 THEN
            backbutton:
            buttonx = 200: buttony = 460
            GOSUB press:
            num$ = LEFT$(num$, LEN(num$) - 1)
            GOSUB number2
        END IF

        'Random Button
        IF mousex > 275 AND mousex < 350 AND mousey > 460 AND mousey < 515 THEN
            timebutton:
            buttonx = 275: buttony = 460
            GOSUB press:
            num$ = STR$(RND)
            _PRINTSTRING (55, 30), num$
            num = VAL(num$)
            GOSUB number:
        END IF

        'Clear
        IF mousex > 275 AND mousex < 350 AND mousey > 20 AND mousey < 75 THEN
            delete:
            a = 0: s = 0: t = 0: d = 0: num$ = ""
            _PRINTSTRING (55, 30), "                                         "
            buttonx = 275: buttony = 20
            GOSUB zero:
        END IF
        '1/x
        IF mousex > 50 AND mousex < 125 AND mousey > 405 AND mousey < 460 THEN
            fraction:
            num = VAL(num$)
            IF num = 0 THEN GOTO skipthis:
            num = 1 / num
            num$ = STR$(num)
            skipthis:
            buttonx = 50: buttony = 405
            GOSUB press:
            GOSUB number:
        END IF

        'x/2
        IF mousex > 126 AND mousex < 200 AND mousey > 405 AND mousey < 460 THEN
            half:
            num = VAL(num$)
            num = num / 2
            num$ = STR$(num)
            buttonx = 126: buttony = 405
            GOSUB press:
            GOSUB number2:
        END IF

        'EXP
        IF mousex > 200 AND mousex < 275 AND mousey > 405 AND mousey < 460 THEN
            expcommand:
            _PRINTSTRING (55, 30), "                                         "
            num = EXP(VAL(num$))
            num$ = STR$(num)
            buttonx = 200: buttony = 405
            GOSUB number2:
            GOSUB press:
        END IF

        'Postive or Negative
        IF mousex > 275 AND mousex < 350 AND mousey > 405 AND mousey < 460 THEN
            posneg:
            IF VAL(num$) < 0 THEN
                num = -VAL(num$)
                num$ = STR$(num)
                GOTO skipplusnegative:
            END IF
            num$ = "-" + num$
            skipplusnegative:
            buttonx = 275: buttony = 405
            GOSUB press:
            GOSUB number:
        END IF

        'Radians and Degrees
        IF mousex > 50 AND mousex < 125 AND mousey > 350 AND mousey < 405 THEN
            radanddeg:
            deg = deg + 1
            IF deg = 2 THEN GOTO deg2rad:
            COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
            _PRINTSTRING (79, 377), "      "
            _PRINTSTRING (79, 377), "rad"
            COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
            _PRINTSTRING (50, 5), "Deg"
            num = VAL(num$)
            num = _R2D(num)
            num$ = STR$(num)
            GOTO skipdeg2rad:
            deg2rad:
            deg = 0
            COLOR _RGB32(0, 0, 0), _RGB32(210, 210, 210)
            _PRINTSTRING (79, 377), "      "
            _PRINTSTRING (79, 377), "deg"
            COLOR _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
            _PRINTSTRING (50, 5), "Rad"
            num = VAL(num$)
            num = _D2R(num)
            num$ = STR$(num)
            skipdeg2rad:
            buttonx = 50: buttony = 350
            GOSUB press:
            GOSUB number:
        END IF

        'Second Power
        IF mousex > 126 AND mousex < 200 AND mousey > 350 AND mousey < 405 THEN
            squared:
            num = VAL(num$)
            num = num ^ 2
            num$ = STR$(num)
            buttonx = 126: buttony = 350
            GOSUB press:
            GOSUB number2:
        END IF

        'logarithm
        IF mousex > 200 AND mousex < 275 AND mousey > 350 AND mousey < 405 THEN
            logarithm:
            num = VAL(num$)
            IF num = 0 THEN GOTO skiplog:
            IF num < 0 THEN GOTO skiplog:
            num = LOG(num)
            num$ = STR$(num)
            skiplog:
            buttonx = 200: buttony = 350
            GOSUB press:
            GOSUB number:
        END IF

        'Pi
        IF mousex > 275 AND mousex < 350 AND mousey > 350 AND mousey < 405 THEN
            pi:
            'num = 3.14159265359
            num = _PI
            num$ = STR$(num)
            buttonx = 275: buttony = 350
            GOSUB press:
            GOSUB number:
        END IF

        'Square Root
        IF mousex > 50 AND mousex < 125 AND mousey > 75 AND mousey < 130 THEN
            squareroot:
            IF num < 0 THEN GOTO skip1:
            num = VAL(num$)
            num = SQR(num)
            num$ = STR$(num)
            skip1:
            buttonx = 50: buttony = 75
            GOSUB press:
            GOSUB number:
        END IF

        'Sine
        IF mousex > 126 AND mousex < 200 AND mousey > 75 AND mousey < 130 THEN
            sine:
            IF deg = 1 THEN num = SIN(_D2R(VAL(num$)))
            IF deg = 0 THEN num = SIN(num)
            num$ = STR$(num)
            buttonx = 126: buttony = 75
            GOSUB press:
            GOSUB number:
        END IF

        'Cosine
        IF mousex > 200 AND mousex < 275 AND mousey > 75 AND mousey < 130 THEN
            cosine:
            IF deg = 1 THEN num = COS(_D2R(VAL(num$)))
            IF deg = 0 THEN num = COS(num)
            num$ = STR$(num)
            buttonx = 200: buttony = 75
            GOSUB press:
            GOSUB number:
        END IF

        'Tangent
        IF mousex > 275 AND mousex < 350 AND mousey > 75 AND mousey < 130 THEN
            tangent:
            IF deg = 1 THEN num = TAN(_D2R(VAL(num$)))
            IF deg = 0 THEN num = TAN(num)
            num$ = STR$(num)
            buttonx = 275: buttony = 75
            GOSUB press:
            GOSUB number:
        END IF

        'Number Buttons
        IF mousex > 50 AND mousex < 125 AND mousey > 130 AND mousey < 185 THEN
            seven:
            num$ = num$ + "7"
            IF n = 1 THEN num$ = "-" + num$: n = 0
            buttonx = 50: buttony = 130
            GOSUB press:
            GOSUB number:
        END IF
        IF mousex > 126 AND mousex < 200 AND mousey > 130 AND mousey < 185 THEN
            eight:
            num$ = num$ + "8"
            IF n = 1 THEN num$ = "-" + num$: n = 0
            buttonx = 126: buttony = 130
            GOSUB press:
            GOSUB number:
        END IF
        IF mousex > 200 AND mousex < 275 AND mousey > 130 AND mousey < 185 THEN
            nine:
            num$ = num$ + "9"
            IF n = 1 THEN num$ = "-" + num$: n = 0
            buttonx = 200: buttony = 130
            GOSUB press:
            GOSUB number:
        END IF
        IF mousex > 50 AND mousex < 125 AND mousey > 185 AND mousey < 240 THEN
            four:
            num$ = num$ + "4"
            IF n = 1 THEN num$ = "-" + num$: n = 0
            buttonx = 50: buttony = 185
            GOSUB press:
            GOSUB number:
        END IF
        IF mousex > 126 AND mousex < 200 AND mousey > 185 AND mousey < 240 THEN
            five:
            num$ = num$ + "5"
            IF n = 1 THEN num$ = "-" + num$: n = 0
            buttonx = 126: buttony = 185
            GOSUB press:
            GOSUB number:
        END IF
        IF mousex > 200 AND mousex < 275 AND mousey > 185 AND mousey < 240 THEN
            six:
            num$ = num$ + "6"
            IF n = 1 THEN num$ = "-" + num$: n = 0
            buttonx = 200: buttony = 185
            GOSUB press:
            GOSUB number:
        END IF
        IF mousex > 50 AND mousex < 125 AND mousey > 240 AND mousey < 295 THEN
            one:
            num$ = num$ + "1"
            IF n = 1 THEN num$ = "-" + num$: n = 0
            buttonx = 50: buttony = 240
            GOSUB press:
            GOSUB number:
        END IF
        IF mousex > 126 AND mousex < 200 AND mousey > 240 AND mousey < 295 THEN
            two:
            num$ = num$ + "2"
            IF n = 1 THEN num$ = "-" + num$: n = 0
            buttonx = 126: buttony = 240
            GOSUB press:
            GOSUB number:
        END IF
        IF mousex > 200 AND mousex < 275 AND mousey > 240 AND mousey < 295 THEN
            three:
            num$ = num$ + "3"
            IF n = 1 THEN num$ = "-" + num$: n = 0
            buttonx = 200: buttony = 240
            GOSUB press:
            GOSUB number:
        END IF
        IF mousex > 50 AND mousex < 125 AND mousey > 295 AND mousey < 350 THEN
            zero2:
            IF num$ <> "0" THEN ' Prevents more than one leading zero input.
                num$ = num$ + "0"
                IF n = 1 THEN num$ = "-" + num$: n = 0
                buttonx = 50: buttony = 295
                GOSUB press:
                GOSUB number:
            END IF
        END IF

        'Decimal
        IF mousex > 126 AND mousex < 200 AND mousey > 295 AND mousey < 350 THEN
            decimal:
            buttonx = 126: buttony = 295
            FOR check = 1 TO LEN(num$)
                IF MID$(num$, check, 1) = "." THEN GOTO skipdec:
            NEXT check
            num$ = num$ + "."
            _PRINTSTRING (55, 30), num$
            skipdec:
            GOSUB press:

        END IF

        'Equals
        IF mousex > 200 AND mousex < 275 AND mousey > 295 AND mousey < 350 THEN
            equals:
            IF a = 1 THEN num = VAL(oldnum$) + VAL(num$): a = 0
            IF s = 1 THEN num = VAL(oldnum$) - VAL(num$): s = 0
            IF t = 1 THEN num = VAL(oldnum$) * VAL(num$): t = 0
            IF d = 1 THEN num = VAL(oldnum$) / VAL(num$): d = 0

            '----------------------------------------------------
            num$ = LTRIM$(STR$(num))
            '----------------------------------------------------

            buttonx = 200: buttony = 295
            GOSUB press:
            GOSUB number2:
        END IF

        'Add
        IF mousex > 275 AND mousex < 350 AND mousey > 295 AND mousey < 350 THEN
            add:
            IF a = 0 THEN
                d = 0: a = 1: s = 0: t = 0
                GOSUB convert: oldnum$ = num$
                _PRINTSTRING (55, 30), "                                         "
                num$ = ""
                GOTO nex4:
            END IF
            IF a = 1 THEN
                num = VAL(oldnum$) + VAL(num$)
                a = 0
            END IF
            GOSUB number2:
            nex4:
            buttonx = 275: buttony = 295
            GOSUB press:
        END IF

        'Subtract
        IF mousex > 275 AND mousex < 350 AND mousey > 240 AND mousey < 295 THEN
            subtract:
            IF s = 0 THEN
                IF num$ = "0" OR num$ = "" OR num = 0 THEN n = 1: GOTO nex3:
                d = 0: a = 0: s = 1: t = 0
                GOSUB convert: oldnum$ = num$
                _PRINTSTRING (55, 30), "                                         "
                num$ = ""
                GOTO nex3:
            END IF
            IF s = 1 THEN
                num = VAL(oldnum$) - VAL(num$)
                s = 0
            END IF
            GOSUB number2:
            nex3:
            buttonx = 275: buttony = 240
            GOSUB press:
        END IF

        'Multiply
        IF mousex > 275 AND mousex < 350 AND mousey > 185 AND mousey < 240 THEN
            multiply:
            IF t = 0 THEN
                d = 0: a = 0: s = 0: t = 1
                GOSUB convert: oldnum$ = num$
                _PRINTSTRING (55, 30), "                                         "
                num$ = ""
                GOTO nex2:
            END IF
            IF t = 1 THEN
                num = VAL(oldnum$) * VAL(num$)
                t = 0
            END IF
            GOSUB number2:
            nex2:
            buttonx = 275: buttony = 185
            GOSUB press:
        END IF

        'Divide
        IF mousex > 275 AND mousex < 350 AND mousey > 130 AND mousey < 185 THEN
            divide:
            IF d = 0 THEN
                d = 1: a = 0: s = 0: t = 0
                GOSUB convert: oldnum$ = num$
                _PRINTSTRING (55, 30), "                                         "
                num$ = ""
                GOTO nex1:
            END IF
            IF d = 1 AND num$ <> "" THEN
                num = VAL(oldnum$) / VAL(num$)
                d = 0
            END IF
            GOSUB number2:
            nex1:
            buttonx = 275: buttony = 130
            GOSUB press:
        END IF
    END IF
LOOP
'For Number Buttons.

convert:
IF VAL(num$) > 9999999999999999 OR LEN(num$) > 19 THEN
    num$ = LEFT$(num$, 19)
END IF
num = VAL(num$)
RETURN

number:
IF VAL(num$) > 9999999999999999 OR LEN(num$) > 19 THEN
    num$ = LEFT$(num$, 19)
END IF

'For Math
number2:
COLOR _RGB32(0, 0, 0), _RGB32(0, 0, 0)
_PRINTSTRING (55, 30), SPACE$(40)

IF VAL(num$) > 9999999999999999 OR LEN(num$) > 19 THEN
    num$ = LEFT$(num$, 19)
END IF
COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
_PRINTSTRING (55, 30), num$

RETURN

'Pressing Each Button

press:
c = 110
FOR bb = 0 TO 10
    c = c - 10
    LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
_DELAY .03

FOR bb = 0 TO 10
    c = c + 10
    LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
NEXT bb
RETURN

'Pressing the Green C Button.
zero:
c = 110
FOR bb = 0 TO 10
    c = c - 10
    LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
NEXT bb
_DELAY .25
FOR bb = 0 TO 10
    c = c + 10
    LINE (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
NEXT bb
RETURN

help:
_FONT 14
CLS
_TITLE "Calculator Help"
PRINT "Esc = Keyboard Help"
PRINT "CTRL+C = Copies To Clipboard"
PRINT "Left Mouse Click Copies To Clipboard."
PRINT "Copy Button Copies To Clipboard"
PRINT "Paste Button Pastes Clipboard To Screen"
PRINT "Backspace = Deletes Last Output Digit"
PRINT "RND = Makes a random number from 0 to 1."
PRINT "Letters can be upper or lower-case."
PRINT "P or N = Positve and Negative Switch."
PRINT "F = 1 / x"
PRINT "H = x / 2"
PRINT "E = EXP"
PRINT "R or D = Radian and Degree Switch."
PRINT "U = X ^ 2"
PRINT "L = Logarithm"
PRINT "I = Pi"
PRINT "Q = Square Root"
PRINT "s = Sine"
PRINT "o = Cosine"
PRINT "t = Tangent"
PRINT
PRINT "Below can be either Number Pad or the others."
PRINT "1-9 = Number Keys"
PRINT ". = Decimal"
PRINT "= = Equals"
PRINT "+ = Add"
PRINT "- = Subtract"
PRINT "* or X = Multiply"
PRINT "/ = Divide"
PRINT
PRINT "Press Esc to go back to calculator."
DO: LOOP UNTIL INKEY$ = CHR$(27)
CLS
_TITLE "Calculator - Esc for help."
GOTO begin:


'This Function is from Dav which makes the icon picture. It uses code at the start of this program.
FUNCTION BASIMAGE1& 'calculatio icon data
    v& = _NEWIMAGE(54, 48, 32)
    DIM m AS _MEM: m = _MEMIMAGE(v&)
    A$ = ""
    A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
    A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
    A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
    A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
    A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
    A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
    A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
    A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
    A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
    A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
    A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
    A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
    A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
    A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
    A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
    A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
    A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
    A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
    A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
    A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
    A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
    A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
    A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
    A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
    A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
    btemp$ = ""
    FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
        IF INSTR(1, B$, "%") THEN
            FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
                IF F$ <> "%" THEN C$ = C$ + F$
            NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
            IF MID$(B$, j, 1) = "#" THEN
        MID$(B$, j) = "@": END IF: NEXT
        FOR t% = LEN(B$) TO 1 STEP -1
            B& = B& * 64 + ASC(MID$(B$, t%)) - 48
            NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
            X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
    NEXT: btemp$ = btemp$ + X$: NEXT
    btemp$ = _INFLATE$(btemp$)
    _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
    BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
END FUNCTION

SUB Clear_MB (var AS INTEGER)

    DO UNTIL NOT _MOUSEBUTTON(var)
        WHILE _MOUSEINPUT: WEND
    LOOP

END SUB 'Clear_MB


Things to note. I had to add this line to the NUMBER2: sub-routine:

_PRINTSTRING (55, 30), SPACE$(40)

It is absolutely needed to clear the field before the number is printed when backspacing, but also when any result has fewer digits than the previous shown result. Now you may want to use something other than SPACE$(40) that will clear the field.

Next, I also had to make a different way to handle not accepting more than one leading zero in a non-decimal entry.

IMPORTANT: You need to revisit the CLIPBOARD routine. I could easily paste a sequence of like 0000...0.0 and it would be accepted. It would also screw up any attempted calculation.

Anyway, there will probaly be other athings to consider with the other math functions. I'm only checking +-*/.

Pete
Reply
#42
Thanks again Pete, I appreciate the help. I didn't come across any Paste "000000" problem with calculations. I did see that sometimes it converts it to 0.0 which is the same number so it doesn't matter. I did come across a +/- button issue though which I fixed. It was when someone gave 0 a negative and did it again, it would keep putting more and more ---- each time you pressed it. So since zero has no negative in reality, I just made it impossible to make zero a negative to fix it. I really hope this is the last update. lol 

Fixed Update: 

Code: (Select All)
'Calculator
'By SierraKen on July 30, 2020.
'Updated on July 24, 2022 with Copy and Paste Buttons.
'Updated on July 26, 2022 with Back Space Button and RND (Random) Button
'Update on July 29, 2022 with math fix problem with Pete's help.
'-----------------------------------------------------------------------
'This is my very first regular calculator.
'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
'Thank you Dav for the icon code!
'Thanks Pete for the math help!

_Icon BASIMAGE1&

_Title "Calculator - Esc for help."
Dim num As Double
Screen _NewImage(400, 525, 32)
f& = _LoadFont("Arial.ttf", 18)
begin:
_Font f&
num$ = ""
c = 0
a = 0: s = 0: t = 0: d = 0
'Setup calculator
Line (50, 25)-(265, 50), _RGB32(255, 255, 255), B
Line (50, 75)-(350, 350), _RGB32(255, 255, 255), B
'Buttons
For buttony = 75 To 405 Step 55
    For buttonx = 50 To 275 Step 75
        For bb = 0 To 10
            c = c + 10
            Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
        Next bb
        Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
        c = 0
    Next buttonx
Next buttony
'Copy Button
buttonx = 50: buttony = 460
For bb = 0 To 10
    c = c + 10
    Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Paste Button
buttonx = 125: buttony = 460
For bb = 0 To 10
    c = c + 10
    Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Back Space Button
buttonx = 200: buttony = 460
For bb = 0 To 10
    c = c + 10
    Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Time Button
buttonx = 275: buttony = 460
For bb = 0 To 10
    c = c + 10
    Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Green C Button
buttonx = 275: buttony = 20
For bb = 0 To 10
    c = c + 10
    Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
Color _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
_PrintString (50, 5), "Rad"
wer:
'Label Buttons
_PrintString (306, 47), "C"
Color _RGB32(0, 0, 0), _RGB32(210, 210, 210)
_PrintString (87, 102), Chr$(251) 'square root
_PrintString (152, 102), "sin"
_PrintString (227, 102), "cos"
_PrintString (302, 102), "tan"
_PrintString (87, 157), "7"
_PrintString (162, 157), "8"
_PrintString (237, 157), "9"
_PrintString (312, 157), "/"
_PrintString (87, 212), "4"
_PrintString (162, 212), "5"
_PrintString (237, 212), "6"
_PrintString (312, 212), "x"
_PrintString (87, 267), "1"
_PrintString (162, 267), "2"
_PrintString (237, 267), "3"
_PrintString (312, 267), "-"
_PrintString (87, 322), "0"
_PrintString (162, 322), "."
_PrintString (237, 322), "="
_PrintString (312, 322), "+"
_PrintString (79, 377), "     "
_PrintString (79, 377), "deg"
_PrintString (162, 377), "x" + Chr$(253) 'second power
_PrintString (227, 377), "log"
_PrintString (307, 377), "Pi"
_PrintString (79, 432), "1/x"
_PrintString (152, 432), "x/2"
_PrintString (227, 432), "exp"
_PrintString (312, 432), Chr$(241) 'Postive or Negative
_PrintString (68, 487), "Copy"
_PrintString (141, 487), "Paste"
_PrintString (210, 487), "<Back"
_PrintString (293, 487), "RND"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
Do
    _Limit 30
    a$ = InKey$
    If a$ <> "" Then mousex = 0: mousey = 0: mouseLeftButton = 0
    If a$ = Chr$(27) Then GoTo help:
    If a$ = Chr$(3) Then a$ = "": GoTo clip: 'Ctrl+C copies to clipboard.
    If a$ = "C" Or a$ = "c" Then a$ = "": GoTo delete: 'Back Space deletes output.
    If a$ = "p" Or a$ = "P" Or a$ = "n" Or a$ = "N" Then a$ = "": GoTo posneg: 'Positive or Negative
    If a$ = "f" Or a$ = "F" Then a$ = "": GoTo fraction:
    If a$ = "h" Or a$ = "H" Then a$ = "": GoTo half:
    If a$ = "e" Or a$ = "E" Then a$ = "": GoTo expcommand:
    If a$ = "r" Or a$ = "R" Or a$ = "d" Or a$ = "D" Then a$ = "": GoTo radanddeg:
    If a$ = "u" Or a$ = "U" Then a$ = "": GoTo squared:
    If a$ = "l" Or a$ = "L" Then a$ = "": GoTo logarithm:
    If a$ = "i" Or a$ = "I" Then a$ = "": GoTo pi:
    If a$ = "q" Or a$ = "Q" Then a$ = "": GoTo squareroot:
    If a$ = "s" Or a$ = "S" Then a$ = "": GoTo sine:
    If a$ = "o" Or a$ = "O" Then a$ = "": GoTo cosine:
    If a$ = "t" Or a$ = "T" Then a$ = "": GoTo tangent:
    If a$ = "1" Then a$ = "": GoTo one:
    If a$ = "2" Then a$ = "": GoTo two:
    If a$ = "3" Then a$ = "": GoTo three:
    If a$ = "4" Then a$ = "": GoTo four:
    If a$ = "5" Then a$ = "": GoTo five:
    If a$ = "6" Then a$ = "": GoTo six:
    If a$ = "7" Then a$ = "": GoTo seven:
    If a$ = "8" Then a$ = "": GoTo eight:
    If a$ = "9" Then a$ = "": GoTo nine:
    If a$ = "0" Then a$ = "": GoTo zero2:
    If a$ = "." Then a$ = "": GoTo decimal:
    If a$ = "=" Then a$ = "": GoTo equals:
    If a$ = "+" Then a$ = "": GoTo add:
    If a$ = "-" Then a$ = "": GoTo subtract:
    If a$ = "*" Or a$ = "x" Or a$ = "X" Then a$ = "": GoTo multiply:
    If a$ = "/" Then a$ = "": GoTo divide:
    If a$ = Chr$(8) Then a$ = "": GoTo backbutton:

    While _MouseInput: Wend
    mousex = _MouseX
    mousey = _MouseY
    mouseLeftButton = _MouseButton(1)

    If mouseLeftButton Then
        Clear_MB 1
        'Clipboard
        If mousex > 50 And mousex < 265 And mousey > 25 And mousey < 50 Then
            clip:
            Color _RGB32(0, 255, 0), _RGB32(0, 0, 0)
            _PrintString (55, 30), num$
            _Delay .5
            num2$ = _Trim$(num$)
            _Clipboard$ = num2$
            Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
            _PrintString (55, 30), num$
        End If

        'Clipboard Button
        If mousex > 50 And mousex < 125 And mousey > 460 And mousey < 515 Then
            clip2:
            Color _RGB32(0, 255, 0), _RGB32(0, 0, 0)
            _PrintString (55, 30), num$
            buttonx = 50: buttony = 460
            GoSub press:
            _Delay .5
            num2$ = _Trim$(num$)
            _Clipboard$ = num2$
            Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
            _PrintString (55, 30), num$
        End If

        'Paste Button
        If mousex > 125 And mousex < 200 And mousey > 460 And mousey < 515 Then
            paste:
            buttonx = 125: buttony = 460
            GoSub press:
            num$ = _Clipboard$
            If Len(num$) > 19 Then num$ = "0"
            _PrintString (55, 30), num$
            num = Val(num$)
            GoSub number:
        End If

        'Back Space Button
        If mousex > 200 And mousex < 275 And mousey > 460 And mousey < 515 Then
            backbutton:
            buttonx = 200: buttony = 460
            GoSub press:
            num$ = Left$(num$, Len(num$) - 1)
            GoSub number2
        End If

        'Random Button
        If mousex > 275 And mousex < 350 And mousey > 460 And mousey < 515 Then
            timebutton:
            buttonx = 275: buttony = 460
            GoSub press:
            num$ = Str$(Rnd)
            _PrintString (55, 30), num$
            num = Val(num$)
            GoSub number:
        End If

        'Clear
        If mousex > 275 And mousex < 350 And mousey > 20 And mousey < 75 Then
            delete:
            a = 0: s = 0: t = 0: d = 0: num$ = ""
            _PrintString (55, 30), "                                         "
            buttonx = 275: buttony = 20
            GoSub zero:
        End If
        '1/x
        If mousex > 50 And mousex < 125 And mousey > 405 And mousey < 460 Then
            fraction:
            num = Val(num$)
            If num = 0 Then GoTo skipthis:
            num = 1 / num
            num$ = Str$(num)
            skipthis:
            buttonx = 50: buttony = 405
            GoSub press:
            GoSub number:
        End If

        'x/2
        If mousex > 126 And mousex < 200 And mousey > 405 And mousey < 460 Then
            half:
            num = Val(num$)
            num = num / 2
            num$ = Str$(num)
            buttonx = 126: buttony = 405
            GoSub press:
            GoSub number2:
        End If

        'EXP
        If mousex > 200 And mousex < 275 And mousey > 405 And mousey < 460 Then
            expcommand:
            _PrintString (55, 30), "                                         "
            num = Exp(Val(num$))
            num$ = Str$(num)
            buttonx = 200: buttony = 405
            GoSub number2:
            GoSub press:
        End If

        'Postive or Negative
        If mousex > 275 And mousex < 350 And mousey > 405 And mousey < 460 Then
            posneg:
            If Val(num$) = 0 Then GoTo skipplusnegative:
            If Val(num$) < 0 Then
                num = -Val(num$)
                num$ = Str$(num)
                GoTo skipplusnegative:
            End If
            num$ = "-" + num$
            skipplusnegative:
            buttonx = 275: buttony = 405
            GoSub press:
            GoSub number:
        End If

        'Radians and Degrees
        If mousex > 50 And mousex < 125 And mousey > 350 And mousey < 405 Then
            radanddeg:
            deg = deg + 1
            If deg = 2 Then GoTo deg2rad:
            Color _RGB32(0, 0, 0), _RGB32(210, 210, 210)
            _PrintString (79, 377), "      "
            _PrintString (79, 377), "rad"
            Color _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
            _PrintString (50, 5), "Deg"
            num = Val(num$)
            num = _R2D(num)
            num$ = Str$(num)
            GoTo skipdeg2rad:
            deg2rad:
            deg = 0
            Color _RGB32(0, 0, 0), _RGB32(210, 210, 210)
            _PrintString (79, 377), "      "
            _PrintString (79, 377), "deg"
            Color _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
            _PrintString (50, 5), "Rad"
            num = Val(num$)
            num = _D2R(num)
            num$ = Str$(num)
            skipdeg2rad:
            buttonx = 50: buttony = 350
            GoSub press:
            GoSub number:
        End If

        'Second Power
        If mousex > 126 And mousex < 200 And mousey > 350 And mousey < 405 Then
            squared:
            num = Val(num$)
            num = num ^ 2
            num$ = Str$(num)
            buttonx = 126: buttony = 350
            GoSub press:
            GoSub number2:
        End If

        'logarithm
        If mousex > 200 And mousex < 275 And mousey > 350 And mousey < 405 Then
            logarithm:
            num = Val(num$)
            If num = 0 Then GoTo skiplog:
            If num < 0 Then GoTo skiplog:
            num = Log(num)
            num$ = Str$(num)
            skiplog:
            buttonx = 200: buttony = 350
            GoSub press:
            GoSub number:
        End If

        'Pi
        If mousex > 275 And mousex < 350 And mousey > 350 And mousey < 405 Then
            pi:
            'num = 3.14159265359
            num = _Pi
            num$ = Str$(num)
            buttonx = 275: buttony = 350
            GoSub press:
            GoSub number:
        End If

        'Square Root
        If mousex > 50 And mousex < 125 And mousey > 75 And mousey < 130 Then
            squareroot:
            If num < 0 Then GoTo skip1:
            num = Val(num$)
            num = Sqr(num)
            num$ = Str$(num)
            skip1:
            buttonx = 50: buttony = 75
            GoSub press:
            GoSub number:
        End If

        'Sine
        If mousex > 126 And mousex < 200 And mousey > 75 And mousey < 130 Then
            sine:
            If deg = 1 Then num = Sin(_D2R(Val(num$)))
            If deg = 0 Then num = Sin(num)
            num$ = Str$(num)
            buttonx = 126: buttony = 75
            GoSub press:
            GoSub number:
        End If

        'Cosine
        If mousex > 200 And mousex < 275 And mousey > 75 And mousey < 130 Then
            cosine:
            If deg = 1 Then num = Cos(_D2R(Val(num$)))
            If deg = 0 Then num = Cos(num)
            num$ = Str$(num)
            buttonx = 200: buttony = 75
            GoSub press:
            GoSub number:
        End If

        'Tangent
        If mousex > 275 And mousex < 350 And mousey > 75 And mousey < 130 Then
            tangent:
            If deg = 1 Then num = Tan(_D2R(Val(num$)))
            If deg = 0 Then num = Tan(num)
            num$ = Str$(num)
            buttonx = 275: buttony = 75
            GoSub press:
            GoSub number:
        End If

        'Number Buttons
        If mousex > 50 And mousex < 125 And mousey > 130 And mousey < 185 Then
            seven:
            num$ = num$ + "7"
            If n = 1 Then num$ = "-" + num$: n = 0
            buttonx = 50: buttony = 130
            GoSub press:
            GoSub number:
        End If
        If mousex > 126 And mousex < 200 And mousey > 130 And mousey < 185 Then
            eight:
            num$ = num$ + "8"
            If n = 1 Then num$ = "-" + num$: n = 0
            buttonx = 126: buttony = 130
            GoSub press:
            GoSub number:
        End If
        If mousex > 200 And mousex < 275 And mousey > 130 And mousey < 185 Then
            nine:
            num$ = num$ + "9"
            If n = 1 Then num$ = "-" + num$: n = 0
            buttonx = 200: buttony = 130
            GoSub press:
            GoSub number:
        End If
        If mousex > 50 And mousex < 125 And mousey > 185 And mousey < 240 Then
            four:
            num$ = num$ + "4"
            If n = 1 Then num$ = "-" + num$: n = 0
            buttonx = 50: buttony = 185
            GoSub press:
            GoSub number:
        End If
        If mousex > 126 And mousex < 200 And mousey > 185 And mousey < 240 Then
            five:
            num$ = num$ + "5"
            If n = 1 Then num$ = "-" + num$: n = 0
            buttonx = 126: buttony = 185
            GoSub press:
            GoSub number:
        End If
        If mousex > 200 And mousex < 275 And mousey > 185 And mousey < 240 Then
            six:
            num$ = num$ + "6"
            If n = 1 Then num$ = "-" + num$: n = 0
            buttonx = 200: buttony = 185
            GoSub press:
            GoSub number:
        End If
        If mousex > 50 And mousex < 125 And mousey > 240 And mousey < 295 Then
            one:
            num$ = num$ + "1"
            If n = 1 Then num$ = "-" + num$: n = 0
            buttonx = 50: buttony = 240
            GoSub press:
            GoSub number:
        End If
        If mousex > 126 And mousex < 200 And mousey > 240 And mousey < 295 Then
            two:
            num$ = num$ + "2"
            If n = 1 Then num$ = "-" + num$: n = 0
            buttonx = 126: buttony = 240
            GoSub press:
            GoSub number:
        End If
        If mousex > 200 And mousex < 275 And mousey > 240 And mousey < 295 Then
            three:
            num$ = num$ + "3"
            If n = 1 Then num$ = "-" + num$: n = 0
            buttonx = 200: buttony = 240
            GoSub press:
            GoSub number:
        End If
        If mousex > 50 And mousex < 125 And mousey > 295 And mousey < 350 Then
            zero2:
            If num$ <> "0" Then ' Prevents more than one leading zero input.
                num$ = num$ + "0"
                If n = 1 Then num$ = "-" + num$: n = 0
                buttonx = 50: buttony = 295
                GoSub press:
                GoSub number:
            End If
        End If

        'Decimal
        If mousex > 126 And mousex < 200 And mousey > 295 And mousey < 350 Then
            decimal:
            buttonx = 126: buttony = 295
            For check = 1 To Len(num$)
                If Mid$(num$, check, 1) = "." Then GoTo skipdec:
            Next check
            num$ = num$ + "."
            _PrintString (55, 30), num$
            skipdec:
            GoSub press:

        End If

        'Equals
        If mousex > 200 And mousex < 275 And mousey > 295 And mousey < 350 Then
            equals:
            If a = 1 Then num = Val(oldnum$) + Val(num$): a = 0
            If s = 1 Then num = Val(oldnum$) - Val(num$): s = 0
            If t = 1 Then num = Val(oldnum$) * Val(num$): t = 0
            If d = 1 Then num = Val(oldnum$) / Val(num$): d = 0

            '----------------------------------------------------
            num$ = LTrim$(Str$(num))
            '----------------------------------------------------

            buttonx = 200: buttony = 295
            GoSub press:
            GoSub number2:
        End If

        'Add
        If mousex > 275 And mousex < 350 And mousey > 295 And mousey < 350 Then
            add:
            If a = 0 Then
                d = 0: a = 1: s = 0: t = 0
                GoSub convert: oldnum$ = num$
                _PrintString (55, 30), "                                         "
                num$ = ""
                GoTo nex4:
            End If
            If a = 1 Then
                num = Val(oldnum$) + Val(num$)
                a = 0
            End If
            GoSub number2:
            nex4:
            buttonx = 275: buttony = 295
            GoSub press:
        End If

        'Subtract
        If mousex > 275 And mousex < 350 And mousey > 240 And mousey < 295 Then
            subtract:
            If s = 0 Then
                If num$ = "0" Or num$ = "" Or num = 0 Then n = 1: GoTo nex3:
                d = 0: a = 0: s = 1: t = 0
                GoSub convert: oldnum$ = num$
                _PrintString (55, 30), "                                         "
                num$ = ""
                GoTo nex3:
            End If
            If s = 1 Then
                num = Val(oldnum$) - Val(num$)
                s = 0
            End If
            GoSub number2:
            nex3:
            buttonx = 275: buttony = 240
            GoSub press:
        End If

        'Multiply
        If mousex > 275 And mousex < 350 And mousey > 185 And mousey < 240 Then
            multiply:
            If t = 0 Then
                d = 0: a = 0: s = 0: t = 1
                GoSub convert: oldnum$ = num$
                _PrintString (55, 30), "                                         "
                num$ = ""
                GoTo nex2:
            End If
            If t = 1 Then
                num = Val(oldnum$) * Val(num$)
                t = 0
            End If
            GoSub number2:
            nex2:
            buttonx = 275: buttony = 185
            GoSub press:
        End If

        'Divide
        If mousex > 275 And mousex < 350 And mousey > 130 And mousey < 185 Then
            divide:
            If d = 0 Then
                d = 1: a = 0: s = 0: t = 0
                GoSub convert: oldnum$ = num$
                _PrintString (55, 30), "                                         "
                num$ = ""
                GoTo nex1:
            End If
            If d = 1 And num$ <> "" Then
                num = Val(oldnum$) / Val(num$)
                d = 0
            End If
            GoSub number2:
            nex1:
            buttonx = 275: buttony = 130
            GoSub press:
        End If
    End If
Loop
'For Number Buttons.

convert:
If Val(num$) > 9999999999999999 Or Len(num$) > 19 Then
    num$ = Left$(num$, 19)
End If
num = Val(num$)
Return

number:
If Val(num$) > 9999999999999999 Or Len(num$) > 19 Then
    num$ = Left$(num$, 19)
End If

'For Math
number2:
Color _RGB32(0, 0, 0), _RGB32(0, 0, 0)
_PrintString (55, 30), Space$(40)

If Val(num$) > 9999999999999999 Or Len(num$) > 19 Then
    num$ = Left$(num$, 19)
End If
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
_PrintString (55, 30), num$

Return

'Pressing Each Button

press:
c = 110
For bb = 0 To 10
    c = c - 10
    Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
_Delay .03

For bb = 0 To 10
    c = c + 10
    Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Return

'Pressing the Green C Button.
zero:
c = 110
For bb = 0 To 10
    c = c - 10
    Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
Next bb
_Delay .25
For bb = 0 To 10
    c = c + 10
    Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
Next bb
Return

help:
_Font 14
Cls
_Title "Calculator Help"
Print "Esc = Keyboard Help"
Print "CTRL+C = Copies To Clipboard"
Print "Left Mouse Click Copies To Clipboard."
Print "Copy Button Copies To Clipboard"
Print "Paste Button Pastes Clipboard To Screen"
Print "Backspace = Deletes Last Output Digit"
Print "RND = Makes a random number from 0 to 1."
Print "Letters can be upper or lower-case."
Print "P or N = Positve and Negative Switch."
Print "F = 1 / x"
Print "H = x / 2"
Print "E = EXP"
Print "R or D = Radian and Degree Switch."
Print "U = X ^ 2"
Print "L = Logarithm"
Print "I = Pi"
Print "Q = Square Root"
Print "s = Sine"
Print "o = Cosine"
Print "t = Tangent"
Print
Print "Below can be either Number Pad or the others."
Print "1-9 = Number Keys"
Print ". = Decimal"
Print "= = Equals"
Print "+ = Add"
Print "- = Subtract"
Print "* or X = Multiply"
Print "/ = Divide"
Print
Print "Press Esc to go back to calculator."
Do: Loop Until InKey$ = Chr$(27)
Cls
_Title "Calculator - Esc for help."
GoTo begin:


'This Function is from Dav which makes the icon picture. It uses code at the start of this program.
Function BASIMAGE1& 'calculatio icon data
    v& = _NewImage(54, 48, 32)
    Dim m As _MEM: m = _MemImage(v&)
    A$ = ""
    A$ = A$ + "haIkJ^eBK\557GZJOl02m5YDX5J1A:YC0aGE##Oc?0RUD5A:HDOA=N=2N96`"
    A$ = A$ + ";87A#=X?hm4S6=N3_[XV4CRgn4]>co5=SJdI?IR9R7K2lSmNFke\bj?c<[I]"
    A$ = A$ + "3QXknHbT9:]dB;Y`kblMd7Tn#B3cF=CZmYb:[Tb<c<Y<b83Ua8c5QJnTNjY["
    A$ = A$ + "X[go?_W<f^AbX=I\7O8IGRiA[eSAbZ7[ZZ[nj[?Z`2;DgD#15lTf;ZXRXlc?"
    A$ = A$ + "okdUEiL`Q<>Ua]nAb]4c3\?_<S8[;_Z[[4mmQIWMfDNiUg3eeTb\[<1T9\n#"
    A$ = A$ + ":\4SR=obhEVAOUX[moCNM[n#j6965KQTImDj:U^BY;mZ[O4j7D>[T3Ukfin\"
    A$ = A$ + "eEomg?EB9U`DLa5[#dfRLlm]7mi0PVb:[\R;MmY>o4mUom;D>NbQnn1OoEee"
    A$ = A$ + "[kSNee7]lAjKcl=b#03T1o6NcX[Lg:Gjc3mIj[CmEbP_g>jjeLM3Ee5jg0m:"
    A$ = A$ + "4DO85DRAaV?IFkER^V#V5TaUnAbU4c3\?WaGln3OT^Jc8gk=gCOLPT=9V7]F"
    A$ = A$ + "GRkWOjYWVZYVJ8cV=cSA07;2]l1[okJn=mc6o9IbR9jG=o[4:8V>Lj#EM]jZ"
    A$ = A$ + "[B3>hPdHS=6chS?^bX84i3FKTA6Q\Je:3V7;a<F1a2ilJ[]VZj2[=jXSB;_l"
    A$ = A$ + "bdNk]7M`17#k_onlX8Dc74S=fH3Jb9WDAGH>\59n?7#<#^RLf[G_JZ[eGOM:"
    A$ = A$ + "H`PdeGO=c=gLS#DcW#Q2aJ>JM1KQ37V^mfKe5ARKTSAlA^VBGYdE:Mmg]^6H"
    A$ = A$ + "P1X012lRZ;\o\>k\CZWNjQjZ[^hl\nj[WkCIXQ6RlkgOL[[;_lBnk7onLK^i"
    A$ = A$ + "VD]eF;eJ[]B]dB;D5ED1O^9;MeNk]CmfK_T=KfX>jX3Zk^kVeDS=f8EGMeAW"
    A$ = A$ + "NjY?k[GUFJY\N#O:8VEGMeDIUE6IaRUTV^P]S>j8>o?olcY3?l#nN6TWhh[^"
    A$ = A$ + "jZW]^>iTChc3SPc>k<VkO_`o7On:IFgh]FOD_EkkMa5GTOn<JJ^iV5RFnPeA"
    A$ = A$ + "]5#\4?m2RYCW>EEG[\b:LmKD_;2AZo92]l1_GX]fJS1ce:Nj5TcNlhAhcGhn"
    A$ = A$ + "TiVK>Fo^LiBID4RlIQ5FPVHR9D^?4cQ=]RI\2bETcaBM3<jcW?jR;^P1e65Q"
    A$ = A$ + "JnPJck^k^?Z^1\Qed:^J1ba8ilOceiQ_hLR>>RnnN:k8gCTj:JBY[Dj2m5^m"
    A$ = A$ + "fKcnnFBGc>k\DiUG>_?UMfIWTR^>nhSiL1m<mBY;DSMZYVRZZZZX]fJ[4^^P"
    A$ = A$ + "?XoXIVIVGd[GH_3hMR3?l`lnCBdjJniWWO?WXW_CEgh^gMSn1`i1#>82el1e"
    A$ = A$ + "FD[O3\VFaE;#>RL=Fd5je2g3\dB;A^MkFID4Rl1m>j`Q35MQi`VFa<F1iZFm"
    A$ = A$ + "7RNRAoff]KG1lOVjn7oDXU?XWKlKS0`L]RWN1i\Xnian_JZYVDf[D4P=AXU?"
    A$ = A$ + "Hm6JX1VH9Na3A_o[o3Ph%%L2"
    btemp$ = ""
    For i& = 1 To Len(A$) Step 4: B$ = Mid$(A$, i&, 4)
        If InStr(1, B$, "%") Then
            For C% = 1 To Len(B$): F$ = Mid$(B$, C%, 1)
                If F$ <> "%" Then C$ = C$ + F$
            Next: B$ = C$: End If: For j = 1 To Len(B$)
            If Mid$(B$, j, 1) = "#" Then
        Mid$(B$, j) = "@": End If: Next
        For t% = Len(B$) To 1 Step -1
            B& = B& * 64 + Asc(Mid$(B$, t%)) - 48
            Next: X$ = "": For t% = 1 To Len(B$) - 1
            X$ = X$ + Chr$(B& And 255): B& = B& \ 256
    Next: btemp$ = btemp$ + X$: Next
    btemp$ = _Inflate$(btemp$)
    _MemPut m, m.OFFSET, btemp$: _MemFree m
    BASIMAGE1& = _CopyImage(v&): _FreeImage v&
End Function

Sub Clear_MB (var As Integer)

    Do Until Not _MouseButton(var)
        While _MouseInput: Wend
    Loop

End Sub 'Clear_MB
Reply
#43
Quote:I really hope this is the last update.
Whether it is the last update or not, see it positively: You have learned a lot.
Reply
#44
Thanks Kernelpanic Smile). Yes I have.
Reply
#45
Kernel, your version might be wrong, I just re-pasted it back into the same post. It might be OK though. I was having some issue with it using the old .exe instead since I didn't save it with a name I believe.
Reply




Users browsing this thread: 15 Guest(s)