dantay9 Posted January 22, 2009 Share Posted January 22, 2009 I came across this great script from Valuater and I loved it. I am trying to make a calculator using the script and it was working great until I started to make the functions. I don't know how to find out if a button is pressed using that script. Can anyone help me? expandcollapse popup#include <EditConstants.au3> #include <WindowsConstants.au3> #include <GuiConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <XSkin.au3> Global $C Global $D Global $E Opt("GUIOnEventMode", 1) $skins = @ScriptDir & "\Skins\red-black" $Calculator = XSkinGUICreate("Calculator", 255, 265, $skins) $ExitButton = XSkinButton("X", 330, 7, 16, 16, "Close") $MinimizeButton = XSkinButton("_", 310, 7, 16, 16, "Minimize") GUICtrlSetFont(-1, 9.5, 800) $Input = GUICtrlCreateInput("", 58, 60, 240, 21) GUICtrlSetBkColor(-1, 0xECEBE9) GUICtrlSetLimit(-1, 39) $FractionBar = XSkinButton("Ab/c", 58, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Clear = XSkinButton("Clear", 159, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Fraction_Decimal = XSkinButton("F <> D", 109, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Delete = XSkinButton("Delete", 209, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Percent = XSkinButton("%", 58, 124, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Exponent = XSkinButton("^", 58, 157, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $SqaureRoot = XSkinButton("Sqrt", 58, 190, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $ClearVar = XSkinButton("ClrVar", 58, 223, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Recall = XSkinButton("Recall", 58, 256, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Store = XSkinButton("Sto >", 58, 289, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Tangent = XSkinButton("Tan", 109, 124, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Sine = XSkinButton("Sin", 159, 124, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Cosine = XSkinButton("Cos", 209, 124, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Divide = XSkinButton("/", 259, 124, 41, 30) GUICtrlSetFont(-1, 10, 800, 0, "Arial") $Graph = XSkinButton("Graph", 259, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Multiply = XSkinButton("X", 259, 164, 41, 30) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Subtract = XSkinButton("-", 259, 204, 41, 30) GUICtrlSetFont(-1, 13, 800, 0, "Arial") $Add = XSkinButton("+", 259, 244, 41, 30) GUICtrlSetFont(-1, 12, 400, 0, "Arial") $Equals = XSkinButton("=", 259, 283, 41, 32) GUICtrlSetFont(-1, 12, 800, 0, "Arial") $Seven = XSkinButton("7", 109, 157, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Eight = XSkinButton("8", 159, 157, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Nine = XSkinButton("9", 209, 157, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Four = XSkinButton("4", 109, 199, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Five = XSkinButton("5", 159, 199, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Six = XSkinButton("6", 209, 199, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $One = XSkinButton("1", 109, 241, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Two = XSkinButton("2", 159, 241, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Three = XSkinButton("3", 209, 241, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Decimal = XSkinButton(".", 159, 283, 41, 32) GUICtrlSetFont(-1, 12, 800, 0, "Arial") $Negative = XSkinButton("+/-", 209, 283, 41, 32) GUICtrlSetFont(-1, 10, 800, 0, "Arial") $Zero = XSkinButton("0", 109, 283, 41, 32) GUISetState() While 1 MouseOver() GUISwitch($Calculator) $msg = GUIGetMsg() Switch $msg Case $Zero calc("nul") Case $One calc(1) Case $Two calc("2") Case $Three calc("3") Case $Four calc("4") Case $Five calc("5") Case $Six calc("6") Case $Seven calc("7") Case $Eight calc("8") Case $Nine calc("9") EndSwitch $ResultText = GUICtrlRead($Input) WEnd Func calc($num) Local $3 = 0, $Result = GUICtrlRead($Input), $Test = 0, $string1, $string2, $string3 If $num = 'get' Then If StringInStr($Result, 'A') Then $string1 = StringReplace($Result, 'A', $C) $3 = 1 EndIf If StringInStr($Result, 'B') Then $string2 = StringReplace($string1, 'B', $D) $3 = 2 EndIf If StringInStr($Result, 'C') Then $string3 = StringReplace($string2, 'C', $E) $3 = 3 EndIf If $3 = 1 Then $p = Execute('$string1') ElseIf $3 = 2 Then $p = Execute('$string2') ElseIf $3 = 3 Then $p = Execute('$string3') ElseIf $3 = 0 Then $p = Execute('GUICtrlRead($Input)') EndIf $p = Execute($p) If @error Then If $C = '' Or Not IsDeclared($C) Then GUICtrlSetData($Input, 'Variable has not been declared') $Test = 1 ElseIf $D = '' Or Not IsDeclared($D) Then GUICtrlSetData($Input, 'Variable has not been declared') $Test = 1 ElseIf $E = '' Or Not IsDeclared($E) Then GUICtrlSetData($Input, 'Variable has not been declared') $Test = 1 EndIf If $Test = 0 Then GUICtrlSetData($Input, 'Syntax ERROR') EndIf Else GUICtrlSetData($Input, $p) EndIf ElseIf $num = 'nul' Then GUICtrlSetData($Input, $ResultText & 0) Else GUICtrlSetData($Input, $num) EndIf EndFunc ;==>calc Link to comment Share on other sites More sharing options...
fctd Posted January 22, 2009 Share Posted January 22, 2009 Try this onehttp://www.autoitscript.com/forum/index.ph...p;hl=calculatorOr type in "Windows Run" the command "calc", you get a nice one two. [list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font] Link to comment Share on other sites More sharing options...
dantay9 Posted January 22, 2009 Author Share Posted January 22, 2009 Firstly, I was making this as a learning experience. Second, I don't understand what I am supposed to do. Where do I type in the command? Link to comment Share on other sites More sharing options...
Pain Posted January 22, 2009 Share Posted January 22, 2009 (edited) He meant that you should use the Windows Calculator. This is where you can find what button that has been pressed in your GUI. $msg = GUIGetMsg() Switch $msg Case $Zero calc("nul") ...... But since you have the line Opt("GUIOnEventMode", 1) you should use GUISetOnEvent instead. It's all in the helpfile. I advice you to start with the tutorials and read the helpfile. Edited January 22, 2009 by Pain Link to comment Share on other sites More sharing options...
dantay9 Posted January 22, 2009 Author Share Posted January 22, 2009 That OnEventMode shouldn't have been in there. I tried replacing the calc function with just Run("Notepad.exe"), but that doesn't even work. My problem has to do with not receiving the message at all. I don't know why. Link to comment Share on other sites More sharing options...
Valuater Posted January 22, 2009 Share Posted January 22, 2009 Please note XSkin updatehttp://www.autoitscript.com/forum/index.ph...st&p=633323Your working code...expandcollapse popup#include <EditConstants.au3> #include <WindowsConstants.au3> #include <GuiConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <XSkin.au3> Global $C Global $D Global $E ;Opt("GUIOnEventMode", 1) $skins = @ScriptDir & "\Skins\red-black" $Calculator = XSkinGUICreate("Calculator", 357, 370, $skins) $ExitButton = XSkinButton("X", 330, 7, 16, 16, "Closer") $MinimizeButton = XSkinButton("_", 310, 7, 16, 16, "Minimizer") GUICtrlSetFont(-1, 9.5, 800) $Input = GUICtrlCreateInput("", 58, 60, 240, 21) GUICtrlSetBkColor(-1, 0xECEBE9) GUICtrlSetLimit(-1, 39) $FractionBar = GUICtrlCreateButton("Ab/c", 58, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Clear = XSkinButton("Clear", 159, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Fraction_Decimal = XSkinButton("F <> D", 109, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Delete = XSkinButton("Delete", 209, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Percent = XSkinButton("%", 58, 124, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Exponent = XSkinButton("^", 58, 157, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $SqaureRoot = XSkinButton("Sqrt", 58, 190, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $ClearVar = XSkinButton("ClrVar", 58, 223, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Recall = XSkinButton("Recall", 58, 256, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Store = XSkinButton("Sto >", 58, 289, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Tangent = XSkinButton("Tan", 109, 124, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Sine = XSkinButton("Sin", 159, 124, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Cosine = XSkinButton("Cos", 209, 124, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Divide = XSkinButton("/", 259, 124, 41, 30) GUICtrlSetFont(-1, 10, 800, 0, "Arial") $Graph = XSkinButton("Graph", 259, 91, 41, 26) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Multiply = XSkinButton("X", 259, 164, 41, 30) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Subtract = XSkinButton("-", 259, 204, 41, 30) GUICtrlSetFont(-1, 13, 800, 0, "Arial") $Add = XSkinButton("+", 259, 244, 41, 30) GUICtrlSetFont(-1, 12, 400, 0, "Arial") $Equals = XSkinButton("=", 259, 283, 41, 32) GUICtrlSetFont(-1, 12, 800, 0, "Arial") $Seven = XSkinButton("7", 109, 157, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Eight = XSkinButton("8", 159, 157, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Nine = XSkinButton("9", 209, 157, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Four = XSkinButton("4", 109, 199, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Five = XSkinButton("5", 159, 199, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Six = XSkinButton("6", 209, 199, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $One = XSkinButton("1", 109, 241, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Two = XSkinButton("2", 159, 241, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Three = XSkinButton("3", 209, 241, 41, 32) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $Decimal = XSkinButton(".", 159, 283, 41, 32) GUICtrlSetFont(-1, 12, 800, 0, "Arial") $Negative = XSkinButton("+/-", 209, 283, 41, 32) GUICtrlSetFont(-1, 10, 800, 0, "Arial") $Zero = XSkinButton("0", 109, 283, 41, 32) GUISetState() While 1 $msg = MouseOver() ; for XSkin buttons $msg2 = GUIGetMsg(); for other non-XSkin stuff Switch $msg Case $Zero calc("nul") Case $One calc(1) Case $Two calc("2") Case $Three calc("3") Case $Four calc("4") Case $Five calc("5") Case $Six calc("6") Case $Seven calc("7") Case $Eight calc("8") Case $Nine calc("9") EndSwitch $ResultText = GUICtrlRead($Input) If $msg2 = $FractionBar Then MsgBox(4096, "Test", "You pressed FractionBar ", 3) WEnd Func Closer() Exit EndFunc Func Minimizer() GUISetState(@SW_MINIMIZE) EndFunc Func calc($num) Local $3 = 0, $Result = GUICtrlRead($Input), $Test = 0, $string1, $string2, $string3 If $num = 'get' Then If StringInStr($Result, 'A') Then $string1 = StringReplace($Result, 'A', $C) $3 = 1 EndIf If StringInStr($Result, 'B') Then $string2 = StringReplace($string1, 'B', $D) $3 = 2 EndIf If StringInStr($Result, 'C') Then $string3 = StringReplace($string2, 'C', $E) $3 = 3 EndIf If $3 = 1 Then $p = Execute('$string1') ElseIf $3 = 2 Then $p = Execute('$string2') ElseIf $3 = 3 Then $p = Execute('$string3') ElseIf $3 = 0 Then $p = Execute('GUICtrlRead($Input)') EndIf $p = Execute($p) If @error Then If $C = '' Or Not IsDeclared($C) Then GUICtrlSetData($Input, 'Variable has not been declared') $Test = 1 ElseIf $D = '' Or Not IsDeclared($D) Then GUICtrlSetData($Input, 'Variable has not been declared') $Test = 1 ElseIf $E = '' Or Not IsDeclared($E) Then GUICtrlSetData($Input, 'Variable has not been declared') $Test = 1 EndIf If $Test = 0 Then GUICtrlSetData($Input, 'Syntax ERROR') EndIf Else GUICtrlSetData($Input, $p) EndIf ElseIf $num = 'nul' Then GUICtrlSetData($Input, $ResultText & 0) Else GUICtrlSetData($Input, $num) EndIf EndFunc ;==>calc8) Link to comment Share on other sites More sharing options...
dantay9 Posted January 22, 2009 Author Share Posted January 22, 2009 Thanks for the help Valuater. I love this code. Link to comment Share on other sites More sharing options...
Valuater Posted January 22, 2009 Share Posted January 22, 2009 Thanks for the help Valuater. I love this code.Your welcome!It's just strange that I had not known about this problem before..... Oh well, all is good now... 8) 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