Checkboxen nacheinander abfragen und ausführen

  • Guten Abend!
    Ich habe ein GUI erstellt mit einigem drin. Woran mein Wissen aber leider scheitert ist, dass ich nun vier Checkboxen habe. Wenn ich auf "OK" drücke, dann möchte ich, dass überprüft wird, ob die Checkboxen "CHECKED" sind und wenn ja, Befehle ausgeführt werden. Soweit klar. Nun ist es aber wichtig, dass zuerst der Befehl von Checkbox1 (falls checked) ausgeführt wird, danach dann CB2, und so weiter...
    Wenn ich normale Schleifen einfach hintereinander reihe, dann führt er immer nur das erste aus (s.u.).
    Help?! Danke Euch...!

    Spoiler anzeigen
    [autoit]

    GUISetState()
    While 1
    $Msg1 = GUIGetMsg()
    Switch $Msg1
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If BitAND(GUICtrlRead($Box1), $GUI_CHECKED) Then RunWait("C:\Users\...\Desktop\Programm\Box1.exe")
    EndSwitch
    WEnd

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

    GUISetState()
    While 1
    $Msg2 = GUIGetMsg()
    Switch $Msg2
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If BitAND(GUICtrlRead($Box2), $GUI_CHECKED) Then RunWait("C:\Users\...\DesktopProgramm\Box2.exe")
    EndSwitch
    WEnd

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

    GUISetState()
    While 1
    $Msg3 = GUIGetMsg()
    Switch $Msg3
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If BitAND(GUICtrlRead($Box3), $GUI_CHECKED) Then RunWait("C:\Users\...\Desktop\Programm\Box3.exe")
    EndSwitch
    WEnd

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

    GUISetState()
    While 1
    $Msg4 = GUIGetMsg()
    Switch $Msg4
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If BitAND(GUICtrlRead($Box4), $GUI_CHECKED) Then RunWait("C:\Users\...\Desktop\Programm\Box4.exe")
    EndSwitch
    WEnd

    [/autoit]

    Einmal editiert, zuletzt von Maxore (24. Januar 2010 um 09:24)

  • Versuch mal das hier:

    Spoiler anzeigen
    [autoit]

    Global $CheckBox[4]

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

    ;...GUI Code

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

    $CheckBox[0] = GUICtrlCreateCheckbox("Box1", 10, 10)
    $CheckBox[1] = GUICtrlCreateCheckbox("Box2", 10, 10)
    $CheckBox[2] = GUICtrlCreateCheckbox("Box3", 10, 10)
    $CheckBox[3] = GUICtrlCreateCheckbox("Box4", 10, 10)

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

    ;...GUI Code

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

    GUISetState()
    While 1
    $Msg1 = GUIGetMsg()
    Switch $Msg1
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    For $i = 0 To 3
    If BitAND(GUICtrlRead($CheckBox[$i]), $GUI_CHECKED) Then RunWait("C:\Users\...\Desktop\Programm\Box" & ($i + 1) & ".exe")
    Next
    EndSwitch
    WEnd

    [/autoit]
  • normalerweise macht man das so ;)

    Spoiler anzeigen
    [autoit]

    GUISetState()
    While 1
    $Msg1 = GUIGetMsg()
    Switch $Msg1
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If BitAND(GUICtrlRead($Box1), $GUI_CHECKED) Then RunWait("C:\Users\...\Desktop\Programm\Box1.exe")
    If BitAND(GUICtrlRead($Box2), $GUI_CHECKED) Then RunWait("C:\Users\...\DesktopProgramm\Box2.exe")
    If BitAND(GUICtrlRead($Box2), $GUI_CHECKED) Then RunWait("C:\Users\...\DesktopProgramm\Box3.exe")
    If BitAND(GUICtrlRead($Box2), $GUI_CHECKED) Then RunWait("C:\Users\...\DesktopProgramm\Box4.exe")

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

    EndSwitch
    WEnd

    [/autoit]
  • Super, danke für die schnellen Ideen!
    @m-obi: Habe nicht erwähnt, dass ich noch ne Radiobox-Abfrage drinhab, geht also so leider nicht.
    Schnitzel: Habs jetzt so gemacht. Leider hört er bei mir nicht mehr auf und führt alles unendlich mal hintereinander aus :D
    Warum?! Was kann ich dagegen machen?

  • wenn es nur eine Radiobox ist kannst du die auch als Checkbox machen. Radiobox macht nur sind ab 2 Boxen.

  • Habs jetzt so gemacht. Leider hört er bei mir nicht mehr auf und führt alles unendlich mal hintereinander aus :D
    Warum?! Was kann ich dagegen machen?

    ui das is interessant.

    Poste doch mal bitte dein ganzes script. wird wahrscheinlich nicht an den kleinen auszug liegen.

  • ist mehr als eine radio box ;)
    Danke nochmal/schonmal!


    Spoiler anzeigen
    [autoit]


    Opt("MustDeclareVars", 1)
    #include <GuiConstantsEx.au3>

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

    HotKeySet ( "{Esc}", "close")
    Func close()
    Exit 0
    EndFunc

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

    Global $Msg1, $Msg2, $Button1

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

    Global $Befehle[45] = ['MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")']

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

    ;Dimension
    Dim $Radio[45]
    Dim $Box[4]

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

    ; GUI
    GuiCreate("Arbeit", 500, 550)

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

    ; BUTTON
    $Button1 = GuiCtrlCreateButton("Go", 200, 510, 100, 30)

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

    ;Checkbox 1
    $Box[0] = GUICtrlCreateCheckbox("&Erster", 70, 480, 80, 20)
    GUICtrlSetState(-1, $GUI_UNCHECKED)

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

    ;Checkbox 2
    $Box[1] = GuiCtrlCreateCheckbox("&Zweiter", 160, 480, 80, 20)
    GuiCtrlSetState(-1, $GUI_UNCHECKED)

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

    ;Checkbox 3
    $Box[2] = GuiCtrlCreateCheckbox("&Dritter", 255, 480, 80, 20)
    GuiCtrlSetState(-1, $GUI_UNCHECKED)

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

    ;Checkbox 4
    $Box[3] = GUICtrlCreateCheckbox("&Vierter", 340, 480, 130, 20)
    GUICtrlSetState(-1, $GUI_UNCHECKED)

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

    ;Gruppe 1
    GUICtrlCreateGroup("Feld 1", 35, 10, 100, 460)
    $Radio[0] = GUICtrlCreateRadio("Ka", 40, 35, 80, 20)
    $Radio[1] = GUICtrlCreateRadio("Ge", 40, 60, 80, 20)
    $Radio[2] = GUICtrlCreateRadio("Gu", 40, 85, 80, 20)
    $Radio[3] = GUICtrlCreateRadio("Ma", 40, 110, 80, 20)
    $Radio[4] = GUICtrlCreateRadio("Er", 40, 135, 80, 20)
    $Radio[5] = GUICtrlCreateRadio("Ra", 40, 160, 80, 20)
    $Radio[6] = GUICtrlCreateRadio("To", 40, 185, 80, 20)
    $Radio[7] = GUICtrlCreateRadio("Sp", 40, 210, 80, 20)
    $Radio[8] = GUICtrlCreateRadio("Zw", 40, 235, 80, 20)
    $Radio[9] = GUICtrlCreateRadio("Kl", 40, 260, 80, 20)
    $Radio[10] = GUICtrlCreateRadio("Ra", 40, 285, 80, 20)
    $Radio[11] = GUICtrlCreateRadio("Bl", 40, 310, 80, 20)
    $Radio[12] = GUICtrlCreateRadio("Fu", 40, 335, 80, 20)
    $Radio[13] = GUICtrlCreateRadio("Kr", 40, 360, 80, 20)
    $Radio[14] = GUICtrlCreateRadio("Kar", 40, 385, 80, 20)
    GUICtrlCreateGroup("", -99, -99 , 1, 1)

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

    ;Gruppe 2
    GUICtrlCreateGroup("Feld 2", 205, 10, 100, 460)
    $Radio[15] = GUICtrlCreateRadio("Ka", 210, 35, 80, 20)
    $Radio[16] = GUICtrlCreateRadio("Ge", 210, 60, 80, 20)
    $Radio[17] = GUICtrlCreateRadio("Gu", 210, 85, 80, 20)
    $Radio[18] = GUICtrlCreateRadio("Ma", 210, 110, 80, 20)
    $Radio[19] = GUICtrlCreateRadio("Er", 210, 135, 80, 20)
    $Radio[20] = GUICtrlCreateRadio("Ra", 210, 160, 80, 20)
    $Radio[21] = GUICtrlCreateRadio("To", 210, 185, 80, 20)
    $Radio[22] = GUICtrlCreateRadio("Sp", 210, 210, 80, 20)
    $Radio[23] = GUICtrlCreateRadio("Zw", 210, 235, 80, 20)
    $Radio[24] = GUICtrlCreateRadio("Kl", 210, 260, 80, 20)
    $Radio[25] = GUICtrlCreateRadio("Ra", 210, 285, 80, 20)
    $Radio[26] = GUICtrlCreateRadio("Bl", 210, 310, 80, 20)
    $Radio[27] = GUICtrlCreateRadio("Fu", 210, 335, 80, 20)
    $Radio[28] = GUICtrlCreateRadio("Kr", 210, 360, 80, 20)
    $Radio[29] = GUICtrlCreateRadio("Kar", 210, 385, 80, 20)
    GUICtrlCreateGroup("", -99, -99 , 1, 1)

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

    ;Gruppe 3
    GUICtrlCreateGroup("Feld 3", 375, 10, 100, 460)
    $Radio[30] = GUICtrlCreateRadio("Ka", 380, 35, 80, 20)
    $Radio[31] = GUICtrlCreateRadio("Ge", 380, 60, 80, 20)
    $Radio[32] = GUICtrlCreateRadio("Gu", 380, 85, 80, 20)
    $Radio[33] = GUICtrlCreateRadio("Ma", 380, 110, 80, 20)
    $Radio[34] = GUICtrlCreateRadio("Er", 380, 135, 80, 20)
    $Radio[35] = GUICtrlCreateRadio("Ra", 380, 160, 80, 20)
    $Radio[36] = GUICtrlCreateRadio("To", 380, 185, 80, 20)
    $Radio[37] = GUICtrlCreateRadio("Sp", 380, 210, 80, 20)
    $Radio[38] = GUICtrlCreateRadio("Zw", 380, 235, 80, 20)
    $Radio[39] = GUICtrlCreateRadio("Kl", 380, 260, 80, 20)
    $Radio[40] = GUICtrlCreateRadio("Ra", 380, 285, 80, 20)
    $Radio[41] = GUICtrlCreateRadio("Bl", 380, 310, 80, 20)
    $Radio[42] = GUICtrlCreateRadio("Fu", 380, 335, 80, 20)
    $Radio[43] = GUICtrlCreateRadio("Kr", 380, 360, 80, 20)
    $Radio[44] = GUICtrlCreateRadio("Kar", 380, 385, 80, 20)
    GUICtrlCreateGroup("", -99, -99 , 1, 1)

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

    GUISetState()
    While 1
    $Msg1 = GUIGetMsg()
    Switch $Msg1
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    For $i = 0 to 44
    If BitAND(GUICtrlRead($Box[0]), $GUI_CHECKED) Then RunWait("C:\Users\...\Desktop\Programm\Box1.exe")
    If BitAND(GUICtrlRead($Radio[$i]), $GUI_CHECKED) Then Execute($Befehle[$i])
    If BitAND(GUICtrlRead($Box[1]), $GUI_CHECKED) Then RunWait("C:\Users\Maximilian\Desktop\Farm\Programm\Box2.exe")
    If BitAND(GUICtrlRead($Box[2]), $GUI_CHECKED) Then RunWait("C:\Users\Maximilian\Desktop\Farm\Programm\Box3.exe")
    If BitAND(GUICtrlRead($Box[3]), $GUI_CHECKED) Then RunWait("C:\Users\Maximilian\Desktop\Farm\Programm\Box4.exe")
    Next
    EndSwitch
    WEnd

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

    ;die Reihenfolge der If-Befehle soll auch die Ausführungsreihenfolge sein
    ;unendlich wiederhot werden nur die Befehle der Checkboxen, die der Radios laufen (wie geplant) nur einmal ab

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]
  • Zitat

    Leider hört er bei mir nicht mehr auf und führt alles unendlich mal hintereinander aus :D
    Warum?! Was kann ich dagegen machen?

    Er führts genausooft aus wie du es ihm gesagt hast :D
    nämlich genau 45 mal

    du hast den befehl in der for schleife, derwegen wird er bei jedem $i einmal ausgeführt. und da du runwait benützt wartet er an der stelle bis das programm wieder beendet wurde und macht dann erst weiter.
    ich glaub du willst es so:

    [autoit]

    While 1
    $Msg1 = GUIGetMsg()
    Switch $Msg1
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If BitAND(GUICtrlRead($Box[0]), $GUI_CHECKED) Then RunWait("C:\Users\...\Desktop\Programm\Box1.exe")
    For $i = 0 to 44
    If BitAND(GUICtrlRead($Radio[$i]), $GUI_CHECKED) Then Execute($Befehle[$i])
    Next
    If BitAND(GUICtrlRead($Box[1]), $GUI_CHECKED) Then RunWait("C:\Users\Maximilian\Desktop\Farm\Programm\Box2.exe")
    If BitAND(GUICtrlRead($Box[2]), $GUI_CHECKED) Then RunWait("C:\Users\Maximilian\Desktop\Farm\Programm\Box3.exe")
    If BitAND(GUICtrlRead($Box[3]), $GUI_CHECKED) Then RunWait("C:\Users\Maximilian\Desktop\Farm\Programm\Box4.exe")
    EndSwitch
    WEnd

    [/autoit]

    PS: an den script könnte man einiges verkürzen ;)

  • Du bist mein Held! Jetz klappt Alles :rock:

    Was würdest Du denn verkürzen? (Nur, falls Du Lust hast Dir die Mühe zu machen... Funktioniert ja auch so ;) )

  • ähm man könnte das ganze radiobutton erstellen deutlich verkürzen

    und was willst du egtl mit dem array befehle? da steht überall der gleiche drin. bleibt das so oder war das nur zur vereinfachung?

    hier verkürzt:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    Opt("MustDeclareVars", 1)
    HotKeySet ( "{Esc}", "close")

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

    Func close()
    Exit 0
    EndFunc

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

    Global $Msg1, $Msg2, $Button1, $Radio

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

    Global $Befehle[45] = ['MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")','MsgBox(0,"","Kräh!")', _
    'MsgBox(0,"","Kräh!")']

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

    ;Dimension
    Dim $Box[4]

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

    ; GUI
    GuiCreate("Arbeit", 500, 550)

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

    ; BUTTON
    $Button1 = GuiCtrlCreateButton("Go", 200, 510, 100, 30)

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

    ;Checkbox 1
    $Box[0] = GUICtrlCreateCheckbox("&Erster", 70, 480, 80, 20)
    ;Checkbox 2
    $Box[1] = GuiCtrlCreateCheckbox("&Zweiter", 160, 480, 80, 20)
    ;Checkbox 3
    $Box[2] = GuiCtrlCreateCheckbox("&Dritter", 255, 480, 80, 20)
    ;Checkbox 4
    $Box[3] = GUICtrlCreateCheckbox("&Vierter", 340, 480, 130, 20)

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

    $Radio = StringSplit("Ka Ge Gu Ma Er Ra To Sp Zw Kl Ra Bl Fu Kr Kar Ka Ge Gu Ma Er Ra To Sp Zw Kl Ra Bl Fu Kr Kar Ka Ge Gu Ma Er Ra To Sp Zw Kl Ra Bl Fu Kr Kar", " ", 2)
    For $i = 0 To 2
    GUICtrlCreateGroup("Feld " & $i+1, 35 + $i * 170, 10, 100, 460)
    For $k = 0 To 14
    $Radio[$k + $i * 15] = GUICtrlCreateRadio($Radio[$k + $i * 15], 40 + $i * 170, 35 + $k * 25, 80, 20)
    Next
    GUICtrlCreateGroup("", -99, -99 , 1, 1)
    Next

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

    GUISetState()
    While 1
    $Msg1 = GUIGetMsg()
    Switch $Msg1
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If BitAND(GUICtrlRead($Box[0]), $GUI_CHECKED) Then RunWait("calc.exe")
    For $i = 0 to 44
    If BitAND(GUICtrlRead($Radio[$i]), $GUI_CHECKED) Then Execute($Befehle[$i])
    Next
    If BitAND(GUICtrlRead($Box[1]), $GUI_CHECKED) Then RunWait("C:\Users\Maximilian\Desktop\Farm\Programm\Box2.exe")
    If BitAND(GUICtrlRead($Box[2]), $GUI_CHECKED) Then RunWait("C:\Users\Maximilian\Desktop\Farm\Programm\Box3.exe")
    If BitAND(GUICtrlRead($Box[3]), $GUI_CHECKED) Then RunWait("C:\Users\Maximilian\Desktop\Farm\Programm\Box4.exe")
    EndSwitch
    WEnd

    [/autoit]
  • die befehle sollen nicht alle die gleichen sein... war nur zur vereinfachung
    die erstellung der radios ist ja richtig geil, so kurz - danke dafür! wird übernommen ;)

  • die befehle sollen nicht alle die gleichen sein... war nur zur vereinfachung
    die erstellung der radios ist ja richtig geil, so kurz - danke dafür! wird übernommen ;)

    joa kurz wird es dadurch schon. aber leider auch recht unübersichtlich.

    dafür kann man mit nur einen wert gleich die ganze spalte verändern.

    hat alles vor und nachteile^^

  • Zitat

    -> kann geschlossen werden...

    das musst du machen ^^

    Klick bei deinem ersten Post auf bearbeiten und setzte das Präfix auf gelöst. Und speichern nicht vergessen ;)