Calculadora em QB64
Calculadora em QB64
"
begin:
_Font f&
num$ = ""
c=0
a = 0: s = 0: t = 0: d = 0
'Setup calculator
'Buttons
For bb = 0 To 10
c = c + 10
Next bb
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
c=0
'Paste Button
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
c=0
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
c=0
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
c=0
'Green C Button
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
wer:
'Label Buttons
Do
_Limit 30
a$ = InKey$
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
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:
_Delay .5
num2$ = _Trim$(num$)
_Clipboard$ = num2$
End If
'Clipboard Button
If mousex > 50 And mousex < 125 And mousey > 460 And mousey < 515 Then
clip2:
GoSub press:
_Delay .5
num2$ = _Trim$(num$)
_Clipboard$ = num2$
End If
'Paste Button
If mousex > 125 And mousex < 200 And mousey > 460 And mousey < 515 Then
paste:
num$ = _Clipboard$
num = Val(num$)
GoSub number:
End If
If mousex > 200 And mousex < 275 And mousey > 460 And mousey < 515 Then
backbutton:
GoSub press:
GoSub number2
End If
'Random Button
If mousex > 275 And mousex < 350 And mousey > 460 And mousey < 515 Then
timebutton:
GoSub press:
num$ = Str$(Rnd)
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$ = ""
GoSub zero:
End If
'1/x
If mousex > 50 And mousex < 125 And mousey > 405 And mousey < 460 Then
fraction:
num = Val(num$)
num = 1 / num
num$ = Str$(num)
skipthis:
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)
GoSub press:
GoSub number2:
End If
'EXP
If mousex > 200 And mousex < 275 And mousey > 405 And mousey < 460 Then
expcommand:
num = Exp(Val(num$))
num$ = Str$(num)
GoSub number2:
GoSub press:
End If
'Postive or Negative
If mousex > 275 And mousex < 350 And mousey > 405 And mousey < 460 Then
posneg:
num = -Val(num$)
num$ = Str$(num)
GoTo skipplusnegative:
End If
skipplusnegative:
GoSub press:
GoSub number:
End If
If mousex > 50 And mousex < 125 And mousey > 350 And mousey < 405 Then
radanddeg:
deg = deg + 1
num = Val(num$)
num = _R2D(num)
num$ = Str$(num)
GoTo skipdeg2rad:
deg2rad:
deg = 0
num = Val(num$)
num = _D2R(num)
num$ = Str$(num)
skipdeg2rad:
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)
GoSub press:
GoSub number2:
End If
'logarithm
If mousex > 200 And mousex < 275 And mousey > 350 And mousey < 405 Then
logarithm:
num = Val(num$)
num = Log(num)
num$ = Str$(num)
skiplog:
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)
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:
GoSub press:
GoSub number:
End If
'Sine
If mousex > 126 And mousex < 200 And mousey > 75 And mousey < 130 Then
sine:
num$ = Str$(num)
GoSub press:
GoSub number:
End If
'Cosine
If mousex > 200 And mousex < 275 And mousey > 75 And mousey < 130 Then
cosine:
GoSub press:
GoSub number:
End If
'Tangent
If mousex > 275 And mousex < 350 And mousey > 75 And mousey < 130 Then
tangent:
num$ = Str$(num)
GoSub press:
GoSub number:
End If
'Number Buttons
If mousex > 50 And mousex < 125 And mousey > 130 And mousey < 185 Then
seven:
GoSub press:
GoSub number:
End If
If mousex > 126 And mousex < 200 And mousey > 130 And mousey < 185 Then
eight:
GoSub press:
GoSub number:
End If
If mousex > 200 And mousex < 275 And mousey > 130 And mousey < 185 Then
nine:
GoSub press:
GoSub number:
End If
If mousex > 50 And mousex < 125 And mousey > 185 And mousey < 240 Then
four:
GoSub press:
GoSub number:
End If
If mousex > 126 And mousex < 200 And mousey > 185 And mousey < 240 Then
five:
num$ = num$ + "5"
GoSub press:
GoSub number:
End If
If mousex > 200 And mousex < 275 And mousey > 185 And mousey < 240 Then
six:
GoSub press:
GoSub number:
End If
If mousex > 50 And mousex < 125 And mousey > 240 And mousey < 295 Then
one:
GoSub press:
GoSub number:
End If
If mousex > 126 And mousex < 200 And mousey > 240 And mousey < 295 Then
two:
GoSub press:
GoSub number:
End If
If mousex > 200 And mousex < 275 And mousey > 240 And mousey < 295 Then
three:
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.
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
Next check
skipdec:
GoSub press:
End If
'Equals
If mousex > 200 And mousex < 275 And mousey > 295 And mousey < 350 Then
equals:
'----------------------------------------------------
num$ = LTrim$(Str$(num))
'----------------------------------------------------
GoSub press:
GoSub number2:
num$ = ""
num = 0
oldnum$ = ""
End If
'Add
If mousex > 275 And mousex < 350 And mousey > 295 And mousey < 350 Then
add:
d = 0: a = 1: s = 0: t = 0
GoSub convert:
oldnum$ = num$
num$ = ""
GoSub press:
End If
'Subtract
If mousex > 275 And mousex < 350 And mousey > 240 And mousey < 295 Then
subtract:
d = 0: a = 0: s = 1: t = 0
GoSub convert:
oldnum$ = num$
num$ = ""
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$
num$ = ""
GoTo nex2:
End If
If t = 1 Then
t=0
End If
GoSub number2:
nex2:
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$
num$ = ""
GoTo nex1:
End If
d=0
End If
GoSub number2:
nex1:
GoSub press:
End If
End If
Loop
convert:
End If
num = Val(num$)
Return
number:
End If
'For Math
number2:
End If
Return
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
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
Print
Print "Below can be either Number Pad or the others."
Cls
GoTo begin:
Loop