Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculator
#1
I was gonna try taking on the task of creating a QM calculator... I was just curious if this was possible. I don't need an example, but I don't want to go through the trouble of trying to make one, if not possible.
Taking on Quick Macros one day at a time
#2
this is totally possible with dialogs and buttons with 'getwintext ids' etc.
it'll be a great project. especially when you build in all kinds of specialty buttons like Fibonacci number calculation.
A new blog on QM coding and automation.

The Macro Hook
#3
Well I'm glad to hear this is possible. Thanks for letting me know. I'll be sure to try and get this done ASAP. The project begins tomorrow!
Taking on Quick Macros one day at a time
#4
Is it possible, in a dialog, to figure out which button was previously pressed?
Taking on Quick Macros one day at a time
#5
you could crate a variable that would recieve that info and then have every button put in their own id over writing what the last button put there.
A new blog on QM coding and automation.

The Macro Hook
#6
Okay, I'm making a mess.
I got the adding, subtracting, dividing, and multiplying to work, kind of, but you have to hit the button again to get the total, rather then hitting the total button. Is there a way to fix this?

Example: Hit 9 divided by 3 then hit divided key again and it gives you the answer, instead of hitting, 9 divided by 3 equals. Any idea how to fix this?


Function Calculator
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


str controls = "14 24"
str e14 e24
e24="0"
str- a b c d e f
a=""
b=""
c=""
d=""
e=""
f=""
CURRENCY- aa bb cc dd ee ff
aa="1"
bb="1"
cc="1"
dd="1"
ee="1"
ff="1"
int- aaa bbb ccc ddd eee fff
aaa=""
bbb=""
ccc=""
ddd=""
eee=""
fff=""
if(!ShowDialog("Calculator" &Calculator &controls)) ret

;BEGIN DIALOG
;0 "" 0x90CB0A44 0x100 0 0 187 122 "QM Calculator"
;3 Button 0x54032000 0x0 56 30 20 16 "1"
;4 Button 0x54032000 0x0 76 30 20 16 "2"
;5 Button 0x54032000 0x0 96 30 20 16 "3"
;6 Button 0x54032000 0x0 56 46 20 16 "4"
;7 Button 0x54032000 0x0 76 46 20 16 "5"
;8 Button 0x54032000 0x0 96 46 20 16 "6"
;9 Button 0x54032000 0x0 56 62 20 16 "7"
;10 Button 0x54032000 0x0 76 62 20 16 "8"
;11 Button 0x54032000 0x0 96 62 20 16 "9"
;12 Button 0x54032000 0x0 76 78 20 16 "0"
;14 Edit 0x54030082 0x50280 26 10 84 14 ""
;15 Button 0x54032000 0x0 116 30 20 16 "/"
;16 Button 0x54032000 0x0 96 78 20 16 "."
;17 Button 0x54032000 0x0 116 46 20 16 "X"
;18 Button 0x54032000 0x0 116 62 20 16 "-"
;19 Button 0x54032000 0x0 116 78 20 16 "+"
;20 Button 0x54032000 0x0 56 78 20 16 "+/-"
;21 Button 0x54032000 0x0 28 98 42 14 "Backspace"
;22 Button 0x54032000 0x0 70 98 42 14 "Clear"
;23 Button 0x54032000 0x0 112 98 48 14 "Total"
;24 Edit 0x54030082 0x200 110 10 50 14 ""
;13 Button 0x54020007 0x0 16 0 154 118 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030001 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,;top
,case 3
,act id(14 hDlg)
,'1
,case 4
,act id(14 hDlg)
,'2
,case 5
,act id(14 hDlg)
,'3
,case 6
,act id(14 hDlg)
,'4
,case 7
,act id(14 hDlg)
,'5
,case 8
,act id(14 hDlg)
,'6
,case 9
,act id(14 hDlg)
,'7
,case 10
,act id(14 hDlg)
,'8
,case 11
,act id(14 hDlg)
,'9
,case 12
,act id(14 hDlg)
,'0
,case 16
,act id(14 hDlg)
,'.
,case 15
,act id(14 hDlg)
,f.getwintext(id(24 hDlg))
,fff=val(f)
,if fff=0
,,a.getwintext(id(14 hDlg))
,,a.setwintext(id(24 hDlg))
,,b=""
,,b.setwintext(id(14 hDlg))
,,goto top
,else goto divide

