Checkbox Auslesen Problem

  • Hallo,

    ich habe dort ein kleines Problem beim Checkboxen auslesen.

    Wenn Checkbox Ja und Nein aktiviert sind, dann soll er etwas anderes senden, als wenn sie einzeln ausgewählt sind.

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 151, 82, 192, 124)
    $Ja = GUICtrlCreateCheckbox("Ja", 8, 16, 49, 17)
    $Nein = GUICtrlCreateCheckbox("Nein", 96, 16, 49, 17)
    $klick = GUICtrlCreateButton("klick", 32, 48, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $klick
    If GUICtrlRead($Nein) and GUICtrlRead($Ja) = $GUI_CHECKED then
    MsgBox (64, "Beides", "Sie haben beide Checkboxen aktiviert.")
    EndIf
    If GUICtrlRead($Ja) = $GUI_CHECKED then
    MsgBox (64, "Ja", "Sie haben die Checkbox Ja aktiviert")
    EndIf
    If GUICtrlRead($Nein) = $GUI_CHECKED then
    MsgBox (64, "Nein", "Sie haben die Checkbox Nein aktiviert")
    EndIf
    EndSwitch
    WEnd

    [/autoit]

    Einmal editiert, zuletzt von White (30. Juni 2011 um 00:38)

    • Offizieller Beitrag

    Das reicht vollkommen aus:

    [autoit]

    If BitAND(GUICtrlRead($Nein), $GUI_CHECKED) then

    [/autoit]
    • Offizieller Beitrag

    Wer den schwachfug in den Beispielen verbrochen hat, sollte man hauen. :D

    Hab am Anfang das net geblickt und wollte auf unchecked testen.

    [autoit]


    If BitAND(GUICtrlRead($Nein), $GUI_UNCHECKED) = $GUI_UNCHECKED then

    [/autoit]


    Geht natürlich nicht da das ganze logisch so ausehen müßte:

    [autoit]


    If BitAND(GUICtrlRead($Nein), $GUI_UNCHECKED) then

    [/autoit]
  • Habe es nun so , jedoch zeigt er 2x " , dass du beide Checkboxen aktiviert hast.

    Könnt ihr mir da noch einmal helfen?

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 151, 82, 192, 124)
    $Ja = GUICtrlCreateCheckbox("Ja", 8, 16, 49, 17)
    $Nein = GUICtrlCreateCheckbox("Nein", 96, 16, 49, 17)
    $klick = GUICtrlCreateButton("klick", 32, 48, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $klick
    If GUICtrlRead($Ja) = $GUI_CHECKED then
    If BitAND(GUICtrlRead($Nein), $GUI_UNCHECKED) then
    MsgBox (64, "Ja", "Sie haben die Checkbox Ja aktiviert")
    Else
    MsgBox (64, "Beides", "Sie haben beide Checkboxen aktiviert.")
    EndIf
    EndIf
    If GUICtrlRead($Nein) = $GUI_CHECKED then
    If BitAND(GUICtrlRead($Ja), $GUI_UNCHECKED) then
    MsgBox (64, "Nein", "Sie haben die Checkbox Nein aktiviert")
    Else
    MsgBox (64, "Beides", "Sie haben beide Checkboxen aktiviert.")
    EndIf
    EndIf
    EndSwitch
    WEnd

    [/autoit]
  • Hallo White,

    ich weiß, der beitrag ist gelöst, aber ich habe eine Version ganz ohne BitAND.

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 151, 82, 192, 124)
    $Ja = GUICtrlCreateCheckbox("Ja", 8, 16, 49, 17)
    $Nein = GUICtrlCreateCheckbox("Nein", 96, 16, 49, 17)
    $klick = GUICtrlCreateButton("klick", 32, 48, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $klick
    If GUICtrlRead($Nein) = $GUI_CHECKED And GUICtrlRead($Ja) = $GUI_CHECKED then
    MsgBox (64, "Beides", "Sie haben beide Checkboxen aktiviert.")
    Else
    If GUICtrlRead($Ja) = $GUI_CHECKED Then
    MsgBox (64, "Ja", "Sie haben die Checkbox Ja aktiviert")
    Else
    MsgBox (64, "Nein", "Sie haben die Checkbox Nein aktiviert")
    EndIf
    EndIf
    EndSwitch
    WEnd

    [/autoit]


    Einfach alles in einen If Ausdruck und darin noch einer, dann noch statt...

    [autoit]

    If GUICtrlRead($Nein) And GUICtrlRead($Ja) = $GUI_CHECKED then

    [/autoit]


    ... das hier geschrieben...

    [autoit]

    If GUICtrlRead($Nein) = $GUI_CHECKED And GUICtrlRead($Ja) = $GUI_CHECKED then

    [/autoit]


    ... und fertig:

    mfg
    hauke96

  • Hallo white,

    mach es do einfach so:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 151, 82, 192, 124)
    $Ja = GUICtrlCreateCheckbox("Ja", 8, 16, 49, 17)
    $Nein = GUICtrlCreateCheckbox("Nein", 96, 16, 49, 17)
    $klick = GUICtrlCreateButton("klick", 32, 48, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $klick
    If BitAND(GUICtrlRead($Nein),$GUI_CHECKED) And BitAND(GUICtrlRead($Ja),$GUI_CHECKED) Then
    MsgBox(64, "Beides", "Sie haben beide Checkboxen aktiviert.")
    Else
    If BitAND(GUICtrlRead($Ja),$GUI_CHECKED) Then
    MsgBox(64, "Ja", "Sie haben die Checkbox Ja aktiviert")
    EndIf
    If BitAND(GUICtrlRead($Nein),$GUI_CHECKED) Then
    MsgBox(64, "Nein", "Sie haben die Checkbox Nein aktiviert")
    EndIf
    EndIf
    EndSwitch
    WEnd

    [/autoit]

    mfg autoBert

  • ;) Hi,
    oder ganz anders ...

    Spoiler anzeigen
    [autoit]


    Global $ckb[2]
    GUICreate("Checkbox", 150, 80)
    $ckb[0] = GUICtrlCreateCheckbox("Ja", 8, 16, 49, 17)
    $ckb[1] = GUICtrlCreateCheckbox("Nein", 96, 16, 49, 17)
    $klick = GUICtrlCreateButton("klick", 32, 48, 75, 22)
    GUISetState(@SW_SHOW)

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

    While 1
    Switch GUIGetMsg()
    Case -3
    Exit
    Case $klick
    If BitAND(GUICtrlRead($ckb[0]), 1) And BitAND(GUICtrlRead($ckb[1]), 1) Then
    MsgBox(64, "Beide", "Beide Checkboxen sind aktiviert !" & @TAB)
    Else
    For $i = 0 To 1 ;i statisch kein Ubound
    If BitAND(GUICtrlRead($ckb[$i]), 1) Then
    Switch $i
    Case 0 ;GUICtrlRead($ckb[0]) = 1
    MsgBox(64, "Ja", "Checkbox Ja ist aktiviert !" & @TAB)
    Case 1 ;GUICtrlRead($ckb[1]) = 1
    MsgBox(64, "Nein", "Checkbox Nein ist aktiviert !" & @TAB)
    EndSwitch
    EndIf
    Next
    EndIf
    EndSwitch
    WEnd
    ; Ende

    [/autoit]