April 22, 2025, 08:27:34 pm
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
Forever
Login with username, password and session length
News
: Want to see a specific Tutorial? ASK!
Home
Help
Search
Arcade
Links
Staff List
Login
Register
My calculator,Math useing input,loops, and some choices
Weekly Qbasic and Qb64 Lesson Topics
>
Forum
>
General Category
>
General QB64 Forum
>
My calculator,Math useing input,loops, and some choices
Pages: [
1
]
2
3
« previous
next »
Print
Author
Topic: My calculator,Math useing input,loops, and some choices (Read 2902 times)
GarrisonRicketson
Admin
Administrator
Hero Member
Posts: 583
My calculator,Math useing input,loops, and some choices
«
on:
January 01, 2011, 01:24:49 am »
I was trying to make a "calculator" mostly I just wanted the add, but it alo has multiply,...What I do not like, is it will show a ? ,after the R to return,
if you put in a number, it repeats,..then you enter the 1st number,then request the second number,--anyway one needs to try it too see what I mean,...it works ok, but it could be better, I just don't know how to make it better, ..I do want it to keep showing all the results,..I would like to make it where in the addition, I could use a string of numbers IE: 3+4+7+2+6+7+8= Any suggestions welcome:
--------code below---------------------
1 PRINT "WELCOME to Garrys invention"
COLOR 2: PRINT "You Can do these things "
PRINT "1)Multiply"
PRINT "2)ADD"
PRINT "4)Quit"
PRINT "3)Return to top"
INPUT i
IF i = 1 THEN GOTO 2
IF i = 2 THEN GOTO 3
IF i = 3 THEN GOTO 1
IF i = 4 THEN END
2 DO
PRINT "press r to return to top"
INPUT i
IF i = r GOTO 1
INPUT C
PRINT "INPUT NEXT NUMBER"
INPUT d
PRINT C * d
INPUT C
INPUT d
PRINT C * d
LOOP
3 DO
PRINT "press R to return to top"
INPUT i
IF i = r GOTO 1
PRINT "input next number"
INPUT A
INPUT b
PRINT A + b
LOOP
-----------------end code-----------------
from Garry
Report Spam
Logged
From Garry
http://www.garryricketsonartworks.com/SMF
http://www.garryricketsonartworks.com/phpbbforum
http://www.garryricketsonartworks.org
http://www.garryspages.webs.com
http://wittywittywhatisthat.freesmfhosting.com/index.php
http://www.garryricketsonartworks.com/FluxBB
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #1
on:
March 11, 2011, 01:43:41 pm »
About the Question mark,
It doesnt always work for me but someplace in the wiki is where i think
I seen This.
If you put a comma before the var it will show the ?
if you put a semi colon before the var it wont show.
I may have it backwards
but try it both ways and if that helps get rid of the ?
OOPS Mr Why already answered this . sorry
Dustie
«
Last Edit: March 11, 2011, 01:46:13 pm by Dustie Bear
»
Report Spam
Logged
GarrisonRicketson
Admin
Administrator
Hero Member
Posts: 583
Re: My calculator,Math useing input,loops, and some choices
«
Reply #2
on:
March 11, 2011, 03:55:23 pm »
I could not make any sense of What MR. Why posted, so I never commented on it,...For me the ? is like a prompt, it is asking for a response,...
It is good to review some of these things,...
And I notice in the code OldosLover posted, it runs like excersise, gveing the user 2 numbers, and you have to enter the correct answer....
I was trying to make it a claculater IE: when one selects add: the then enter the numbers they want to add, 55, then 50, and it would show, the result,..
105 by string I ment, the user could enter, a string of numbers add, 2+5+6+8+9 I know one can use
Code:
PRINT 2+3+9+2+3
in QB64, and it will calculate, and show the result 19, so what I was trying to do is make a program, where all yu do is enter the numbers yu want to add, or multiply, or divide, and get the answer, a real simple calculator.
Later I guess I got side tracked, and never continued with this....
But would still like to see a calculator....
and Dusty,(and anyone) now yu will see a example, on useing a request for tutorials.....one thing always leads to another...
from Garry
Report Spam
Logged
From Garry
http://www.garryricketsonartworks.com/SMF
http://www.garryricketsonartworks.com/phpbbforum
http://www.garryricketsonartworks.org
http://www.garryspages.webs.com
http://wittywittywhatisthat.freesmfhosting.com/index.php
http://www.garryricketsonartworks.com/FluxBB
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #3
on:
March 13, 2011, 01:42:02 pm »
Hi
I working on a calculater with graphics resembling a calculater but im have trouble figuring
out how to make longer numbers and still have decimal points.
Can you help me figue that out. LOL
I can use integer64 but that drops off the decimals
I have it adding numbers but havent finished the rest of it yet.
If you would like to use this graphic to build yours you more than welcome to it!
Here is a picture of it
http://dl.dropbox.com/u/19871604/calc.bmp
Here is the sub routine that draws it:
Code:
SUB DrawCalculater
'---- Size of calculater
LX = 0
RX = 255
TY = 0
BY = 260
'---- Outline of calculater
'LINE (LX, TY)-(RX, BY), _RGB(70, 70, 70), B
'LINE (LX, TY)-(LX, BY), _RGB(255, 255, 255)
'LINE (LX, TY)-(RX, TY), _RGB(255, 255, 255)
'---- Display Box
LINE (LX + 20, TY + 20)-(RX - 20, TY + 40), _RGB(70, 70, 70), B
LINE (LX + 20, TY + 40)-(RX - 20, TY + 40), _RGB(250, 250, 250)
LINE (RX - 20, TY + 20)-(RX - 20, TY + 40), _RGB(250, 250, 250)
'Draw Buttons
FOR TY = 1 TO 130 STEP 30
FOR LX = 1 TO 169 STEP 56
LINE (LX + 20, TY + 50)-(LX + 65, TY + 74), _RGB(70, 70, 70), B
LINE (LX + 20, TY + 50)-(LX + 20, TY + 74), _RGB(250, 250, 250)
LINE (LX + 20, TY + 50)-(LX + 65, TY + 50), _RGB(250, 250, 250)
NEXT LX
NEXT TY
' ----------- Put Lables on buttons
' --- Row 1
_PRINTSTRING (28, 55), "SqrR": _PRINTSTRING (95, 55), "%"
_PRINTSTRING (145, 55), CHR$(0) + CHR$(26): _PRINTSTRING (192, 55), "Clear"
' --- Row 2
_PRINTSTRING (40, 87), "7": _PRINTSTRING (96, 87), "8"
_PRINTSTRING (150, 88), "9": _PRINTSTRING (200, 87), CHR$(0) + CHR$(246)
' --- Row 3
_PRINTSTRING (40, 117), "4": _PRINTSTRING (96, 117), "5"
_PRINTSTRING (150, 117), "6": _PRINTSTRING (208, 117), "x"
' --- Row 4
_PRINTSTRING (40, 146), "1": _PRINTSTRING (96, 146), "2"
_PRINTSTRING (150, 146), "3": _PRINTSTRING (208, 146), "-"
' --- Row 5
_PRINTSTRING (40, 176), "0": _PRINTSTRING (96, 176), "."
_PRINTSTRING (150, 176), "=": _PRINTSTRING (208, 176), "+"
END SUB
Dustie
«
Last Edit: March 13, 2011, 02:14:57 pm by Dustie Bear
»
Report Spam
Logged
GarrisonRicketson
Admin
Administrator
Hero Member
Posts: 583
Re: My calculator,Math useing input,loops, and some choices
«
Reply #4
on:
March 13, 2011, 03:37:18 pm »
Quote
I working on a calculater with graphics resembling a calculater but im have trouble figuring
out how to make longer numbers and still have decimal points.
Can you help me figue that out. LOL
I can use integer64 but that drops off the decimals
Sorry on that I don't know.
I looked the image, and it is nice I like it,...On the code, I ran it but nothing,
just a black screen, "with press any key" at the bottom, to exit ? I guess thats cause it is just the sub by itself ?
from garry
«
Last Edit: March 26, 2012, 12:05:01 am by GarrisonRicketson
»
Report Spam
Logged
From Garry
http://www.garryricketsonartworks.com/SMF
http://www.garryricketsonartworks.com/phpbbforum
http://www.garryricketsonartworks.org
http://www.garryspages.webs.com
http://wittywittywhatisthat.freesmfhosting.com/index.php
http://www.garryricketsonartworks.com/FluxBB
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #5
on:
March 13, 2011, 05:44:38 pm »
Sorry I only copied the sub : im bad!
heres the whole thing.
I only have the add a couple other buttons working at the moment
the add button , equal button and move back button and clear button work
its not finished but works enough to get the idea. There are plenty notes to
see what happening
Code:
SCREEN _NEWIMAGE(260, 215, 32)
_SCREENMOVE _MIDDLE
CONST KEY_KP0& = 100256
CONST KEY_KP1& = 100257
CONST KEY_KP2& = 100258
CONST KEY_KP3& = 100259
CONST KEY_KP4& = 100260
CONST KEY_KP5& = 100261
CONST KEY_KP6& = 100262
CONST KEY_KP7& = 100263
CONST KEY_KP8& = 100264
CONST KEY_KP9& = 100265
DIM SHARED TxtPosition
'DIM SHARED Shown AS _INTEGER64 ' Integers are not the cats meow for this program! LOL
'DIM SHARED Sum AS _INTEGER64
'DIM SHARED Plus AS _INTEGER64
'DIM SHARED Total AS long
COLOR _RGB(0, 0, 0), _RGB(200, 200, 200)
CLS
' Make the Calculater graphics
DrawCalculater
ClckBttns
SLEEP
SYSTEM
SUB ClckBttns
' -------- Box around color box -----------
txtpos = 220
DO 'WHILE _MOUSEINPUT
rrr = _MOUSEINPUT
' --------- Row 1 --- SqrR ------------------------
IF _MOUSEX > 22 AND _MOUSEX < 65 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN LOCATE 1, 15: PRINT "SqrR ";
END IF
'----------- Row 1 --- Divide -----------------------
IF _MOUSEX > 76 AND _MOUSEX < 121 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN LOCATE 1, 15: PRINT "% ";
END IF
'----------- Row 1 --- Remove last diget entered per mouse click
IF _MOUSEX > 132 AND _MOUSEX < 179 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN
Shonum$ = LEFT$(Shonum$, L - 1)
L = LEN(Shonum$)
IF L > 0 THEN
Shown = VAL(Shonum$): txtpos = txtpos + 8:
_PRINTSTRING (21, 22), " "
_PRINTSTRING (txtpos, 23), Shonum$
ELSE
txtpos = 220: Shonum$ = "": _PRINTSTRING (21, 23), " "
END IF
END IF
END IF
' -------------Row 1 --- Clears the view window and resets the VARS
' --- Clear
IF _MOUSEX > 190 AND _MOUSEX < 1233 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN Shown = 0: Shonum$ = "": txtpos = 220: _PRINTSTRING (27, 22), " "
END IF
' ----------- Row 2 ---- Number 7 -------------
' --- '7'
IF _MOUSEX > 22 AND _MOUSEX < 65 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(7))
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------ row 2 --- Number 8 -------------
IF _MOUSEX > 77 AND _MOUSEX < 122 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(8))
txtpos = txtpos - 8
Shown = Shown + 8
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------Row 2 --- Number 9 ----------
IF _MOUSEX > 133 AND _MOUSEX < 177 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(9))
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------- Row 2 ---Divide ----- Not Set up yet -------
IF _MOUSEX > 189 AND _MOUSEX < 233 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) THEN LOCATE 1, 15: PRINT "Div ";
END IF
' ------------- Row 3 ---Number 4 -------------------------
IF _MOUSEX > 22 AND _MOUSEX < 66 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(4))
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ----------- Row 3 ----- Number 5 ------------------------
IF _MOUSEX > 77 AND _MOUSEX < 121 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(5))
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ----------- Row 3 ----- Number 6 --------------------
IF _MOUSEX > 134 AND _MOUSEX < 178 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(6))
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------- Row 3 ------- Multiply not setup yet ----------------------
' --- X
IF _MOUSEX > 189 AND _MOUSEX < 234 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) THEN LOCATE 1, 15: PRINT "X ";
END IF
' ------------- Row 4 ----- Number 1 -----------------------
IF _MOUSEX > 22 AND _MOUSEX < 66 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(1))
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' -------------Row 4 ------ Number 2 -----------------------
IF _MOUSEX > 78 AND _MOUSEX < 122 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(2))
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------Row 4 -------- Number 3 -----------------
IF _MOUSEX > 133 AND _MOUSEX < 179 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(3))
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ---------- Row 4 -------------Divide not set up yet -----------------------------
IF _MOUSEX > 190 AND _MOUSEX < 234 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) THEN LOCATE 1, 15: PRINT "- ";
END IF
' --------- Row 5 ------ Number 0 ----------------------------
IF _MOUSEX > 22 AND _MOUSEX < 64 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) AND LEN(Shownum$) < 12 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(0))
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' -------- Row 5 ----------- Decimal point ---------
IF _MOUSEX > 78 AND _MOUSEX < 122 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) THEN
Shonum$ = Shonum$ + LTRIM$(".")
txtpos = 220
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' --------Row 5 ------------ Equals works ------------------------
IF _MOUSEX > 133 AND _MOUSEX < 179 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) THEN
_PRINTSTRING (21, 22), " "
Shown = Shown + Sum
Shownum$ = LTRIM$(STR$(Shown))
L = LEN(Shonum$)
L = L * 8
txtpos = 218 - L
_PRINTSTRING (txtpos, 23), Shownum$
Shownum$ = ""
END IF
END IF
'----------- Row 5 -------------------- add works--------------------
IF _MOUSEX > 190 AND _MOUSEX < 234 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
' ------------- End Button Routines -----------------------------
' the following Seems to stop most of excessive mouse clicks
_DELAY .02
'------ Clear the mouse droppings! ---------------
Mclear = 0
DO UNTIL Mclear <> 0
DO WHILE _MOUSEINPUT
IF _MOUSEBUTTON(1) THEN Mclear = Mclear + 1
LOOP
LOOP
LOOP
END SUB
'____________________________________________________________
'------------------------------------------------------------
SUB DrawCalculater
'---- Size of calculater
LX = 0
RX = 255
TY = 0
BY = 260
'---- Outline of calculater
'LINE (LX, TY)-(RX, BY), _RGB(70, 70, 70), B
'LINE (LX, TY)-(LX, BY), _RGB(255, 255, 255)
'LINE (LX, TY)-(RX, TY), _RGB(255, 255, 255)
'---- Display Box
LINE (LX + 20, TY + 20)-(RX - 20, TY + 40), _RGB(70, 70, 70), B
LINE (LX + 20, TY + 40)-(RX - 20, TY + 40), _RGB(250, 250, 250)
LINE (RX - 20, TY + 20)-(RX - 20, TY + 40), _RGB(250, 250, 250)
'Draw Buttons
FOR TY = 1 TO 130 STEP 30
FOR LX = 1 TO 169 STEP 56
LINE (LX + 20, TY + 50)-(LX + 65, TY + 74), _RGB(70, 70, 70), B
LINE (LX + 20, TY + 50)-(LX + 20, TY + 74), _RGB(250, 250, 250)
LINE (LX + 20, TY + 50)-(LX + 65, TY + 50), _RGB(250, 250, 250)
NEXT LX
NEXT TY
' ----------- Put Lables on buttons
' --- Row 1
_PRINTSTRING (28, 55), "SqrR": _PRINTSTRING (95, 55), "%"
_PRINTSTRING (145, 55), CHR$(0) + CHR$(26): _PRINTSTRING (192, 55), "Clear"
' --- Row 2
_PRINTSTRING (40, 87), "7": _PRINTSTRING (96, 87), "8"
_PRINTSTRING (150, 88), "9": _PRINTSTRING (200, 87), CHR$(0) + CHR$(246)
' --- Row 3
_PRINTSTRING (40, 117), "4": _PRINTSTRING (96, 117), "5"
_PRINTSTRING (150, 117), "6": _PRINTSTRING (208, 117), "x"
' --- Row 4
_PRINTSTRING (40, 146), "1": _PRINTSTRING (96, 146), "2"
_PRINTSTRING (150, 146), "3": _PRINTSTRING (208, 146), "-"
' --- Row 5
_PRINTSTRING (40, 176), "0": _PRINTSTRING (96, 176), "."
_PRINTSTRING (150, 176), "=": _PRINTSTRING (208, 176), "+"
END SUB
Report Spam
Logged
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #6
on:
March 13, 2011, 06:42:48 pm »
I could use your help on doing large numbers in text form or maybe I didnt understand correctly.
My middle name is Confussed,
I agree divide creates decimals , unless you want to enter say 24.53 or somthing
Thats where I was having trouble , for instance
num = 49.64
Foo$ = str$(num)
Print Foo$
49
everything past decimal is dropped
Shown = Shown + Sum
Shownum$ = LTRIM$(STR$(Shown))
Im kinda using strings. but I dont know a way to do the math without converting it to numerals
I could certainly use your help in that department if ya wouldnt mind?
heres reason I convert to text$
I kind of fell in love with _PRINTSTRING, sure makes graphics a pleasure, wish we
had something like that years ago. I hated print the get put image of the text to another
location.
Dustie
«
Last Edit: March 13, 2011, 06:46:06 pm by Dustie Bear
»
Report Spam
Logged
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #7
on:
March 13, 2011, 07:02:45 pm »
I finaly got the add to add with decimals, thanks
you can enter say, 5.4 click add
then enter 3.2
and it will give answer 8.6
I have no idea how I did it but it works.
Thanks for the response, I may toy with that too.
Now to get my Vars to accept realy long numbers! LOL
Dustie
Report Spam
Logged
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #8
on:
March 13, 2011, 08:39:50 pm »
Select case would be cool
Also I found few bugs in it and im working on them so its not
ready to repost just it yet.
Old Dos, if you want more buttons, just go down to the sub routine
and find this
'Draw Buttons
FOR TY = 1 TO 130 STEP 30
change the 130 to 160 to make 4 more buttons then
make the window taller to fit the new row of buttons
If you need more buttons
pretty cool , huh?
I use locate and print the _mousex and mousey up the the corner someplace to find the locations
of the buttons.
i have a weather chart program I made that uses the mouse with select case
options and works good, So that would be cool.
I may post my weather Chart program before long. trouble with it is I have to
check the weather early in the morning, then the temp at hotest part of day.
and I dont like getting up that early. LOL
Cant wait to see your version of calculater.
Dustie
«
Last Edit: March 13, 2011, 09:33:49 pm by Dustie Bear
»
Report Spam
Logged
GarrisonRicketson
Admin
Administrator
Hero Member
Posts: 583
Re: My calculator,Math useing input,loops, and some choices
«
Reply #9
on:
March 13, 2011, 11:27:08 pm »
It sounds worth while to me,...right now when I need a calculator I am useing my cell phone! I had one I downloaded from some where that actually was very similar to Dustys, but some how I lost it ....If he,you do make one, I promise, I will take good care of it,and try not to lose it! but if I do, it will be here,, and I can get it again,...or idealy I will learn how to make one.
from Garry
Report Spam
Logged
From Garry
http://www.garryricketsonartworks.com/SMF
http://www.garryricketsonartworks.com/phpbbforum
http://www.garryricketsonartworks.org
http://www.garryspages.webs.com
http://wittywittywhatisthat.freesmfhosting.com/index.php
http://www.garryricketsonartworks.com/FluxBB
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #10
on:
March 13, 2011, 11:40:38 pm »
I have all the functions working now and played with it for a while
OOPS,, just looked on here and square root isn't done yet. Oversite, My Bad
I made a pointer calling it Answer$ = "Add" for instance - depending on the function called for
the formulas are done when the equal button is pressed.
This version is just a start perhaps. So all ideas are welcome.
In case your wondering, (im not good at naming Vars),,,,, Shown var stands for Show Number. LOL
Then its its transferred to Shown$ so it can be used with the graphic print command.
so far the only problem I had was , if I enter a number and dont let up the button soon
enough it will put a few more of that number up! I followed the Wiki routine which is
suppose to avoid that and it helps some but not always.
I like your idea with select case etc, it might make it easier to find routines.
it would give it more clarity I think.
Code:
SCREEN _NEWIMAGE(260, 215, 32)
_SCREENMOVE _MIDDLE
CONST KEY_KP0& = 100256
CONST KEY_KP1& = 100257
CONST KEY_KP2& = 100258
CONST KEY_KP3& = 100259
CONST KEY_KP4& = 100260
CONST KEY_KP5& = 100261
CONST KEY_KP6& = 100262
CONST KEY_KP7& = 100263
CONST KEY_KP8& = 100264
CONST KEY_KP9& = 100265
DIM SHARED TxtPosition
'DIM SHARED Shown AS _INTEGER64 ' Integers are not the cats meow for this program! LOL
'DIM SHARED Sum AS _INTEGER64
'DIM SHARED Plus AS _INTEGER64
'DIM SHARED Total AS long
COLOR _RGB(0, 0, 0), _RGB(200, 200, 200)
CLS
' Make the Calculater graphics
DrawCalculater
ClckBttns
SLEEP
SYSTEM
SUB ClckBttns
' -------- Box around color box -----------
txtpos = 220
DO 'WHILE _MOUSEINPUT
rrr = _MOUSEINPUT
' --------- Row 1 --- SqrR ------------------------
IF _MOUSEX > 22 AND _MOUSEX < 65 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN LOCATE 1, 15: PRINT "SqrR ";
END IF
'----------- Row 1 --- Percent -----------------------
IF _MOUSEX > 76 AND _MOUSEX < 121 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "PerCnt"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
'----------- Row 1 --- Remove last diget entered per mouse click
IF _MOUSEX > 132 AND _MOUSEX < 179 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN
L = LEN(Shonum$)
Shonum$ = LEFT$(Shonum$, L - 1)
Shownum = VAL(Shonum$)
IF L > 0 THEN
Shown = VAL(Shonum$): txtpos = txtpos + 8:
_PRINTSTRING (21, 22), " "
_PRINTSTRING (txtpos, 23), Shonum$
ELSE
txtpos = 220: Shonum$ = "": _PRINTSTRING (21, 23), " "
END IF
END IF
END IF
' -------------Row 1 --- Clears the view window and resets the VARS
' --- Clear
IF _MOUSEX > 190 AND _MOUSEX < 233 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN Shown = 0: Sum = 0: Shonum$ = "": txtpos = 220: _PRINTSTRING (27, 22), " "
END IF
' ----------- Row 2 ---- Number 7 -------------
' --- '7'
IF _MOUSEX > 22 AND _MOUSEX < 65 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(7))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------ row 2 --- Number 8 -------------
IF _MOUSEX > 77 AND _MOUSEX < 122 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(8))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = Shown + 8
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------Row 2 --- Number 9 ----------
IF _MOUSEX > 133 AND _MOUSEX < 177 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(9))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------- Row 2 ---Divide ----- Not Set up yet -------
IF _MOUSEX > 189 AND _MOUSEX < 233 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "Div"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
' ------------- Row 3 ---Number 4 -------------------------
IF _MOUSEX > 22 AND _MOUSEX < 66 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(4))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ----------- Row 3 ----- Number 5 ------------------------
IF _MOUSEX > 77 AND _MOUSEX < 121 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(5))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ----------- Row 3 ----- Number 6 --------------------
IF _MOUSEX > 134 AND _MOUSEX < 178 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(6))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------- Row 3 ------- Multiply not setup yet ----------------------
' --- X
IF _MOUSEX > 189 AND _MOUSEX < 234 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "Mult"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
' ------------- Row 4 ----- Number 1 -----------------------
IF _MOUSEX > 22 AND _MOUSEX < 66 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(1))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' -------------Row 4 ------ Number 2 -----------------------
IF _MOUSEX > 78 AND _MOUSEX < 122 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(2))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------Row 4 -------- Number 3 -----------------
IF _MOUSEX > 133 AND _MOUSEX < 179 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(3))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ---------- Row 4 ------------- Subtract -----------------------------
IF _MOUSEX > 190 AND _MOUSEX < 234 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "Sub"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
' --------- Row 5 ------ Number 0 ----------------------------
IF _MOUSEX > 22 AND _MOUSEX < 64 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) AND LEN(Shownum$) < 12 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(0))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' -------- Row 5 ----------- Decimal point ---------
IF _MOUSEX > 78 AND _MOUSEX < 122 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) THEN
Shonum$ = Shonum$ + LTRIM$(".")
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' --------Row 5 ------------ Equals works ------------------------
IF _MOUSEX > 133 AND _MOUSEX < 179 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) THEN
_PRINTSTRING (21, 22), " "
IF Answer$ = "PerCnt" THEN
Sum = Sum / 100
Shown = Sum * Shown
END IF
IF Answer$ = "Sub" THEN
Shown = Sum - Shown
END IF
IF Answer$ = "add" THEN
Shown = Shown + Sum
END IF
IF Answer$ = "Mult" THEN
Shown = Shown * Sum
END IF
IF Answer$ = "Div" THEN
Shown = Sum / Shown
END IF
IF Answer$ = "Mod" THEN
Shown = Sum \ Shown
END IF
Shonum$ = RTRIM$(STR$(Shown))
L = LEN(Shonum$)
L = L * 8 - 8
txtpos = 220 - L
_PRINTSTRING (txtpos, 23), Shonum$
Shownum$ = ""
END IF
END IF
'----------- Row 5 -------------------- add works--------------------
IF _MOUSEX > 190 AND _MOUSEX < 234 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "add"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
' ------------- End Button Routines -----------------------------
' the following Seems to stop most of excessive mouse clicks
_DELAY .02
'------ Clear the mouse droppings! ---------------
Mclear = 0
DO UNTIL Mclear <> 0
DO WHILE _MOUSEINPUT
IF _MOUSEBUTTON(1) THEN Mclear = Mclear + 1
LOOP
LOOP
LOOP
END SUB
'____________________________________________________________
'------------------------------------------------------------
SUB DrawCalculater
'---- Size of calculater
LX = 0
RX = 255
TY = 0
BY = 260
'---- Outline of calculater
'LINE (LX, TY)-(RX, BY), _RGB(70, 70, 70), B
'LINE (LX, TY)-(LX, BY), _RGB(255, 255, 255)
'LINE (LX, TY)-(RX, TY), _RGB(255, 255, 255)
'---- Display Box
LINE (LX + 20, TY + 20)-(RX - 20, TY + 40), _RGB(70, 70, 70), B
LINE (LX + 20, TY + 40)-(RX - 20, TY + 40), _RGB(250, 250, 250)
LINE (RX - 20, TY + 20)-(RX - 20, TY + 40), _RGB(250, 250, 250)
'Draw Buttons
FOR TY = 1 TO 130 STEP 30
FOR LX = 1 TO 169 STEP 56
LINE (LX + 20, TY + 50)-(LX + 65, TY + 74), _RGB(70, 70, 70), B
LINE (LX + 20, TY + 50)-(LX + 20, TY + 74), _RGB(250, 250, 250)
LINE (LX + 20, TY + 50)-(LX + 65, TY + 50), _RGB(250, 250, 250)
NEXT LX
NEXT TY
' ----------- Put Lables on buttons
' --- Row 1
_PRINTSTRING (28, 55), "SqrR": _PRINTSTRING (97, 55), "%"
_PRINTSTRING (145, 55), CHR$(0) + CHR$(26): _PRINTSTRING (192, 55), "Clear"
' --- Row 2
_PRINTSTRING (40, 87), "7": _PRINTSTRING (96, 87), "8"
_PRINTSTRING (150, 88), "9": _PRINTSTRING (200, 87), CHR$(0) + CHR$(246)
' --- Row 3
_PRINTSTRING (40, 117), "4": _PRINTSTRING (96, 117), "5"
_PRINTSTRING (150, 117), "6": _PRINTSTRING (208, 117), "x"
' --- Row 4
_PRINTSTRING (40, 146), "1": _PRINTSTRING (96, 146), "2"
_PRINTSTRING (150, 146), "3": _PRINTSTRING (208, 146), "-"
' --- Row 5
_PRINTSTRING (40, 176), "0": _PRINTSTRING (96, 176), "."
_PRINTSTRING (150, 176), "=": _PRINTSTRING (208, 176), "+"
END SUB
«
Last Edit: March 14, 2011, 12:09:39 am by Dustie Bear
»
Report Spam
Logged
GarrisonRicketson
Admin
Administrator
Hero Member
Posts: 583
Re: My calculator,Math useing input,loops, and some choices
«
Reply #11
on:
March 14, 2011, 01:28:21 am »
It looks good, but, I found a "bug" I tried 58 devided by 10, and keep getting 1.3,....? should be 5.8, the add, multiply seems to be good,...
and don't get me wrong, I couldn't have even done this much,...
From Garry, take your time there is no hurry
OOPS!
Code:
' ------------- Row 2 ---Divide ----- Not Set up yet ----
IF _MOUSEX > 189 AND _MOUSEX < 233 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "Div"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
Sorry, it is not a "bug", I just noticed in your code,.
divide----not set up yet, some numbers do divide ok,..but if it is not yet ready...
But deffinately looks good so far..
OlDoslover, yes big numbers,...but not to big,...so they all fit on my screen!
ABOUT THIS BIG
«
Last Edit: March 14, 2011, 01:40:58 am by GarrisonRicketson
»
Report Spam
Logged
From Garry
http://www.garryricketsonartworks.com/SMF
http://www.garryricketsonartworks.com/phpbbforum
http://www.garryricketsonartworks.org
http://www.garryspages.webs.com
http://wittywittywhatisthat.freesmfhosting.com/index.php
http://www.garryricketsonartworks.com/FluxBB
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #12
on:
March 14, 2011, 09:15:07 am »
Garry, I found the 5.8 bug, I was starting to think it
was a glitch in QB64 but found it was a typo I made. Thanks for finding that, it had to do
with the way Numbr 8 was being handled
Garry Add two lines at the top of the program, you will have
big letters
like this
SCREEN _NEWIMAGE(260, 215, 32) <---- these two lines are at the top
_SCREENMOVE _MIDDLE
_FULLSCREEN <--- add these two lines, just below the above
_MOUSESHOW
Old Dos, Yes my backspace is pointing in this direction. ---->
My handheld calculater is pointing in the direction so I made mine the same.
Thanks for all the tips and help guys, just hope we dont find to many more bugs. LOL
I will post the program again as soon as I can look over Old Dos's Mouse release routine.
Dont see a need to as the changes has been minor since last posting.
Dustie
Report Spam
Logged
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #13
on:
March 14, 2011, 02:39:18 pm »
Got your MousePoll to work,
and you can make the window _FULLSCREEN if you unrem it at the top of the prog
so you can have BIG letters LOL
This Pole for the mouse is even a bit better for this purpose now
I removed a lot of the code as wasnt necesary for this prog
first checks for mouse button then
if -1 then call MousePoll
look at the MousePoll sub to see what went on from there.
Rreason to put delay in the mousePoll instead of main loop will be obvious when you see it
as it doesnt slow down the main prog when nothing has been clicked.
Also added Square Root which I forgot in the last entry!
Boy and I ever getting forgetfull in my old age!
Dustie
Code:
SCREEN _NEWIMAGE(260, 215, 32)
_SCREENMOVE _MIDDLE
'_FULLSCREEN
'_MOUSESHOW
CONST KEY_KP0& = 100256
CONST KEY_KP1& = 100257
CONST KEY_KP2& = 100258
CONST KEY_KP3& = 100259
CONST KEY_KP4& = 100260
CONST KEY_KP5& = 100261
CONST KEY_KP6& = 100262
CONST KEY_KP7& = 100263
CONST KEY_KP8& = 100264
CONST KEY_KP9& = 100265
DIM SHARED TxtPosition
DIM SHARED mx%, my%, mbl%, mbr%
DIM SHARED Shown AS SINGLE
DIM SHARED Sum AS SINGLE
COLOR _RGB(0, 0, 0), _RGB(200, 200, 200)
CLS
' Make the Calculater graphics
DrawCalculater
ClckBttns
SLEEP
SYSTEM
SUB ClckBttns
' -------- Box around color box -----------
txtpos = 220
DO 'WHILE _MOUSEINPUT
rrr = _MOUSEINPUT
' --------- Row 1 --- SqrR ------------------------
IF _MOUSEX > 22 AND _MOUSEX < 65 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Sum = Shown
Shown = SQR(Sum)
Shonum$ = RTRIM$(STR$(Shown))
L = LEN(Shonum$)
L = L * 8 - 8
txtpos = 220 - L
_PRINTSTRING (txtpos, 23), Shonum$
Shownum$ = ""
END IF
END IF
'----------- Row 1 --- Percent -----------------------
IF _MOUSEX > 76 AND _MOUSEX < 121 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "PerCnt"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
'----------- Row 1 --- Remove last diget entered per mouse click
IF _MOUSEX > 132 AND _MOUSEX < 179 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN
L = LEN(Shonum$)
Shonum$ = LEFT$(Shonum$, L - 1)
Shownum = VAL(Shonum$)
IF L > 0 THEN
Shown = VAL(Shonum$): txtpos = txtpos + 8:
_PRINTSTRING (21, 22), " "
_PRINTSTRING (txtpos, 23), Shonum$
ELSE
txtpos = 220: Shonum$ = "": _PRINTSTRING (21, 23), " "
END IF
END IF
END IF
' -------------Row 1 --- Clears the view window and resets the VARS
' --- Clear
IF _MOUSEX > 190 AND _MOUSEX < 1233 AND _MOUSEY > 51 AND _MOUSEY < 75 THEN
IF _MOUSEBUTTON(1) THEN Shown = 0: Sum = 0: Shonum$ = "": txtpos = 220: _PRINTSTRING (27, 22), " "
END IF
' ----------- Row 2 ---- Number 7 -------------
' --- '7'
IF _MOUSEX > 22 AND _MOUSEX < 65 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(7))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------ row 2 --- Number 8 -------------
IF _MOUSEX > 77 AND _MOUSEX < 122 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(8))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------Row 2 --- Number 9 ----------
IF _MOUSEX > 133 AND _MOUSEX < 177 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(9))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------- Row 2 ---Divide ----- Not Set up yet -------
IF _MOUSEX > 189 AND _MOUSEX < 233 AND _MOUSEY > 82 AND _MOUSEY < 104 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "Div"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
' ------------- Row 3 ---Number 4 -------------------------
IF _MOUSEX > 22 AND _MOUSEX < 66 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(4))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ----------- Row 3 ----- Number 5 ------------------------
IF _MOUSEX > 77 AND _MOUSEX < 121 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(5))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ----------- Row 3 ----- Number 6 --------------------
IF _MOUSEX > 134 AND _MOUSEX < 178 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(6))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------- Row 3 ------- Multiply not setup yet ----------------------
' --- X
IF _MOUSEX > 189 AND _MOUSEX < 234 AND _MOUSEY > 111 AND _MOUSEY < 135 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "Mult"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
' ------------- Row 4 ----- Number 1 -----------------------
IF _MOUSEX > 22 AND _MOUSEX < 66 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(1))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' -------------Row 4 ------ Number 2 -----------------------
IF _MOUSEX > 78 AND _MOUSEX < 122 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(2))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ------------Row 4 -------- Number 3 -----------------
IF _MOUSEX > 133 AND _MOUSEX < 179 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) AND LEN(Shonum$) < 16 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(3))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' ---------- Row 4 ------------- Subtract -----------------------------
IF _MOUSEX > 190 AND _MOUSEX < 234 AND _MOUSEY > 142 AND _MOUSEY < 165 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "Sub"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
' --------- Row 5 ------ Number 0 ----------------------------
IF _MOUSEX > 22 AND _MOUSEX < 64 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) AND LEN(Shownum$) < 12 THEN
Shonum$ = Shonum$ + LTRIM$(STR$(0))
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' -------- Row 5 ----------- Decimal point ---------
IF _MOUSEX > 78 AND _MOUSEX < 122 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) THEN
Shonum$ = Shonum$ + LTRIM$(".")
L = LEN(Shonum$)
L = L * 8 - 16
txtpos = 220 - L
txtpos = txtpos - 8
Shown = VAL(Shonum$)
_PRINTSTRING (txtpos, 23), Shonum$
END IF
END IF
' --------Row 5 ------------ Equals works ------------------------
IF _MOUSEX > 133 AND _MOUSEX < 179 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) THEN
_PRINTSTRING (21, 22), " "
IF Answer$ = "PerCnt" THEN
Sum = Sum / 100
Shown = Sum * Shown
END IF
IF Answer$ = "Sub" THEN
Shown = Sum - Shown
END IF
IF Answer$ = "add" THEN
Shown = Shown + Sum
END IF
IF Answer$ = "Mult" THEN
Shown = Shown * Sum
END IF
IF Answer$ = "Div" THEN
Shown = Sum / Shown
END IF
IF Answer$ = "Mod" THEN
Shown = Sum \ Shown
END IF
Shonum$ = RTRIM$(STR$(Shown))
L = LEN(Shonum$)
L = L * 8 - 8
txtpos = 220 - L
_PRINTSTRING (txtpos, 23), Shonum$
Shownum$ = ""
END IF
END IF
'----------- Row 5 -------------------- add works--------------------
IF _MOUSEX > 190 AND _MOUSEX < 234 AND _MOUSEY > 171 AND _MOUSEY < 195 THEN
IF _MOUSEBUTTON(1) THEN
txtpos = 220: _PRINTSTRING (21, 23), " "
Answer$ = "add"
Sum = Shown
Shown = 0
Shonum$ = ""
END IF
END IF
' ------------- End Button Routines -----------------------------
mbl% = _MOUSEBUTTON(1)
IF mbl% = -1 THEN MousePoll
LOOP
END SUB
'____________________________________________________________
'------------------------------------------------------------
SUB DrawCalculater
'---- Size of calculater
LX = 0
RX = 255
TY = 0
BY = 260
'---- Outline of calculater
'LINE (LX, TY)-(RX, BY), _RGB(70, 70, 70), B
'LINE (LX, TY)-(LX, BY), _RGB(255, 255, 255)
'LINE (LX, TY)-(RX, TY), _RGB(255, 255, 255)
'---- Display Box
LINE (LX + 20, TY + 20)-(RX - 20, TY + 40), _RGB(70, 70, 70), B
LINE (LX + 20, TY + 40)-(RX - 20, TY + 40), _RGB(250, 250, 250)
LINE (RX - 20, TY + 20)-(RX - 20, TY + 40), _RGB(250, 250, 250)
'Draw Buttons
FOR TY = 1 TO 130 STEP 30
FOR LX = 1 TO 169 STEP 56
LINE (LX + 20, TY + 50)-(LX + 65, TY + 74), _RGB(70, 70, 70), B
LINE (LX + 20, TY + 50)-(LX + 20, TY + 74), _RGB(250, 250, 250)
LINE (LX + 20, TY + 50)-(LX + 65, TY + 50), _RGB(250, 250, 250)
NEXT LX
NEXT TY
' ----------- Put Lables on buttons
' --- Row 1
_PRINTSTRING (28, 55), "SqrR": _PRINTSTRING (97, 55), "%"
_PRINTSTRING (145, 55), CHR$(0) + CHR$(26): _PRINTSTRING (192, 55), "Clear"
' --- Row 2
_PRINTSTRING (40, 87), "7": _PRINTSTRING (96, 87), "8"
_PRINTSTRING (150, 88), "9": _PRINTSTRING (200, 87), CHR$(0) + CHR$(246)
' --- Row 3
_PRINTSTRING (40, 117), "4": _PRINTSTRING (96, 117), "5"
_PRINTSTRING (150, 117), "6": _PRINTSTRING (208, 117), "x"
' --- Row 4
_PRINTSTRING (40, 146), "1": _PRINTSTRING (96, 146), "2"
_PRINTSTRING (150, 146), "3": _PRINTSTRING (208, 146), "-"
' --- Row 5
_PRINTSTRING (40, 176), "0": _PRINTSTRING (96, 176), "."
_PRINTSTRING (150, 176), "=": _PRINTSTRING (208, 176), "+"
END SUB
'------------------- MousePoll ---------------
SUB MousePoll ()
_DELAY .4
DO WHILE _MOUSEINPUT
mbl% = _MOUSEBUTTON(1): mbr% = _MOUSEBUTTON(2) ': mx% = _MOUSEX: my% = _MOUSEY:
LOOP
END SUB
«
Last Edit: March 14, 2011, 02:45:27 pm by Dustie Bear
»
Report Spam
Logged
Dustie Bear
Full Member
Posts: 115
Re: My calculator,Math useing input,loops, and some choices
«
Reply #14
on:
March 14, 2011, 06:39:16 pm »
That sounds great about changing the size!
I agree, full screen was never my favorite either.
but it was an option if we had to.
Since I dont know how to do what you suggest, That will have to be your project.
and I like that idea.
I can help with part of it if you tell me what to do. That is if its going to
be a big project.
I think all the functions are working correctly now and the mouse
doesnt over react anymore.
We can remove all those Const's for keypresses at the top of the program too.
When I first started writing it I was going to use keypresses then decided, why not
use the mouse.
So they can be deleted, I just never got around to it. LOL Actualy I forgot I had put them there. LOL
Dustie
«
Last Edit: March 14, 2011, 10:48:16 pm by Dustie Bear
»
Report Spam
Logged
Pages: [
1
]
2
3
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> Useful Information ,Rules,FAQs,LINKS,etc.
===> INTRODUCE Yourself
=> General QB64 Forum
=> MS DOS, FREE DOS, ANY DOS
-----------------------------
QB64 lessons and tutorials,Games
-----------------------------
=> Lesson Disussion
=> Weekly Lesson
=> Games
-----------------------------
TUTORIALS
-----------------------------
=> QB64 Tutorials
=> Text Adventure
=> QBasic Tutorials
=> Other Tutorials
-----------------------------
UNSEENS GDK+SFML Librarys
-----------------------------
=> Discussions on GDK+SFML
=> GDK+SFML Demos, and projects
-----------------------------
DEMOS
-----------------------------
=> Working QB64 Demos
=> QB64 Games
=> QB64 Programs You Are Proud Of.
=> Function + SUB Club
-----------------------------
OFF TOPIC,and Off The wall
-----------------------------
=> OffTopic and Off the Wall
Powered by
EzPortal
Loading...