layer Posted December 24, 2004 Share Posted December 24, 2004 hey guys, i added a greater then, less then, or equal to function to my calculator, here ya go! 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) Global $Menu_item32= GUICtrlCreateMenuItem ("Greater then... etc", $menu_29) 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 = GUICtrlRead ($i2) $tmpread = GUICtrlRead ($i) Select Case $get = $GUI_EVENT_CLOSE Calc() ExitLoop Case $get = $b $tmpread = GUICtrlRead ($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 = GUICtrlRead ($i3) If $tmpread = 16 Then MsgBox(0, "Result", "1 Pound") Else $tmpread = GUICtrlRead ($i3) $oz2lb = Number($tmpread / 16) MsgBox(0, "Result", $oz2lb & " Pounds") EndIf Case $get = $b4 $tmpread = GUICtrlRead ($i4) $lb2oz = Number($tmpread * 16) MsgBox(0, "Result", $lb2oz & " Ounces") EndSelect Wend EndFunc ;==>Conversions 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 = GUICtrlRead ($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 ;==>Calc 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 ;==>_PopStack 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 ;==>_CalcRPN 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 ;==>_PushStack Func Greaterthen () #include <GUIConstants.au3> GUICreate ("Greater then, less then, or equal too", 300, 300) GUISetState () $edit2= GUICtrlCreateEdit ("", 115, 50, 50, 20, $ES_AUTOHSCROLL) $edit= GUICtrlCreateEdit ("", 45, 50, 50, 20, $ES_AUTOHSCROLL) $button= GUICtrlCreateButton ("<,>, or =", 10, 10) $label= GUICtrlCreateLabel ("Use '/' marks for fractions. Ex [1/2].", 45, 180) $label2= GUICtrlCreateLabel ("Use % signs as percentage. Ex [100%].", 45, 200) $biginput= GUICtrlCreateInput ("", 45, 75, 100, 20, 0x0800) $littleinput= GUICtrlCreateInput ("", 45, 100, 100, 20, 0x0800) $maxlabel= GUICtrlCreateLabel ("Max #", 5, 75) $minlabel= GUICtrlCreateLabel ("Min #", 5, 100) $label3= GUICtrlCreateLabel ("Use . marks for decimals. Ex [10.5].", 45, 220) $read= GUICtrlRead ($edit) $read2= GUICtrlRead ($edit2) $findmin= _Min ($read, $read2) $findmax= _Max ($read, $read2) While 1 $get=GUIGetMsg () Select Case $get= -3 Exit Case $get= $button $read= GUICtrlRead ($edit) $read2= GUICtrlRead ($edit2) If $read=$read2 Then $equal= _Equal ($edit, $edit2) GUICtrlDelete ($biginput) $biginput= GUICtrlCreateInput ("", 45, 75, 100, 20, 0x0800) GUICtrlDelete ($littleinput) $littleinput= GUICtrlCreateInput ("", 45, 100, 100, 20, 0x0800) GUICtrlSetData ($biginput, "=", 1) GUICtrlSetData ($littleinput, "=", 1) Else $findmax= _Max ($read, $read2) GUICtrlDelete ($biginput) $biginput= GUICtrlCreateInput ("", 45, 75, 100, 20, 0x0800) GUICtrlSetData ($biginput, $findmax, 1) $findmin= _Min ($read, $read2) GUICtrlDelete ($littleinput) $littleinput= GUICtrlCreateInput ("", 45, 100, 100, 20, 0x0800) GUICtrlSetData ($littleinput, $findmin, 1) EndIf EndSelect WEnd EndFunc Func _Max( $edit, $edit2 ) If $edit > $edit2 Then Return $edit Else Return $edit2 EndIf EndFunc Func _Min( $edit, $edit2 ) If $edit > $edit2 Then Return $edit2 Else Return $edit EndIf EndFunc Func _Equal( $edit, $edit2 ) If $edit=$edit2 then Return '=' EndIf 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 = GUICtrlRead ($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 = GUICtrlRead ($Edit_23) $sqrtnum = Sqrt($getnum) GUICtrlSetData($Edit_23, " Square root is: ", 1) GUICtrlSetData($Edit_23, $sqrtnum, 1) Case $get= $menu_item32 Greaterthen () EndSelect Wend Exit any bugs, comments, suggestions, or questions, please post em' here!! thanks!! FootbaG Link to comment Share on other sites More sharing options...
themax90 Posted December 24, 2004 Share Posted December 24, 2004 whoa layer u workin more then me LOL, and I anm puttin in like 5 hours a day Link to comment Share on other sites More sharing options...
layer Posted December 24, 2004 Author Share Posted December 24, 2004 lol, thanks. by the way... i love your instant messenger!!! w00t! FootbaG Link to comment Share on other sites More sharing options...
Valik Posted December 25, 2004 Share Posted December 25, 2004 Just two suggestions about your release method... Could the script be put as an attachment in the top post, and could all the updates be contained in a single thread (Until that thread gets large and unwieldy). Then with each update, the first post is updated with a new attachment. Right now, I see two threads on this script sitting next to each other. Keeping it in one thread cuts down on forum clutter and makes it easier to find the latest version and also find all discussion and evolution of a script. Link to comment Share on other sites More sharing options...
layer Posted December 25, 2004 Author Share Posted December 25, 2004 sure good idea, thanks valik FootbaG 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