Sign in to follow this  
Followers 0
dantay9

Calculator

8 posts in this topic

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?

#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

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites



Try this one

http://www.autoitscript.com/forum/index.ph...p;hl=calculator

Or 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]

Share this post


Link to post
Share on other sites

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?


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Pain

Share this post


Link to post
Share on other sites

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.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

Please note XSkin update

http://www.autoitscript.com/forum/index.ph...st&p=633323

Your working code...

#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  ;==>calc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks for the help Valuater. I love this code.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

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)


NEWHeader1.png

Share this post


Link to post
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
Sign in to follow this  
Followers 0