Jump to content

Increment several fields to adjust value of one


Kohr
 Share

Recommended Posts

I am trying to use GUICtrlCreateUpdown in several Inputs that will adjust another label. I have about 30 Input controls that this would be used on and I was hoping there is an easier way to accomplish this task.

This will eventually be used to simulate betting where you increase different bet type fields and for each bet placed it will take your money away (one label used to indicate this).

Kohr

Attached example

#include "GUIConstants.au3"
Opt("GUIOnEventMode", 1)

GUICreate("", 200, 200)

$input = GUICtrlCreateInput("0", 10, 10, 50, 20, $ES_NUMBER)
$updown = GUICtrlCreateUpdown($input)
GUICtrlSetLimit($updown, 100, 0)
GUICtrlSetOnEvent($updown, "test")
Global $old = 0

$input2 = GUICtrlCreateInput("0", 70, 10, 50, 20, $ES_NUMBER)
$updown2 = GUICtrlCreateUpdown($input2)
GUICtrlSetLimit($updown2, 100, 0)
GUICtrlSetOnEvent($updown2, "test")
Global $old2 = 0

$labelPlayerMoney = GUICtrlCreateLabel("0", 100, 100, 50, 20)

GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked")

While 1
    Sleep(200)
WEnd

Func test()
    $bumpValue = 10
    If $old <> Int(GUICtrlRead($input)) Then
        If $old < Int(GUICtrlRead($input)) Then; up
            $old = ((Int(GUICtrlRead($input)) - $old) * $bumpValue) + $old
            If $old > 100 Then $old = 100
            GUICtrlSetData($input, $old)
            $ret = GUICtrlRead($labelPlayerMoney)
            GUICtrlSetData($labelPlayerMoney, $ret + $bumpValue)
        Else
            $old = (($old - Int(GUICtrlRead($input))) * - $bumpValue) + $old
            If $old < 0 Then $old = 0
            GUICtrlSetData($input, $old)
            $ret = GUICtrlRead($labelPlayerMoney)
            GUICtrlSetData($labelPlayerMoney, $ret - $bumpValue)
        EndIf
    EndIf
    If $old2 <> Int(GUICtrlRead($input2)) Then
        If $old2 < Int(GUICtrlRead($input2)) Then; up
            $old2 = ((Int(GUICtrlRead($input2)) - $old2) * $bumpValue) + $old2
            If $old2 > 100 Then $old2 = 100
            GUICtrlSetData($input2, $old2)
            $ret = GUICtrlRead($labelPlayerMoney)
            GUICtrlSetData($labelPlayerMoney, $ret + $bumpValue)
        Else
            $old2 = (($old2 - Int(GUICtrlRead($input2))) * - $bumpValue) + $old2
            If $old2 < 0 Then $old2 = 0
            GUICtrlSetData($input2, $old2)
            $ret = GUICtrlRead($labelPlayerMoney)
            GUICtrlSetData($labelPlayerMoney, $ret - $bumpValue)
        EndIf
    EndIf
EndFunc   ;==>test

Func CloseClicked()
    Exit
EndFunc   ;==>CloseClicked
Link to comment
Share on other sites

maybe...

#include "GUIConstants.au3"
Opt("GUIOnEventMode", 1)

Dim $Input[3], $old[3]

For $x = 1 To UBound($old) - 1
    $old[$x] = 0
Next

GUICreate("", 200, 200)

$Input[1] = GUICtrlCreateInput("0", 10, 10, 50, 20, $ES_NUMBER)
$updown = GUICtrlCreateUpdown($Input[1])
GUICtrlSetLimit($updown, 100, 0)
GUICtrlSetOnEvent($updown, "test")

$Input[2] = GUICtrlCreateInput("0", 70, 10, 50, 20, $ES_NUMBER)
$updown2 = GUICtrlCreateUpdown($Input[2])
GUICtrlSetLimit($updown2, 100, 0)
GUICtrlSetOnEvent($updown2, "test")

$labelPlayerMoney = GUICtrlCreateLabel("0", 100, 100, 50, 20)

GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked")

While 1
    Sleep(20)
WEnd

Func test()
    $bumpValue = 10
    For $i = 1 To UBound($Input) - 1
        If $old[$i] <> Int(GUICtrlRead($Input[$i])) Then
            If $old[$i] < Int(GUICtrlRead($Input[$i])) Then; up
                $old[$i]= ((Int(GUICtrlRead($Input[$i])) - $old[$i]) * $bumpValue) + $old[$i]
                If $old[$i] > 100 Then $old[$i] = 100
                GUICtrlSetData($Input[$i], $old[$i])
                $ret = GUICtrlRead($labelPlayerMoney)
                GUICtrlSetData($labelPlayerMoney, $ret + $bumpValue)
            Else
                $old[$i]= (($old[$i] - Int(GUICtrlRead($Input[$i]))) * - $bumpValue) + $old[$i]
                If $old[$i] < 0 Then $old[$i] = 0
                GUICtrlSetData($Input[$i], $old[$i])
                $ret = GUICtrlRead($labelPlayerMoney)
                GUICtrlSetData($labelPlayerMoney, $ret - $bumpValue)
            EndIf
        EndIf
    Next
EndFunc   ;==>test

Func CloseClicked()
    Exit
EndFunc   ;==>CloseClicked

8)

Edited by Valuater

NEWHeader1.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...