Unterschied (Switch case) (If Then endif)

  • hallo
    ich wollte eine einfache abfrage des GUICtrlCreateSlider
    in einen label ausgeben.
    soweit so gut,

    mach ich es in (Switch case)
    flackert es extrem...

    mach ich es in (If Then endif)
    flackert es nicht mehr ganz so starck...
    aber warum ??? mach ich was falsch?

    [autoit]


    #include <Debug.au3>
    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 623, 138, 192, 114)
    $Label1 = GUICtrlCreateLabel("Label1", 216, 16, 36, 17)
    $Slider1 = GUICtrlCreateSlider(56, 48, 481, 20)
    GUICtrlSetLimit(-1, 100, 0)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

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

    ;_DebugSetup("debug", True) ;

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

    While 1

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

    $nMsg = GUIGetMsg()

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

    if $nMsg <> 0 Then
    ;_DebugOut($nMsg)
    EndIf

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

    ;If (GUICtrlRead($Slider1)) And ($nMsg <> 0) Then
    ;GUICtrlSetData($Label1, GUICtrlRead($Slider1))
    ;EndIf

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

    Switch $nMsg
    Case $nMsg = $Slider1
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
    EndSwitch

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

    ;Select
    ;Case $nMsg = $Slider1
    ;GUICtrlSetData($Label1, GUICtrlRead($Slider1))
    ;EndSelect

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

    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch

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

    WEnd

    [/autoit]
  • Du hast da wohl etwas falsch verstanden...

    [autoit]

    #include <Debug.au3>
    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 623, 138, 192, 114)
    $Label1 = GUICtrlCreateLabel("Label1", 216, 16, 36, 17)
    $Slider1 = GUICtrlCreateSlider(56, 48, 481, 20)
    GUICtrlSetLimit(-1, 100, 0)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Slider1
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit]

    LG
    Christoph :)


  • hi danke für die antwort aber......
    ich möchte das der wert des sliders sich in echtzeit ändert.
    nicht wenn ich die maus loslasse.

  • Zeile 7:

    Spoiler anzeigen
    [autoit]

    #include <Debug.au3>
    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 623, 138, 192, 114, Default, $WS_EX_COMPOSITED + $WS_EX_LAYERED)
    $Label1 = GUICtrlCreateLabel("Label1", 216, 16, 36, 17)
    $Slider1 = GUICtrlCreateSlider(56, 48, 481, 20)
    GUICtrlSetLimit(-1, 100, 0)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

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

    ;_DebugSetup("debug", True) ;

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

    While 1

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

    $nMsg = GUIGetMsg()

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

    if $nMsg <> 0 Then
    ;_DebugOut($nMsg)
    EndIf

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

    ;If (GUICtrlRead($Slider1)) And ($nMsg <> 0) Then
    ;GUICtrlSetData($Label1, GUICtrlRead($Slider1))
    ;EndIf

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

    Switch $nMsg
    Case $nMsg = $Slider1
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
    EndSwitch

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

    ;Select
    ;Case $nMsg = $Slider1
    ;GUICtrlSetData($Label1, GUICtrlRead($Slider1))
    ;EndSelect

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

    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch

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

    WEnd

    [/autoit]
  • ;)

    [autoit]

    #include <Debug.au3>
    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 623, 138, 192, 114)
    $Label1 = GUICtrlCreateLabel("Label1", 216, 16, 36, 17)
    $Slider1 = GUICtrlCreateSlider(56, 48, 481, 20)
    GUICtrlSetLimit(-1, 100, 0)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###
    Local $iLast

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    If GUICtrlRead($Slider1) <> $iLast Then
    $iLast = GUICtrlRead($Slider1)
    GUICtrlSetData($Label1, $iLast)
    EndIf
    WEnd

    [/autoit]

    LG
    Christoph :)

    • Offizieller Beitrag

    Ich würde es so machen:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 623, 138, 192, 114)
    $Label1 = GUICtrlCreateLabel("Label1", 216, 16, 36, 17)
    $Slider1 = GUICtrlCreateSlider(56, 48, 481, 20)
    GUICtrlSetLimit(-1, 100, 0)
    GUIRegisterMsg($WM_HSCROLL, "_ChangeSlider")
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

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

    Func _ChangeSlider($hWnd, $Msg, $wParam, $lParam)
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
    Return $GUI_RUNDEFMSG
    EndFunc ;==>_ChangeSlider

    [/autoit]
  • @make-grafik Deine Switch Abfrage macht wenig Sinn. Switch vergleicht den Wert jeder einzelnen Case ... Zeile mit dem Wert hinter dem Switch Statement. Du vergleichst den Wert von $nMsg mit dem Ergebnis von $nMsg = $slider1 (bei dem nur True oder False rauskommt).
    Du könntest die Abfrage auch gleich weglassen, weil diese Zeile "GUICtrlSetData($Label1, GUICtrlRead($Slider1))" sowieso bei fast jedem Schleifendurchgang ausgeführt wird.


  • hey vielen dank
    schöne lösung das gefällt mir danke


  • hey danke
    aber das ist mir noch zu kompiziert :S
    werde ich mir auf jeden fall speichern und näher anschauen