Posts: 1,000
Threads: 50
Joined: May 2022
Reputation:
27
There is an error in the combination of ".0". In this combination.
The program otherwise works correctly; as far as i tested it. If this is correct, then this is not a fundamental error in the program, but only in relation to ".0". This input collides with something, but only those who are familiar with this basic can find that out.
Posts: 419
Threads: 75
Joined: Apr 2022
Reputation:
22
07-27-2022, 09:27 PM
(This post was last modified: 07-28-2022, 12:01 AM by SierraKen.)
Yes, if anyone wants to take a look at the code and help me fix the problem, it's here:
(Code fixed on Pete's post toward end of this page.)
Posts: 2,186
Threads: 222
Joined: Apr 2022
Reputation:
104
07-27-2022, 09:54 PM
(This post was last modified: 07-27-2022, 10:27 PM by Pete.)
Partial fix.
This will not fix the problem of .301 not registering the zero after the 3, or an entry of -.0, but it does fix the problem of the calculator not registering a .0 entry:
Replace your NUMBER: sub routine with...
Code: (Select All) number:
IF VAL(num$) > 9999999999999999 OR LEN(num$) > 19 THEN
num$ = LEFT$(num$, 19)
END IF
num = VAL(num$)
'For Math
number2:
COLOR _RGB32(0, 0, 0), _RGB32(0, 0, 0)
_PRINTSTRING (55, 30), ""
'---------------------------------------------------------------------
IF num$ = ".0" THEN ' Leading decimal followed by a zero.
ELSE
num$ = STR$(num)
END IF
'---------------------------------------------------------------------
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
Pete
Posts: 422
Threads: 27
Joined: Apr 2022
Reputation:
26
SierraKen
since speed is not an issue in a calculator, you could use string-math
here's some code that you should be able to adapt https://web.archive.org/web/202002200200...vault.html
Posts: 2,186
Threads: 222
Joined: Apr 2022
Reputation:
104
Ah, now I see more of what is causing the problem. You are converting string to val and back WHILE you are still entering the number. Axe that. Don't convert the string to num until you hit a computation button.That way, you won't get .308 being processed three times as .3 followed by .30 (which val truncates to .3 and converts to string .3, and then when you input to 8, you get .38 instead of .308. If you waited until the plus sign, minus sign, or whatever computation button was pressed, the val of the string .308 would be val .308, no problem.
Unfortunately, this would require rewriting the flow of the code.
Pete
Shoot first and shoot people who ask questions, later.
Posts: 2,186
Threads: 222
Joined: Apr 2022
Reputation:
104
Okay, based on your first post, not the second one, I made a couple of changes.
See the CONVERT label and '-------------------------------- remark lines for the code added to the equals routine.
I can't be certain it won't cause other problems but it did fix everything I had reported as a bug in my previous posts. Hopefully it is simple enough to follow. i know I hate it when too many changes get made and everyone falls off the coding truck...
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$ = STR$(num)
num$ = LEFT$(num$, LEN(num$) - 1)
_PRINTSTRING (55, 30), num$
num = VAL(num$)
GOSUB number:
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:
num$ = num$ + "0"
IF n = 1 THEN num$ = "-" + num$: n = 0
buttonx = 50: buttony = 295
GOSUB press:
GOSUB number:
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), ""
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
So now we input all the numbers first, then convert to num.
Pete
Posts: 419
Threads: 75
Joined: Apr 2022
Reputation:
22
LOL!!!! Thank you Pete!!!! I was worried I would have to dump PrintString and go with LOCATE on every variable! LOL That would be horrendous and probably not even possible on such a small window. You rock.
I see you fixed it with this: num$ = LTrim$(Str$(num)) on the Equals section, and dumping the STR$ and VAL lines on the number: and number2: sections, awesome! Thanks again.
This will wrap up this app, at least for the time being. Now I can use this app instead of the one that comes with Windows.
Posts: 276
Threads: 14
Joined: Apr 2022
Reputation:
27
07-28-2022, 12:41 AM
(This post was last modified: 07-28-2022, 12:50 AM by OldMoses.)
(07-25-2022, 09:53 PM)bplus Wrote: Yes there is a way to do this that waits for _Mousebutton(1) to clear, Old Moses had a nice little sub, but Ken doesn't recall I don't think, I saved it but on my hard drive that I lost.
Maybe @OldMoses could remind us?
I learned the simple _delay trick from Pete.
That was my Clear_MB (mouse button #) subroutine. I call it immediately after I get a mouse click and pass the button number, then let whatever sort of mouse button handling I need to do. It stops any chance of a "click through" event. I've never noticed any tendency to slow things down.
EDIT: Ah, I see you guys already found it. Glad it can be of use.
Code: (Select All) 'Description
'Clear the mousebutton queue
SUB Clear_MB (var AS INTEGER)
DO UNTIL NOT _MOUSEBUTTON(var)
WHILE _MOUSEINPUT: WEND
LOOP
END SUB 'Clear_MB
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Posts: 20
Threads: 2
Joined: Apr 2022
Reputation:
2
(07-27-2022, 11:51 AM)bplus Wrote: Ooops, indeed I missed a line with the copy & paste. Rather obvious and simple to fix.
I hope everyone sees the silliness of the manual positioning of buttons. It's difficult to
keep boxes lined up, esp. during development when one is resizing and repositioning
them. What if one decides to use a different screen resolution? Again it's a pain to keep
them consistent in position and style.
@ChiaPet, Beautiful elegance!
Too bad you left this Data Line out:
DATA Copy,Paste, <Back, RND
I think those are missing items from Case Is code. I see your _delay .2 is later.
Posts: 419
Threads: 75
Joined: Apr 2022
Reputation:
22
07-28-2022, 10:11 PM
(This post was last modified: 07-28-2022, 10:13 PM by SierraKen.)
Pete, now the Back Space button doesn't work. I'll see if I can fix it but if we can't, then I'll remove it and put something else in its place.
|