,case 17
,f.getwintext(id(24 hDlg))
,fff=val(f)
,if fff=0
,,a.getwintext(id(14 hDlg))
,,a.setwintext(id(24 hDlg))
,,b=""
,,b.setwintext(id(14 hDlg))
,,goto top
,else goto multiply

,case 18
,act id(14 hDlg)
,f.getwintext(id(24 hDlg))
,fff=val(f)
,if fff=0
,,a.getwintext(id(14 hDlg))
,,a.setwintext(id(24 hDlg))
,,b=""
,,b.setwintext(id(14 hDlg))
,,goto top
,else goto subtract

,case 19
,act id(14 hDlg)
,f.getwintext(id(24 hDlg))
,fff=val(f)
,if fff=0
,,a.getwintext(id(14 hDlg))
,,a.setwintext(id(24 hDlg))
,,b=""
,,b.setwintext(id(14 hDlg))
,,goto top
,else goto add

,case 20
,act id(14 hDlg)
,'-
,case 21
,act id(14 hDlg)
,'B
,case 22
,act id(14 hDlg)
,b.setwintext(id(14 hDlg))
,b.setwintext(id(24 hDlg))
,case 23
,goto bottom

,;divide
,a.getwintext(id(14 hDlg))
,f.getwintext(id(24 hDlg))
,aa=a
,bb=f
,cc.div(bb aa)
,d=cc
,d.setwintext(id(24 hDlg))
,b.setwintext(id(14 hDlg))
,out "hello1"
,goto top

,;multiply
,a.getwintext(id(14 hDlg))
,f.getwintext(id(24 hDlg))
,aa=a
,bb=f
,cc.mul(bb aa)
,d=cc
,d.setwintext(id(24 hDlg))
,b.setwintext(id(14 hDlg))
,out "hello2"
,goto top

,;add
,a.getwintext(id(14 hDlg))
,f.getwintext(id(24 hDlg))
,aa=a
,bb=f
,cc.add(bb aa)
,d=cc
,d.setwintext(id(24 hDlg))
,b.setwintext(id(14 hDlg))
,out "hello3"
,goto top

,;subtract
,a.getwintext(id(14 hDlg))
,f.getwintext(id(24 hDlg))
,aa=a
,bb=f
,cc.sub(bb aa)
,d=cc
,d.setwintext(id(24 hDlg))
,b.setwintext(id(14 hDlg))
,out "hello4"
,goto top
,
,;bottom
,a.getwintext(id(24 hDlg))
,aaa=val(a)
,if aaa=0
,,a.getwintext(id(14 hDlg))
,,a.setwintext(id(24 hDlg))
,else
,,out "success"
,'total
,case IDOK
,case IDCANCEL
ret 1
Taking on Quick Macros one day at a time
#7
I would work the number pad like this:

Function Calculator
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 211 92 "QM Calculator"
;3 Button 0x54032000 0x0 10 56 48 14 "1"
;4 Button 0x54032000 0x0 58 56 48 14 "2"
;5 Button 0x54032000 0x0 106 56 48 14 "3"
;6 Button 0x54032000 0x0 10 42 48 14 "4"
;7 Button 0x54032000 0x0 58 42 48 14 "5"
;8 Button 0x54032000 0x0 106 42 48 14 "6"
;9 Button 0x54032000 0x0 10 28 48 14 "7"
;10 Button 0x54032000 0x0 58 28 48 14 "8"
;11 Button 0x54032000 0x0 106 28 48 14 "9"
;12 Button 0x54032000 0x0 156 70 48 14 "."
;13 Button 0x54032000 0x0 156 28 48 14 "+"
;14 Button 0x54032000 0x0 156 42 48 14 "-"
;15 Button 0x54032000 0x0 156 56 48 14 "/"
;16 Button 0x54032000 0x0 10 70 144 14 "="
;17 Edit 0x54030080 0x200 10 12 194 14 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030001 "" "" ""

