Jump to content

AU3 Calc


ioliver
 Share

Recommended Posts

Thanks for reading my post. Here is the code for AU3 Calc that I wrote today.

; 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

* 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 :D 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 :D

but great work!!! :D

my calc is attacked on the bottom of the page!! :lol::D

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 :idea:

EDIT: you should add a "Clear" button too :idiot:

EDIT: deleted the code off the page cause it was too big and made it an attackment ;)

Edited by layer
FootbaG
Link to comment
Share on other sites

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 :idiot:

calc_v14.au3

Link to comment
Share on other sites

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

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 :D I will have it out shortly :idiot:.

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

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. :idiot:

Edited by IanR
Link to comment
Share on other sites

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

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 :idiot:

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...