Jump to content
Sign in to follow this  
kjpolker

Performing math functions when reading input

Recommended Posts

kjpolker

So I have an input box with a value in it such as 10, I want the value of 10 to be altered using math the way I want it when it is read, for example of what I am trying to get at here is a sample script that obviously doesn't work but you should get the idea.

#include <GUIConstants.au3>

$Form2 = GUICreate("Form2", 144, 128, 303, 217)
$Input1 = GUICtrlCreateInput("Value", 24, 24, 65, 21)
$Input2 = GUICtrlCreateInput("Value", 24, 48, 65, 21)
$Input3 = GUICtrlCreateInput("Value", 24, 72, 65, 21)
$Input4 = GUICtrlCreateInput("Value", 24, 96, 65, 21)
$Button1 = GUICtrlCreateButton("OK", 96, 23, 33, 25, 0)
$Button2 = GUICtrlCreateButton("OK", 96, 47, 33, 25, 0)
$Button3 = GUICtrlCreateButton("OK", 96, 71, 33, 25, 0)
$Button4 = GUICtrlCreateButton("OK", 96, 95, 33, 25, 0)
$Label1 = GUICtrlCreateLabel("÷", 6, 24, 14, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("x", 7, 48, 11, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("+", 6, 71, 13, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("_", 7, 90, 13, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
                Case $Button1
                        Run("notepad.exe")
                        WinWaitActive("Untitled - Notepad")
                        Send(GUICtrlRead($Input1) & " Divide value by 2 somehow and write that value here")
                Case $Button2
                        Run("notepad.exe")
                        WinWaitActive("Untitled - Notepad")
                        Send(GUICtrlRead($Input1) & " Multiply value by 2 somehow and write that value here")
                Case $Button3
                        Run("notepad.exe")
                        WinWaitActive("Untitled - Notepad")
                        Send(GUICtrlRead($Input1) & " Add 2 to the value somehow and write that value here")
                Case $Button4
                        Run("notepad.exe")
                        WinWaitActive("Untitled - Notepad")
                        Send(GUICtrlRead($Input1) & " Subtract 2 to the value somehow and write that value here")
    EndSwitch
WEnd

Get what I mean?

Edited by kjpolker

Share this post


Link to post
Share on other sites
kjpolker

What if there is no parenthesis? In my case it is a loop time:

Until $times = GUICtrlRead($input4) / 5

And for some reason it does its loop the amount of times in my input box rather the the amount divided by 5.

Edited by kjpolker

Share this post


Link to post
Share on other sites
demandnothing

i made this app a while back to calculate KDR (Kill Death Ratio) for first person shooter games.. it might come in handy for your cause.. i dont know about the notepad deal, but check it out.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("KDR Calculator", 206, 398, 327, 218)
GUISetBkColor(0x000080)
$Kills = GUICtrlCreateInput("Kills", 52, 8, 105, 21)
GUICtrlSetCursor (-1, 5)
$Deaths = GUICtrlCreateInput("Deaths", 52, 42, 105, 21)
GUICtrlSetCursor (-1, 5)
$Current = GUICtrlCreateInput("Current KDR", 12, 84, 73, 21)
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 3)
$Desired = GUICtrlCreateInput("Desired KDR", 116, 102, 73, 21)
GUICtrlSetCursor (-1, 5)
$Label1 = GUICtrlCreateLabel("Never Say Die", 32, 152, 188, 32)
GUICtrlSetFont(-1, 16, 800, 0, "Rothenburg Decorative")
GUICtrlSetColor(-1, 0x960000)
$KillsToGo = GUICtrlCreateInput("KillsToGo", 40, 184, 121, 21)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 3)
$CharacterLookUp = GUICtrlCreateInput("CharacterLookUp", 8, 360, 121, 21)
$Button1 = GUICtrlCreateButton("Go", 144, 360, 35, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Calculate", 32, 120, 75, 25, $WS_GROUP)
$Label2 = GUICtrlCreateLabel("Success", 11, 231, 172, 61)
GUICtrlSetFont(-1, 34, 400, 0, "Rothenburg Decorative")
GUICtrlSetColor(-1, 0x960000)
$KillsAfter = GUICtrlCreateInput("KillsAfter", 40, 280, 121, 21)
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 3)
$DeathsAfter = GUICtrlCreateInput("DeathsAfter", 40, 312, 121, 21)
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 3)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $Web = ShellExecute("http://combatarms.nexon.net/Community/Profile.aspx?user=" & GUICtrlRead($CharacterLookUp))
        Case $Button2
            Calculate()
    EndSwitch
WEnd



 Func Calculate()
    $K = GUICtrlRead($Kills)
    $D = GUICtrlRead($Deaths)
    $C = $K / $D
    $F = StringLeft($C, 4)
    $E = GUICtrlRead($Desired)
    $y = $D * $E
    $x = $K * $E
    $v = $y - $K
    $t = $x + $D
    $m = $v + $K
    $m2 = $v + $t

    GUICtrlSetData($Current, $F & " -KDR")
    If Not Number($E) = 0 Then
        If $v >= 0 Then
            GUICtrlSetData($KillsToGo, $v & " More Kills")
            GUICtrlSetData($KillsAfter, $m & " Kills")
            GUICtrlSetData($DeathsAfter, $D & " Deaths")
        ElseIf $v < 0 Then
            GUICtrlSetData($KillsToGo, $v*(-1) & " More Deaths")
            GUICtrlSetData($KillsAfter, $K & " Kills")
            GUICtrlSetData($DeathsAfter, $m2 & " Deaths")
        EndIf
    Else
        Sleep(100)
    EndIf
EndFunc

and not having parenthesis as you've put it is fine.. it'll work that way

Edited by demandnothing

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  

×