str controls = "17"
str e17 Number
e17=0
if(!ShowDialog("Calculator" &Calculator &controls)) ret

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,Number="1"
,Numbers Number
,case 4
,Number="2"
,Numbers Number
,case 5
,Number="3"
,Numbers Number
,case 6
,Number="4"
,Numbers Number
,case 7
,Number="5"
,Numbers Number
,case 8
,Number="6"
,Numbers Number
,case 9
,Number="7"
,Numbers Number
,case 10
,Number="8"
,Numbers Number
,case 11
,Number="9"
,Numbers Number
,case 12
,str a.getwintext(id(17 win("QM Calculator" "#32770")))
,Number="."
,a.trim("0123456789")
,if a="."
,,ret
,Numbers Number
,case IDOK
,case IDCANCEL
ret 1

Function Numbers
Code:
Copy      Help
function str&Number
if Number="."
,str a.getwintext(id(17 win("QM Calculator" "#32770")))
,str b.format("%s." a)
,b.setwintext(id(17 win("QM Calculator" "#32770")))ret
else
,str wText.getwintext(id(17 win("QM Calculator" "#32770")))
,if wText="0"
,,wText.ltrim("0")
,str Set.format("%s%s" wText Number)
,Set.setwintext(id(17 win("QM Calculator" "#32770")))
#8
I don't think I'm capable of making this with one edit box, like you have in your example. That's how I originally started, but I had to make some adjustments to mine to get it to work.


But I'm making some progress, I got almost everything working but for some reason I get the error exception, and I'm not sure why?

Example: 4 x 5 total then hit divide and you get error exception.




Function Calculator
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


str controls = "14 24"
str e14 e24
e24="0.00"
str- a b c d e f
a=""
b=""
c=""
d=""
e=""
f=""
CURRENCY- aa bb cc dd ee ff
aa="1"
bb="1"
cc="1"
dd="1"
ee="1"
ff="1"
int- aaa bbb ccc ddd eee fff ggg hhh iii jjj
aaa=""
bbb=""
ccc=""
ddd=""
eee=""
fff=""
ggg=""
hhh=""
iii=""
jjj=""
if(!ShowDialog("Calculator" &Calculator &controls)) ret

