layer Posted December 24, 2004 Posted December 24, 2004 (edited) dont be fooled by the amount of code, that's just functions, but then again those are needed to run the program, but some of the functions are just to allow the calculator and conversions windows to be open at teh same time...expandcollapse popup; Script generated by AutoBuilder 0.5 Prototype (controls [button's, edit's, etc] were created by AutoBuilder) #include <GuiConstants.au3> Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("AuCalculator v. 3.5", 392, 316,(@DesktopWidth-392)/2, (@DesktopHeight-316)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) Global $Button_1 = GuiCtrlCreateButton("1", 70, 70, 40, 30) Global $Edit_23 = GuiCtrlCreateEdit("", 70, 25, 180, 20, $ES_AUTOHSCROLL) Global $Button_3 = GuiCtrlCreateButton("2", 140, 70, 40, 30) Global $Button_4 = GuiCtrlCreateButton("3", 210, 70, 40, 30) Global $Button_5 = GuiCtrlCreateButton("4", 70, 120, 40, 30) Global $Button_6 = GuiCtrlCreateButton("5", 140, 120, 40, 30) Global $Button_7 = GuiCtrlCreateButton("6", 210, 120, 40, 30) Global $Button_8 = GuiCtrlCreateButton("Clear", 280, 20, 40, 30) Global $Button_9 = GuiCtrlCreateButton("7", 70, 170, 40, 30) Global $Button_10 = GuiCtrlCreateButton("8", 140, 170, 40, 30) Global $Button_11 = GuiCtrlCreateButton("9", 210, 170, 40, 30) Global $Button_12 = GuiCtrlCreateButton("Equals =", 130, 250, 60, 40) Global $Button_13 = GuiCtrlCreateButton("Add +", 40, 210, 60, 40) Global $Button_14 = GuiCtrlCreateButton("Subtract -", 210, 210, 60, 40) Global $Button_15 = GuiCtrlCreateButton("Multiply *", 40, 260, 60, 30) Global $Button_16 = GuiCtrlCreateButton("0", 140, 210, 40, 30) Global $Button_17 = GuiCtrlCreateButton("Divide /", 210, 260, 60, 30) Global $Button_28 = GuiCtrlCreateButton('Decimal "."', 280, 70, 60, 40) Global $Menu_29= GUICtrlCreateMenu ("Switch to...") Global $MenuItem_30= GUICtrlCreateMenuItem ("Conversions", $Menu_29) GLobal $Button_31= GUICtrlCreateButton ("Square Root", 280, 120) GuiSetState() Func Conversions () #include <GUIConstants.au3> GUICreate ("Conversions") GUISetState (@SW_SHOW) $b= GUICtrlCreateButton ("Convert", 5, 30) $l= GUICtrlCreateLabel ("Feet to inches:", 1, 1) $i= GUICtrlCreateInput ("Feet here", 55, 33) $b2= GUICtrlCreateButton ("Convert", 5, 100,) $l2= GUICtrlCreateLabel ("Inches to feet:", 1, 75) $i2= GUICtrlCreateInput ("Inches here", 54, 103) $b3= GUICtrlCreateButton ("Convert", 5, 170) $l3= GUICtrlCreateLabel ("Ounces to pounds:", 1, 145) $i3= GUICtrlCreateInput ("Ounces here", 53, 173, 0x0080) $b4= GUICtrlCreateButton ("Convert", 5, 233) $l4= GUICtrlCreateLabel ("Pounds to ounces:", 1, 210) $i4= GUICtrlCreateInput ("Pounds to ounces", 53, 235) While 1 $get= GUIGetMsg () $tmpread2= GUIRead ($i2) $tmpread= GUIRead ($i) Select Case $get= $GUI_EVENT_CLOSE Calc () ExitLoop Case $get= $b $tmpread= GUIRead ($i) $fee2in= Number ($tmpread*12) MsgBox (0, "Result", $fee2in & " Inches") Case $get= $b2 If $tmpread2= 12 Then MsgBox (0, "Result", "1 Foot") Else $in2fee= Number ($tmpread2/12) MsgBox (0, "Result", $in2fee & " Feet") EndIf Case $get= $b3 $tmpread= GUIRead ($i3) If $tmpread= 16 Then MsgBox (0, "Result", "1 Pound") Else $tmpread= GUIRead ($i3) $oz2lb= Number ($tmpread/16) MsgBox (0, "Result", $oz2lb & " Pounds") EndIf Case $get= $b4 $tmpread= GUIRead ($i4) $lb2oz= Number ($tmpread*16) MsgBox (0, "Result", $lb2oz & " Ounces") EndSelect WEnd EndFunc Func Calc () #include <GuiConstants.au3> Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("AuCalculator v. 3.5", 392, 316,(@DesktopWidth-392)/2, (@DesktopHeight-316)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) Global $Button_1 = GuiCtrlCreateButton("1", 70, 70, 40, 30) Global $Edit_23 = GuiCtrlCreateEdit("", 70, 25, 180, 20, $ES_AUTOHSCROLL) Global $Button_3 = GuiCtrlCreateButton("2", 140, 70, 40, 30) Global $Button_4 = GuiCtrlCreateButton("3", 210, 70, 40, 30) Global $Button_5 = GuiCtrlCreateButton("4", 70, 120, 40, 30) Global $Button_6 = GuiCtrlCreateButton("5", 140, 120, 40, 30) Global $Button_7 = GuiCtrlCreateButton("6", 210, 120, 40, 30) Global $Button_8 = GuiCtrlCreateButton("Clear", 280, 20, 40, 30) Global $Button_9 = GuiCtrlCreateButton("7", 70, 170, 40, 30) Global $Button_10 = GuiCtrlCreateButton("8", 140, 170, 40, 30) Global $Button_11 = GuiCtrlCreateButton("9", 210, 170, 40, 30) Global $Button_12 = GuiCtrlCreateButton("Equals =", 130, 250, 60, 40) Global $Button_13 = GuiCtrlCreateButton("Add +", 40, 210, 60, 40) Global $Button_14 = GuiCtrlCreateButton("Subtract -", 210, 210, 60, 40) Global $Button_15 = GuiCtrlCreateButton("Multiply *", 40, 260, 60, 30) Global $Button_16 = GuiCtrlCreateButton("0", 140, 210, 40, 30) Global $Button_17 = GuiCtrlCreateButton("Divide /", 210, 260, 60, 30) Global $Button_28 = GuiCtrlCreateButton('Decimal "."', 280, 70, 60, 40) Global $Menu_29= GUICtrlCreateMenu ("Switch to...") Global $MenuItem_30= GUICtrlCreateMenuItem ("Conversions", $Menu_29) GuiSetState() While 1 $get = GuiGetMsg() Select Case $get = -3;Should really use $GUI_EVENT_CLOSE ExitLoop Case $get= $button_1 GUICtrlSetData ($edit_23, "1", 1) Case $get= $button_3 GUICtrlSetData ($edit_23, "2", 1) Case $get= $button_4 GUICtrlSetData ($edit_23, "3", 1) Case $get= $button_5 GUICtrlSetData ($edit_23, "4", 1) Case $get= $button_6 GUICtrlSetData ($edit_23, "5", 1) Case $get= $button_7 GUICtrlSetData ($edit_23, "6", 1) Case $get= $button_9 GUICtrlSetData ($edit_23, "7", 1) Case $get= $button_10 GUICtrlSetData ($edit_23, "8", 1) Case $get= $button_11 GUICtrlSetData ($edit_23, "9", 1) Case $get= $button_16 GUICtrlSetData ($edit_23, "0", 1) Case $get=$button_13 GUICtrlSetData ($edit_23, "+", 1) Case $get=$button_14 GUICtrlSetData ($edit_23, "-", 1) Case $get=$button_12 $sum = GUIRead ($edit_23) $result = _CalcRPN($sum) GUICtrlSetData ($edit_23, "= ", 1) GUICtrlSetData ($edit_23, $result, 1) Case $get=$button_17 GUICtrlSetData ($edit_23, "/", 1) Case $get=$button_15 GUICtrlSetData ($edit_23, "*", 1) Case $get= $MenuItem_30 Conversions () ExitLoop Case $get= $Button_8 GUICtrlDelete ($edit_23) Global $Edit_23 = GuiCtrlCreateEdit("", 70, 25, 180, 20, $ES_AUTOHSCROLL) Case $get= $Button_28 GUICtrlSetData ($Edit_23, ".", 1) EndSelect WEnd Exit EndFunc Func _PopStack(ByRef $vaStack) Local $vValue If Not IsArray($vaStack) Then SetError(1) ; invalid stack Else $vValue = $vaStack[UBound($vaStack)-1] If UBound($vaStack) > 1 Then ReDim $vaStack[UBound($vaStack)-1] $vaStack[0] = UBound($vaStack)-1 Else $vaStack[0] = 0 SetError(2) ; empty stack EndIf EndIf Return $vValue EndFunc Func _CalcRPN($sInfix) Local $sOps = "+-*/^" Local $vaStack1[1] Local $vaStack2[1] Local $sChar Local $sNextChar Local $n, $i Local $nOperand1 Local $nOperand2 Local $sOp $sInfix = StringStripWS($sInfix, 8) For $n = 1 To StringLen($sInfix) $sChar = StringMid($sInfix, $n, 1) If (Asc($sChar) >= 48 And Asc($sChar) <= 57) Or $sChar = "." Then ; if character is a digit or a dot then get full number While $n < StringLen($sInfix) $sNextChar = StringMid($sInfix, $n+1, 1) If (Asc($sNextChar) >= 48 And Asc($sNextChar) <= 57) Or $sNextChar = "." Then $sChar = $sChar & $sNextChar $n = $n+1 Else ExitLoop EndIf WEnd ; push number into stack1 _PushStack($vaStack1, Number($sChar)) ElseIf $sChar = "(" Then ; push left bracket into stack2 _PushStack($vaStack2, $sChar) ElseIf $sChar = ")" Then ; pop operators from stack2 and push them into stack1 until left bracket While $vaStack2[0] > 0 And $vaStack2[$vaStack2[0]] <> "(" _PushStack($vaStack1, _PopStack($vaStack2)) WEnd ; pop left bracket from stack2 If $vaStack2[$vaStack2[0]] = "(" Then _PopStack($vaStack2) Else ; get position of operator. Higher position = higher precedence $i = StringInStr($sOps, $sChar) If $i > 0 Then ; pop higher precedence operators from stack2 and push them into stack1 While $vaStack2[0] > 0 And StringInStr($sOps, $vaStack2[$vaStack2[0]]) >= $i _PushStack($vaStack1, _PopStack($vaStack2)) WEnd ; push current operator into stack2 _PushStack($vaStack2, $sChar) EndIf EndIf Next ; pop remaining operators from stack2 and push them into stack1 While $vaStack2[0] > 0 _PushStack($vaStack1, _PopStack($vaStack2)) WEnd ; clear stack2 Redim $vaStack2[1] ; copy stack1 to stack2 so the stack order is reversed For $n = $vaStack1[0] To 1 Step -1 _PushStack($vaStack2, $vaStack1[$n]) Next ; clear stack1 ReDim $vaStack1[1] While $vaStack2[0] > 0 If StringInStr($sOps, $vaStack2[$vaStack2[0]]) Then ; if top item is an operator then pop the operator $sOp = _PopStack($vaStack2) ; pop the second operand $nOperand2 = _PopStack($vaStack1) ; pop the first operand $nOperand1 = _PopStack($vaStack1) ; perform the calculation and push the result into stack1 Select Case $sOp = "+" _PushStack($vaStack1, $nOperand1+$nOperand2) Case $sOp = "-" _PushStack($vaStack1, $nOperand1-$nOperand2) Case $sOp = "*" _PushStack($vaStack1, $nOperand1*$nOperand2) Case $sOp = "/" _PushStack($vaStack1, $nOperand1/$nOperand2) Case $sOp = "^" _PushStack($vaStack1, $nOperand1^$nOperand2) EndSelect Else ; pop number from stack2 and push into stack1 _PushStack($vaStack1, _PopStack($vaStack2)) EndIf WEnd ; the last remaining item in stack1 is the final result Return _PopStack($vaStack1) EndFunc Func _PushStack(ByRef $vaStack, $vValue) If Not IsArray($vaStack) Then SetError(1) ; invalid stack Return 0 EndIf ReDim $vaStack[UBound($vaStack)+1] $vaStack[UBound($vaStack)-1] = $vValue $vaStack[0] = UBound($vaStack)-1 Return 1 EndFunc While 1 $get = GuiGetMsg() Select Case $get = -3;Should really use $GUI_EVENT_CLOSE ExitLoop Case $get= $button_1 GUICtrlSetData ($edit_23, "1", 1) Case $get= $button_3 GUICtrlSetData ($edit_23, "2", 1) Case $get= $button_4 GUICtrlSetData ($edit_23, "3", 1) Case $get= $button_5 GUICtrlSetData ($edit_23, "4", 1) Case $get= $button_6 GUICtrlSetData ($edit_23, "5", 1) Case $get= $button_7 GUICtrlSetData ($edit_23, "6", 1) Case $get= $button_9 GUICtrlSetData ($edit_23, "7", 1) Case $get= $button_10 GUICtrlSetData ($edit_23, "8", 1) Case $get= $button_11 GUICtrlSetData ($edit_23, "9", 1) Case $get= $button_16 GUICtrlSetData ($edit_23, "0", 1) Case $get=$button_13 GUICtrlSetData ($edit_23, "+", 1) Case $get=$button_14 GUICtrlSetData ($edit_23, "-", 1) Case $get=$button_12 $sum = GUIRead ($edit_23) $result = _CalcRPN($sum) GUICtrlSetData ($edit_23, "= ", 1) GUICtrlSetData ($edit_23, $result, 1) Case $get=$button_17 GUICtrlSetData ($edit_23, "/", 1) Case $get=$button_15 GUICtrlSetData ($edit_23, "*", 1) Case $get= $MenuItem_30 Conversions () ExitLoop Case $get= $Button_8 GUICtrlDelete ($edit_23) Global $Edit_23 = GuiCtrlCreateEdit("", 70, 25, 180, 20, $ES_AUTOHSCROLL) Case $get= $Button_28 GUICtrlSetData ($Edit_23, ".", 1) Case $get= $Button_31 $getnum= GUIRead ($edit_23) $sqrtnum= Sqrt ($getnum) GUICtrlSetData ($edit_23, " Square root is: ", 1) GUICtrlSetData ($edit_23, $sqrtnum, 1) EndSelect WEnd Exitcomments, suggestions, questions, bugs? report em' heretanks a million EDIT: i added sqare root!! i want more functions to add!!! on my to do list is...:-add scince calculator!!! w00t Edited December 24, 2004 by layer FootbaG
themax90 Posted December 24, 2004 Posted December 24, 2004 (edited) Great man, I LOVE IT!!! The feel of microsofts calc in easlier versions.I have a few comments. When you switch to conversions, have it hide the First calc window and make the conversions window have the button to switch back to normal calc (eg: hide conversions window and show calc window) Also, just a suggestion, upgrade to 3.0.133(if you want) because I had to change a few things. GUIRead has been changed to GUICtrlRead and SendMsg to CtrlSendMsg. I have attached the 3.0.133 version for all those who use that. Sorry if I am pirating your code but, I just had to update it. Love the calc!!!!Conversion RemovedAgent Smith Edited December 29, 2004 by Agent Smith
SlimShady Posted December 24, 2004 Posted December 24, 2004 It's great.Two bugs:- You can't close the conversions window- When you click on the equal button while the cursor is in the middle of the expression... see for yourself
SumTingWong Posted December 24, 2004 Posted December 24, 2004 You can pass square roots to the _CalcRPN UDF as follows: ; Example using AutoIT $n = Sqrt(9) MsgBox(4096,'debug:' , '$n:' & $n);### Debug MSGBOX ; Example using RPN UDF $n = _CalcRPN("9^(1/2)") MsgBox(4096,'debug:' , '$n:' & $n);### Debug MSGBOX
layer Posted December 24, 2004 Author Posted December 24, 2004 tanks guys glad you like it... but i know about that conversion window and teh calculator window about being open at teh same time, im still figuring out how to fix it... P.S: agent-smith, thats ok, it's open source FootbaG
layer Posted December 24, 2004 Author Posted December 24, 2004 where can i get 3.0.133? it's not on teh beta page!! FootbaG
phillip123adams Posted December 24, 2004 Posted December 24, 2004 where can i get 3.0.133? it's not on teh beta page!! <{POST_SNAPBACK}>I think you mean v3.0.103.133. That's the unstable beta dated 23-Dec-2004. Phillip
themax90 Posted December 24, 2004 Posted December 24, 2004 Yeah thats what I mean, sorry.You can gget it from here:http://www.autoitscript.com/autoit3/files/unstable/autoit/Sorry about that.
MHz Posted December 24, 2004 Posted December 24, 2004 (edited) I think you mean v3.0.103.133. That's the unstable beta dated 23-Dec-2004.<{POST_SNAPBACK}>I think this is right. Buttanks guysLayer, this is wrong, proper english would be nice, thanks. For maybe a worldwide audience, may not know the difference, for what you mean.Merry Christmas.Edit: sorry, xmas to christmas. to show good meaning. Edited December 24, 2004 by MHz
layer Posted December 24, 2004 Author Posted December 24, 2004 yeah, thanks, i appreciate the comments, i just wanted to change my typing style... but now I know that I should type like this because some people may not know what it means... it's sort of weird how I can type like: "Hello, how are you today? I am good, and you?" and i can still type as fast as i type with bad english as fast as i type with good but i was just trying to see different ways of typing.. FootbaG
Administrators Jon Posted December 24, 2004 Administrators Posted December 24, 2004 I think this is right. ButLayer, this is wrong, proper english would be nice, thanks. For maybe a worldwide audience, may not know the difference, for what you mean.Merry Christmas.Edit: sorry, xmas to christmas. to show good meaning. I read an article today about people moaning about the Xmas abbreviation and apparently its been in use for at least 1000 years. http://news.bbc.co.uk/1/hi/magazine/4097755.stm Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Josbe Posted December 24, 2004 Posted December 24, 2004 I read an article today about people moaning about the Xmas abbreviation and apparently its been in use for at least 1000 years. http://news.bbc.co.uk/1/hi/magazine/4097755.stm<{POST_SNAPBACK}>Very interesting. • AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta
MHz Posted December 24, 2004 Posted December 24, 2004 Sorry, I have nothing against shorthand, just so long as everyone can understand. teh and the are different though? No wishes to offend or scutinize. Have a nice day.
this-is-me Posted December 24, 2004 Posted December 24, 2004 That article also references XPmas - ~1021 B.C. To sound a little like some other posters, I wonder if this was a Microsoft Conspiracy... Who else would I be?
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