ioliver Posted January 10, 2005 Share Posted January 10, 2005 Thanks for reading my post. Here is the code for AU3 Calc that I wrote today. expandcollapse popup; AU3 Calc ; ioliver ; January 10, 2005 #Include <GUIConstants.au3> $num1 = "" $num2 = "" GUICreate("AU3 Calc", 135, 175) $display = GUICtrlCreateInput("0", 5, 5, 125) $one = GUICtrlCreateButton("1", 5, 35, 25, 25) $two = GUICtrlCreateButton("2", 35, 35, 25, 25) $three = GUICtrlCreateButton("3", 65, 35, 25, 25) $div = GUICtrlCreateButton("/", 100, 35, 25, 25) $four = GUICtrlCreateButton("4", 5, 70, 25, 25) $five = GUICtrlCreateButton("5", 35, 70, 25, 25) $six = GUICtrlCreateButton("6", 65, 70, 25, 25) $mul = GUICtrlCreateButton("*", 100, 70, 25, 25) $seven = GUICtrlCreateButton("7", 5, 105, 25, 25) $eight = GUICtrlCreateButton("8", 35, 105, 25, 25) $nine = GUICtrlCreateButton("9", 65, 105, 25, 25) $sub = GUICtrlCreateButton("-", 100, 105, 25, 25) $zero = GUICtrlCreateButton("0", 5, 140, 25, 25) $dec = GUICtrlCreateButton(".", 35, 140, 25, 25) $equal = GUICtrlCreateButton("=", 65, 140, 25, 25) $add = GUICtrlCreateButton("+", 100, 140, 25, 25) GUISetState (@SW_SHOW) ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $one $msg = "1" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $two $msg = "2" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $three $msg = "3" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $four $msg = "4" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $five $msg = "5" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $six $msg = "6" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $seven $msg = "7" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $eight $msg = "8" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $nine $msg = "9" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $zero $msg = "0" $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $dec $msg = "." $num = $num & $msg GUICtrlSetData($display, $num) Case $msg = $add If $num1 = "" Then $num1 = GUICtrlRead($display) $num = "" Else $num2 = GUICtrlRead($display) $num = "" EndIf $operator = "+" GUICtrlSetData($display, "0") Case $msg = $sub If $num1 = "" Then $num1 = GUICtrlRead($display) $num = "" Else $num2 = GUICtrlRead($display) $num = "" EndIf $operator = "-" GUICtrlSetData($display, "0") Case $msg = $mul If $num1 = "" Then $num1 = GUICtrlRead($display) $num = "" Else $num2 = GUICtrlRead($display) $num = "" EndIf $operator = "*" GUICtrlSetData($display, "0") Case $msg = $div If $num1 = "" Then $num1 = GUICtrlRead($display) $num = "" Else $num2 = GUICtrlRead($display) $num = "" EndIf $operator = "/" GUICtrlSetData($display, "0") Case $msg = $equal If $num1 = "" Then $num1 = GUICtrlRead($display) $num ="" Else $num2 = GUICtrlRead($display) $num = "" EndIf If $operator = "+" Then $ans = $num1 + $num2 GUICtrlSetData($display, $ans) ElseIf $operator = "-" Then $ans = $num1 - $num2 GUICtrlSetData($display, $ans) ElseIf $operator = "*" Then $ans = $num1 * $num2 GUICtrlSetData($display, $ans) ElseIf $operator = "/" Then $ans = $num1 / $num2 GUICtrlSetData($display, $ans) EndIf EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend Just make sure you have AutoIt v.3 Lastest Unstable, and run the code. * I do remember someone else making a GUI calculator, so this isn't an original idea. I don't remember who it was though. But, I just wanted to try it out, so here my version of the calculator. The code isn't that neat, but let me know what you think. Thanks again for reading, Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF Link to comment Share on other sites More sharing options...
SvenP Posted January 10, 2005 Share Posted January 10, 2005 Very good job Ian, For who's interested. I've another implementation of a calculator in AutoIt 3. See attachment. :-)) Regards, -Svencalculator.au3 Link to comment Share on other sites More sharing options...
Nova Posted January 10, 2005 Share Posted January 10, 2005 (edited) For who's interested. I've another implementation of a calculator in AutoIt 3.LMAO Edited January 10, 2005 by Nova Link to comment Share on other sites More sharing options...
ioliver Posted January 10, 2005 Author Share Posted January 10, 2005 Ok, that is funny. I didn't even realize it was meant to be a joke until Nova's post. I just thought SvenP had forgot the link. Ok, good one. Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF Link to comment Share on other sites More sharing options...
layer Posted January 10, 2005 Share Posted January 10, 2005 (edited) * I do remember someone else making a GUI calculator, so this isn't an original idea. I don't remember who it was though. But, I just wanted to try it out, so here my version of the calculator.that would be me but id have to say i like yours over mine because #1: your code is neater then mine#2: i like how yours is small (i like small GUI windows)#3: i think it's neat how yours does overwrites the number entere, thats profesional but great work!!! my calc is attacked on the bottom of the page!! theres some more too in it, but thats all part of the calculator... but much thanks to the one who made this UDF for the actual function EDIT: you should add a "Clear" button too EDIT: deleted the code off the page cause it was too big and made it an attackment Edited January 10, 2005 by layer FootbaG Link to comment Share on other sites More sharing options...
Lazycat Posted January 11, 2005 Share Posted January 11, 2005 If you interesting, here is also my GUI calculator, so idea is not new, you're right. I'm not posted it before because I think this is not usefull - calc.exe made this work far better, this was mainly internal GUI teach stuff, and it was at begining of past year. Today I'm just changed GUI syntax to get it work. It's unfinished and I'm not plan to finish that at all. But possibly some ideas will be usefull. But be aware - script contain a lot of redundant code calc_v14.au3 Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
ioliver Posted January 11, 2005 Author Share Posted January 11, 2005 Thanks to all for the comments. @Lazycat, great job on your calculator! @Everyone else, thanks for taking the time to look at my calc. Please, don't get me wrong, I'm not trying to replace the Windows Calculator [Run(Calc.exe)], I was just trying to see if I could create on, so that I could familiar with the GUI, and coding in general. Anyway, thanks again, please keep the comments comming. @Layer, I'll try to add a clear button, and fix some problems with the script. Thanks again, Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF Link to comment Share on other sites More sharing options...
JSThePatriot Posted January 11, 2005 Share Posted January 11, 2005 Thanks to all for the comments. @Lazycat, great job on your calculator!@Everyone else, thanks for taking the time to look at my calc. Please, don't get me wrong, I'm not trying to replace the Windows Calculator [Run(Calc.exe)], I was just trying to see if I could create on, so that I could familiar with the GUI, and coding in general. Anyway, thanks again, please keep the comments comming.@Layer, I'll try to add a clear button, and fix some problems with the script.Thanks again,Ian<{POST_SNAPBACK}>I dont like writing "Hello World" programs/scripts. So I prefer to write a Calculator, or (What I am working on) to learn a new lang or set of funtions. That is a secret right now I will have it out shortly .JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
Josbe Posted January 11, 2005 Share Posted January 11, 2005 Yes, Window's calc has more things. But, someone might improveevery thing, for example, to implement the CalcRPN and another things...keep up the good work. @Lazycat: Your calc it looks nice. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
ioliver Posted January 11, 2005 Author Share Posted January 11, 2005 Thanks Josbe. Quick Question: Does anyone know how I can Right-Justify the text in the Display? Thanks, Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF Link to comment Share on other sites More sharing options...
Josbe Posted January 11, 2005 Share Posted January 11, 2005 Thanks Josbe.Quick Question: Does anyone know how I can Right-Justify the text in the Display?Thanks,Ian<{POST_SNAPBACK}>Using EDIT:$display = GUICtrlCreateEdit("0", 5, 5, 125, 20, $ES_RIGHT) AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
ioliver Posted January 11, 2005 Author Share Posted January 11, 2005 Thanks Josbe, works great. Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF Link to comment Share on other sites More sharing options...
IanR Posted January 13, 2005 Share Posted January 13, 2005 (edited) Actually, the feedback I get from users is that the MS Calculator suffers from a serious bug. Most users seem to prefer a hardware-calculator for that reason. Basically, after doing one calculation on the MS product, you MUST explicitly Clear it before using it again. If you don't, your next answer is affected by the previous one, even though Enter (=) was pressed. You don't have to do this on a typical desktop calculator, and it makes the MS calc awkward and error-prone. I think this comes about because MS thought it would be 'clever' to make Enter repeat the last calculation as a timesaver, and didn't think the effects of this through properly. Glad to see this one doesn't suffer that problem. Edited January 13, 2005 by IanR If it says "Made in China" then it just might be made by slave labour... Link to comment Share on other sites More sharing options...
Lazycat Posted January 13, 2005 Share Posted January 13, 2005 Strange, all calculators I have used had the same behaviour, despite sofware or hardware I'm not lucky? Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
JSThePatriot Posted January 13, 2005 Share Posted January 13, 2005 I also have had the same experience with calculators. I always clear out a calc before using it again. JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
tazdev Posted January 13, 2005 Share Posted January 13, 2005 I like it. For newbies like me, reading the code teaches a TON. Even if it is as simple as (run "calc.exe") you learn that you can run programs in a script Good job.Thanks to all for the comments. @Lazycat, great job on your calculator!@Everyone else, thanks for taking the time to look at my calc. Please, don't get me wrong, I'm not trying to replace the Windows Calculator [Run(Calc.exe)], I was just trying to see if I could create on, so that I could familiar with the GUI, and coding in general. Anyway, thanks again, please keep the comments comming.@Layer, I'll try to add a clear button, and fix some problems with the script.Thanks again,Ian<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now