;BEGIN DIALOG
;0 "" 0x90CB0A44 0x100 0 0 187 122 "QM Calculator"
;3 Button 0x54032000 0x0 56 30 20 16 "1"
;4 Button 0x54032000 0x0 76 30 20 16 "2"
;5 Button 0x54032000 0x0 96 30 20 16 "3"
;6 Button 0x54032000 0x0 56 46 20 16 "4"
;7 Button 0x54032000 0x0 76 46 20 16 "5"
;8 Button 0x54032000 0x0 96 46 20 16 "6"
;9 Button 0x54032000 0x0 56 62 20 16 "7"
;10 Button 0x54032000 0x0 76 62 20 16 "8"
;11 Button 0x54032000 0x0 96 62 20 16 "9"
;12 Button 0x54032000 0x0 76 78 20 16 "0"
;14 Edit 0x54030082 0x50280 26 10 84 14 ""
;15 Button 0x54032000 0x0 116 30 20 16 "/"
;16 Button 0x54032000 0x0 96 78 20 16 "."
;17 Button 0x54032000 0x0 116 46 20 16 "X"
;18 Button 0x54032000 0x0 116 62 20 16 "-"
;19 Button 0x54032000 0x0 116 78 20 16 "+"
;20 Button 0x54032000 0x0 56 78 20 16 "+/-"
;21 Button 0x54032000 0x0 28 98 42 14 "Backspace"
;22 Button 0x54032000 0x0 70 98 42 14 "Clear"
;23 Button 0x54032000 0x0 112 98 48 14 "Total"
;24 Edit 0x54030082 0x200 110 10 50 14 ""
;13 Button 0x54020007 0x0 16 0 154 118 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030001 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,;top
,case 3
,act id(14 hDlg)
,'1
,case 4
,act id(14 hDlg)
,'2
,case 5
,act id(14 hDlg)
,'3
,case 6
,act id(14 hDlg)
,'4
,case 7
,act id(14 hDlg)
,'5
,case 8
,act id(14 hDlg)
,'6
,case 9
,act id(14 hDlg)
,'7
,case 10
,act id(14 hDlg)
,'8
,case 11
,act id(14 hDlg)
,'9
,case 12
,act id(14 hDlg)
,'0
,case 16
,act id(14 hDlg)
,'.
,case 15
,ggg=1
,act id(14 hDlg)
,f.getwintext(id(24 hDlg))
,fff=val(f)
,if fff=0.00
,,a.getwintext(id(14 hDlg))
,,a.setwintext(id(24 hDlg))
,,b=""
,,b.setwintext(id(14 hDlg))
,,goto top
,else goto bottom

,case 17
,ggg=2
,f.getwintext(id(24 hDlg))
,fff=val(f)
,if fff=0.00
,,a.getwintext(id(14 hDlg))
,,a.setwintext(id(24 hDlg))
,,b=""
,,b.setwintext(id(14 hDlg))
,,goto top
,else goto bottom

,case 18
,ggg=3
,act id(14 hDlg)
,f.getwintext(id(24 hDlg))
,fff=val(f)
,if fff=0.00
,,a.getwintext(id(14 hDlg))
,,a.setwintext(id(24 hDlg))
,,b=""
,,b.setwintext(id(14 hDlg))
,,goto top
,else goto bottom

,case 19
,ggg=4
,act id(14 hDlg)
,f.getwintext(id(24 hDlg))
,fff=val(f)
,if fff=0.00
,,a.getwintext(id(14 hDlg))
,,a.setwintext(id(24 hDlg))
,,b=""
,,b.setwintext(id(14 hDlg))
,,goto top
,else goto bottom

,case 20
,act id(14 hDlg)
,'-
,case 21
,act id(14 hDlg)
,'B
,case 22
,act id(14 hDlg)
,b.setwintext(id(14 hDlg))
,b.setwintext(id(24 hDlg))
,case 23
,goto bottom

,;divide
,a.getwintext(id(14 hDlg))
,f.getwintext(id(24 hDlg))
,aa=val(a)
,bb=val(f)
,cc=0
,cc.div(bb aa);; error exception
,d=cc
,d.setwintext(id(24 hDlg))
,b.setwintext(id(14 hDlg))
,out "hello1"
,goto top

,;multiply
,a.getwintext(id(14 hDlg))
,f.getwintext(id(24 hDlg))
,aa=val(a)
,bb=val(f)
,cc=0
,cc.mul(bb aa);; error exception
,d=cc
,d.setwintext(id(24 hDlg))
,b.setwintext(id(14 hDlg))
,out "hello2"
,goto top

,;subtract
,a.getwintext(id(14 hDlg))
,f.getwintext(id(24 hDlg))
,aa=val(a)
,bb=val(f)
,cc=0
,cc.sub(bb aa)
,d=cc
,d.setwintext(id(24 hDlg))
,b.setwintext(id(14 hDlg))
,out "hello4"
,goto top

,;add
,a.getwintext(id(14 hDlg))
,f.getwintext(id(24 hDlg))
,aa=val(a)
,bb=val(f)
,cc=0
,cc.add(bb aa)
,d=cc
,d.setwintext(id(24 hDlg))
,b.setwintext(id(14 hDlg))
,out "hello3"
,goto top

