Fehler im Skript [aber wo?]

  • Das ist ein kleiner und gekürzter Ausschnitt.

    Es gibt 4 Eingabefelder.
    2 Stück gehören immer "zusammen".
    Wenn man auf den Button "Speichern" klickt, dann werden 2 Inputfelder verglichen (immer die, die nebeneinander sind)

    Dabei gilt:
    Der linke Input müsste immer der Kleinere sein.
    Der rechte demnach der Größere.
    Beide Inputs haben maximale Größen, die sie erreichen können.
    - wenn sie diese Grenzen überrschreiten, dann wird ein vorgeschriebener Standardwert genommen
    Sind beide Inputs gleichgroß, dann wird ihnen der Standardwert zugeschrieben
    Ist der erste Wert größer als der zweite, dann sollen sie vertauscht werden.

    Genau beim letzten Punkt liegt das Problem.
    Bei mir vertauschen sich die Werte, auch wenn sie sich nicht vertauschen sollten!?
    Wo liegt mein Denkfehler?

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <GuiTab.au3>
    #Include <GuiButton.au3>
    #include <ButtonConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $min, $max, $min_d, $max_d
    Global $button0, $input0, $input1, $input2, $input3

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("Name", 400, 300)
    GUICtrlCreateGroup("Test", 30, 90, 100, 180)
    $label0 = GuiCtrlCreateLabel("Zahl1", 40, 108, -1, -1)
    GUICtrlSetTip($label0, "Zahlenbestimmung: Min. - Max.")
    $label1 = GuiCtrlCreateLabel("Min.", 40, 123, -1, -1)
    GUICtrlSetTip($label1, "Min-Wert: [38;11199[")
    $label2 = GuiCtrlCreateLabel("Max.", 90, 123, -1, -1)
    GUICtrlSetTip($label2, "Max-Wert: ]39;11200]")
    $input0 = GUICtrlCreateInput("70", 40, 138, 38, 20)
    $input1 = GUICtrlCreateInput("11200", 78, 138, 38, 20)
    $input2 = GUICtrlCreateInput("50", 40, 183, 38, 20)
    $input3 = GUICtrlCreateInput("60", 78, 183, 38, 20)
    $button0 = GuiCtrlCreateButton("Speichern", 50, 205)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While(1)
    $stateGUI = GUIGetMsg()
    Switch $stateGUI
    Case $GUI_EVENT_CLOSE
    Exit
    Case $button0
    test()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func test()
    $min = GUICtrlRead($input0)
    $max = GUICtrlRead($input1)
    $min_d = GUICtrlRead($input2)
    $max_d = GUICtrlRead($input3)
    If $min > $max Then
    $x = $max
    $max = $min
    $min = $x
    GUICtrlSetData($input0, $min)
    GUICtrlSetData($input1, $max)
    EndIf
    If $min < 38 Or $min > 11199 Or $min = $max Then
    $min = 70
    GUICtrlSetData($input0, 70)
    EndIf
    If $max > 11200 Or $max < 39 Or $min = $max Then
    $max = 11200
    GUICtrlSetData($input1, 11200)
    EndIf
    If $min_d > $max_d Then
    $x = $max_d
    $max_d = $min_d
    $min_d = $x
    GUICtrlSetData($input0, $min_d)
    GUICtrlSetData($input1, $max_d)
    EndIf
    If $min_d > 59999 Or $min_d < 10 Or $min_d = $max_d Then
    $min_d = 50
    GUICtrlSetData($input2, 50)
    EndIf
    If $max_d > 60000 Or $max_d < 11 Or $min_d = $max_d Then
    $max_d = 60
    GUICtrlSetData($input3, 60)
    EndIf
    EndFunc

    [/autoit]

    .. Verkürzungen müssen nicht sein (Arrays etc.). ;)

  • Hallo seTTS,

    ich hoffe ich habe dich richtig verstanden, ich hab auf jeden Fall einmal die Abfragen in der Reihenfolge gemacht wie du es beschrieben hast. Herausgekommen ist diese Lösung:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <GuiTab.au3>
    #Include <GuiButton.au3>
    #include <ButtonConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $min, $max, $min_d, $max_d
    Global $button0, $input0, $input1, $input2, $input3

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("Name", 400, 300)
    GUICtrlCreateGroup("Test", 30, 90, 100, 180)
    $label0 = GuiCtrlCreateLabel("Zahl1", 40, 108, -1, -1)
    GUICtrlSetTip($label0, "Zahlenbestimmung: Min. - Max.")
    $label1 = GuiCtrlCreateLabel("Min.", 40, 123, -1, -1)
    GUICtrlSetTip($label1, "Min-Wert: [38;11199[")
    $label2 = GuiCtrlCreateLabel("Max.", 90, 123, -1, -1)
    GUICtrlSetTip($label2, "Max-Wert: ]39;11200]")
    $input0 = GUICtrlCreateInput("70", 40, 138, 38, 20)
    $input1 = GUICtrlCreateInput("11200", 78, 138, 38, 20)
    $input2 = GUICtrlCreateInput("50", 40, 183, 38, 20)
    $input3 = GUICtrlCreateInput("60", 78, 183, 38, 20)
    $button0 = GuiCtrlCreateButton("Speichern", 50, 205)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While(1)
    $stateGUI = GUIGetMsg()
    Switch $stateGUI
    Case $GUI_EVENT_CLOSE
    Exit
    Case $button0
    test()
    GUISetState()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func test()
    $min = GUICtrlRead($input0)
    $max = GUICtrlRead($input1)
    If $min < 38 Or $min > 11199 Or $min = $max Then $min = 70
    If $max > 11200 Or $max < 39 Or $min = $max Then $max = 11200
    If $min > $max Then
    $x = $max
    $max = $min
    $min = $x
    EndIf
    GUICtrlSetData($input0, $min)
    GUICtrlSetData($input1, $max)
    ;ConsoleWrite("Min: " & $min & " Max: " & $max & @CRLF)
    $min_d = GUICtrlRead($input2)
    $max_d = GUICtrlRead($input3)
    If $min_d > 59999 Or $min_d < 10 Or $min_d = $max_d Then $min_d = 50
    If $max_d > 60000 Or $max_d < 11 Or $min_d = $max_d Then $max_d = 60
    If $min_d > $max_d Then
    $x = $max_d
    $max_d = $min_d
    $min_d = $x
    EndIf
    GUICtrlSetData($input2, $min_d)
    GUICtrlSetData($input3, $max_d)
    ;ConsoleWrite("Min: " & $min_d & " Max: " & $max_d & @CRLF)
    EndFunc

    [/autoit]

    PS.: das zweite Zahlenpaar hatest du aus versehen den Input-Feldern des 1. Paares zugewiesen

    mfg (Auto)Bert

  • Danke =)
    Du hast es deutlich eleganter gelöst =).
    Nur ein Problem hab ich immer noch.

    Die ersten 2 InputFelder spielen i-wie verrückt.
    Die tauschen ihren Wert immer unabhängig ihres Wertes, was eigentlich völlig unömglich ist...
    Stehe da echt auf dem Schlauch..

    Wieso ist das so? ?(

    • Offizieller Beitrag

    Das Feld wird nicht als Zahl ausgelesen, sondern als String.
    Will man den Zahlwert vergleichen, dann sollte man Number davor setzen:

    [autoit]


    Func test()
    $min = Number(GUICtrlRead($input0))
    $max = Number(GUICtrlRead($input1))
    If $min < 38 Or $min > 11199 Or $min = $max Then $min = 70
    If $max > 11200 Or $max < 39 Or $min = $max Then $max = 11200
    If $min > $max Then
    $x = $max
    $max = $min
    $min = $x
    EndIf
    GUICtrlSetData($input0, $min)
    GUICtrlSetData($input1, $max)
    ;ConsoleWrite("Min: " & $min & " Max: " & $max & @CRLF)
    $min_d = Number(GUICtrlRead($input2))
    $max_d = Number(GUICtrlRead($input3))
    If $min_d > 59999 Or $min_d < 10 Or $min_d = $max_d Then $min_d = 50
    If $max_d > 60000 Or $max_d < 11 Or $min_d = $max_d Then $max_d = 60
    If $min_d > $max_d Then
    $x = $max_d
    $max_d = $min_d
    $min_d = $x
    EndIf
    GUICtrlSetData($input2, $min_d)
    GUICtrlSetData($input3, $max_d)
    ;ConsoleWrite("Min: " & $min_d & " Max: " & $max_d & @CRLF)
    EndFunc

    [/autoit]
  • Danke Oscar =)
    Ich wär nie dahinter gekommen xD
    Des steht aber nicht in der Hilfsbeschreibung von GUICtrlRead bzw. CUICtrlCreateInput, dass Inputs als String abgefragt werden.
    Schade.. ;)