mymusicmanager Posted October 28, 2013 Share Posted October 28, 2013 The calculator does not work the way I want it to. It appears that when I type for instance 55 + 2, it turns out to be 110 (55 * 2) Any help / suggestions is well accepted expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "Math.au3" Global $Memory = 0 Global $TempMem = 0 Global $DoPlus = False Global $DoMinus = False Global $DoDivide= False Global $DoMultiply = False Global $Button[11] #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Calculator", 347, 357, 192, 124) $Input1 = GUICtrlCreateInput("", 10, 20, 220, 20) $Button[1] = GUICtrlCreateButton("1", 56, 40, 49, 33) $Button[2] = GUICtrlCreateButton("2", 120, 40, 49, 33) $Button[3] = GUICtrlCreateButton("3", 184, 40, 49, 33) $Button[4] = GUICtrlCreateButton("4", 56, 88, 49, 33) $Button[5] = GUICtrlCreateButton("5", 120, 88, 49, 33) $Button[6] = GUICtrlCreateButton("6", 184, 88, 49, 33) $Button[7] = GUICtrlCreateButton("7", 56, 136, 49, 33) $Button[8] = GUICtrlCreateButton("8", 120, 136, 49, 33) $Button[9]= GUICtrlCreateButton("9", 184, 136, 49, 33) $Button[0] = GUICtrlCreateButton("0", 120, 184, 49, 33) $Button11 = GUICtrlCreateButton("Flush Memory", 30, 184, 76, 33) $Button12 = GUICtrlCreateButton("+", 184, 184, 49, 33) $Button13 = GUICtrlCreateButton("=", 248, 40, 49, 33) $Button14 = GUICtrlCreateButton("/", 248, 136, 49, 33) $Button15 = GUICtrlCreateButton("*", 248, 88, 49, 33) $Button16 = GUICtrlCreateButton("-", 248, 184, 49, 33) $Label1 = GUICtrlCreateLabel("Output = ", 24, 294, 312, 17) $label2 = GUICtrlCreateLabel ("Current number(s): ", 24, 260, 312, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $Msg = GUIGetMsg() for $lNum = 0 To 9 If $Msg = $Button[$lNum] Then GUICtrlSetData( $Input1, GUICtrlRead( $Input1 ) & $lNum ) Next Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Button11 _ClearID($Input1) Case $Button12 GUICtrlSetData($input1, GUICtrlRead($input1) & ("+")) $TempMem = GUICtrlRead($input1) $Memory=$TempMem $DoPlus=True Case $Button13 If $DoPlus=True Then Calculate(1) If $DoDivide=True Then Calculate(2) If $DoMinus=True Then Calculate(3) if $DoMultiply=True Then Calculate(4) Case $Button14 GUICtrlSetData($input1, GUICtrlRead($input1) & ("/")) $TempMem = GUICtrlRead($input1) $Memory=$TempMem $DoDivide=True Case $Button15 GUICtrlSetData($input1, GUICtrlRead($input1) & ("*")) $TempMem = GUICtrlRead($input1) $Memory=$TempMem $DoMultiply=True Case $Button16 GUICtrlSetData($input1, GUICtrlRead($input1) & ("-")) $TempMem = GUICtrlRead($input1) $Memory=$TempMem $DoMinus=True EndSwitch WEnd Func _ClearID( $aID ) GUICtrlSetData( $aID, "" ) GUICtrlSetState( $aID, $GUI_FOCUS ) EndFunc Func Calculate($CalcVar) If $CalcVar=1 Then $Memory=$Memory+$TempMem If $CalcVar=2 Then $Memory=$Memory/$TempMem if $CalcVar=3 Then $Memory=$Memory-$TempMem if $CalcVar=4 then $Memory=$Memory*$TempMem GUICtrlSetData ($input1, " "&$Memory) $DoPlus=False $DoDivide=False $DoMinus=False $DoMultiply=False EndFunc Thank you in advance Link to comment Share on other sites More sharing options...
water Posted October 28, 2013 Share Posted October 28, 2013 The result is always twice the value of the first operand because you don#t read the second operand when "=" is clicked. $TempMem always has the value of operand 1. But should be operand 2. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mymusicmanager Posted October 28, 2013 Author Share Posted October 28, 2013 Any way to explain that easier / more in.depth? Link to comment Share on other sites More sharing options...
water Posted October 28, 2013 Share Posted October 28, 2013 Add ConsoleWrite($CalcVar & "-" & $Memory & "-" & $TempMem & @LF) as first line into function Calculate and you will see that both variables always have the same value. When adding 12+2 $Memory should be 12 and $TempMem should be 2 but you will see that $TempMem is 12 as well, which is wrong. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mymusicmanager Posted October 28, 2013 Author Share Posted October 28, 2013 I added your line to the top of the Calculate function, but 9 * 2 is still 81 Your line made the console say how it calculated the line, which showed "4-9*-9*" Link to comment Share on other sites More sharing options...
water Posted October 28, 2013 Share Posted October 28, 2013 My line doesn't solve your problem - it simply shows that both variables have the same value. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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