,
,;bottom
,if ggg=1
,,goto divide
,if ggg=2
,,goto multiply
,if ggg=3
,,goto subtract
,if ggg=4
,,goto add
,else
,,out "success"
,'total
,case IDOK
,case IDCANCEL
ret 1
Taking on Quick Macros one day at a time
#9
I can see that you are doing a very good job on your program and I like it but since I do not get the error can you tell me how you get it?

PS
Are you going to make it so you can do things like 5+5-7 will not equal 7?
#10
Been working on this...I still have to work out the Math functions...there is a lot to consider when it comes to using a calculator...It's got to be very intuitive!

Definately needs more work, but might give some more ideas to work with.

.qml   Calculator.qml (Size: 6.2 KB / Downloads: 129)
#11
Ahh...the logic in the operators section is crazy...

I'm playing around with states to allow operations at certain times and then resetting.

I'll get it, but there are so many considerations. Does anyone have some suggestions?

I feel like I am making an RPN calculator...if anyone has ever used one of those you'll know that it sucks! Reversed Polish Notation!!!

Thanks
#12
TheVig Wrote:Ahh...the logic in the operators section is crazy...

I'm playing around with states to allow operations at certain times and then resetting.

I'll get it, but there are so many considerations. Does anyone have some suggestions?

I feel like I am making an RPN calculator...if anyone has ever used one of those you'll know that it sucks! Reversed Polish Notation!!!

Thanks
I know what you mean, that's what I was saying. It took alot of thinking on how to reset the variables and give the buttons values and whatnot, I should be able to get it to work by the weekend.

Time_Runner Wrote:I can see that you are doing a very good job on your program and I like it but since I do not get the error can you tell me how you get it?

PS
Are you going to make it so you can do things like 5+5-7 will not equal 7?


The problem is that right now, it registers as, 5 --> + transfers it to the right side --> 5 is the next number --> hit minus so it minuses 5 from the previous 5 --> then when you hit 7 it probly subtracts it, equaling -7. I'm trying to fix that.
Taking on Quick Macros one day at a time
#13
Maybe this will be interesting.
Macro
Code:
Copy      Help
str s ss
inp- s "Ex: 2*2. Ex2: (50+30)/4. Ex3: Sqr(20^2 + 10^2)" "Calculator"
mes VbsEval(s)
err mes "error"

VBScript operators:
http://www.google.lt/search?q=site%3Ami ... +operators
VBScript functions:
http://www.google.lt/search?q=site%3Ami ... +functions
#14
If you want Multi Precision Math Library, you can use this: http://digilander.libero.it/foxes/xnumbersdll.zip
#15
That's a big help you two. Thank you very much.
Taking on Quick Macros one day at a time
#16
I figured out a really cool idea. I used the Math function in this to do the order of operations. This works pretty good now. Not all of the functionality of the calculator work, but you can get the idea.

**File Updated in next post**

Hope you all enjoy!

Jimmy Vig
#17
I think I pretty much have it down! Let me know if you can crash it.


.qml   QM Calculator.qml (Size: 9.97 KB / Downloads: 105)

Thanks for the project idea. I learned a lot while making this by having to read forum posts, help text, and just lots of thinking. QM is the best!

I put the the finished calculator in My QM:
http://www.quickmacros.com/forum/showthr...p?tid=2628

Please post any comments/suggestions on my calculator there/

Thanks,
Jimmy Vig
#18
Very nice and very quick but you need to change.

int wM5=id(32 win("QM Calculator" "#32770"))

to

int wM5=id(33 win("QM Calculator" "#32770"))
#19
Well I must say, I feel no need now, to finish mine. Confusedhock:

Great work Jimmy.
Taking on Quick Macros one day at a time


Forum Jump:


Users browsing this thread: 1 Guest(s)