Seltsames ComboBox Verhalten

  • Hi Leute,
    ich arbeite im Moment an einem kleinen Projekt für mich, deshalb ist der Code auch so unsauber und dort habe ich ein komisches Verhalten festgestellt.
    Ich habe verschiedene ComboBoxen und je nachdem welche ich auswähle ändert sich die zweite ComboBox, dabei ist mir etwas aufgefallen:
    Wenn ich in dem Programm "Days of Ahoul" auswähle, dann nimmt er den Inhalt von "Pillars of Avalon". Dann habe ich erstmal alles auf die ComboBoxen geschoben und habe die Elemente bei jeder Änderung löschen und neu erstellen lassen. Als das auch nichts half habe ich einfach mal Debug "Console Writes" erstellt und siehe da:
    Oben steht ja if $SelectedItem = 2 Then ConsoleWrite(blablabla), aber das trifft nie ein. Das heißt eigentlich müsste ja dann unten in dem if Befehl die Schleife durch Days of Ahoul durchgehen, tut sie aber nicht.
    Dann ist mir noch weiterhin aufgefallen, dass wenn ich von "Siege of Avalon" die Maus ohne "Pillars of Avalon" zu berühren direkt auf "Days of Ahoul" schiebe, das Programm "Days of Ahoul" erkennt.
    Wieso ist mir schleierhaft, vieleicht könnt ihr mir helfen

    Spoiler anzeigen
    [autoit]


    $SelectedItem = 0
    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    ; $BackupPath = IniRead("ModToolConfig.ini","main","BackupPath",@ScriptDir & "\BackupFiles")
    ;$PoAInstalled = IniRead("ModToolConfig.ini","mods","PoAInstalled","error")
    ; $DoAInstalled = IniRead("ModToolConfig.ini","mods","DoAInstalled","error")
    ;$ActivatedGame = IniRead("ModToolConfig.ini","mods","ActivatedGame","error")
    $PoAInstalled = 0
    $DoAInstalled = 0
    ConsoleWrite($BackupPath & @CRLF & $PoAInstalled & @CRLF & $DoAInstalled & @CRLF & $ActivatedGame & @CRLF)
    ;If $PoAInstalled = "error" or $DoAInstalled = "error" or $ActivatedGame = "error" Then
    ; MsgBox(16,"SoA Mod Tool","ERROR, ini konnte nicht gelesen werden")
    ; Exit
    ;EndIf
    #Region ### START Koda GUI section ### Form=D:\Extras\Programmieren\AUTOIT\Koda Forms\SoA Mod Tool.kxf
    Global $Form_main1 = GUICreate("SoA Mod Tool", 679, 63, 238, 140)
    Global $Combo_main1 = GUICtrlCreateCombo("Siege of Avalon", 0, 24, 209, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1,"Pillars of Avalon|Days of Ahoul","")
    $Label_main1 = GUICtrlCreateLabel("Spiel auswählen", 56, 0, 119, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Label_main2 = GUICtrlCreateLabel("Kapitel auswählen", 264, 0, 132, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    Global $Combo_main2 = GUICtrlCreateCombo("Bitte wählen", 224, 24, 209, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetState(-1, $GUI_DISABLE)
    $Button_main1 = GUICtrlCreateButton("Installieren", 440, 24, 233, 33)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

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

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

    EndSwitch
    ;ConsoleWrite(GUICtrlRead($Combo_main1))
    If $SelectedItem = 2 Then
    ConsoleWrite($SelectedItem & @CRLF)
    EndIf
    If GUICtrlRead($Combo_main1) = 'Pillars of Avalon' and Not $SelectedItem = 1 Then
    ConsoleWrite("Pillars of Avalon" & @CRLF)
    GUICtrlSetState($Combo_main2,$GUI_ENABLE)
    If $PoAInstalled = 0 or $PoAInstalled = 1 Then
    GUICtrlDelete($Combo_main2)
    $Combo_main2 = GUICtrlCreateCombo("Kapitel 1", 224, 24, 209, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1,"Kapitel 2|Kapitel 3|Alle Kapitel")
    ElseIf $PoAInstalled = 2 Then
    GUICtrlDelete($Combo_main2)
    $Combo_main2 = GUICtrlCreateCombo("Kapitel 1+2", 224, 24, 209, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1,"Kapitel 3")
    ElseIf $PoAInstalled = 3 Then
    GUICtrlDelete($Combo_main2)
    $Combo_main2 = GUICtrlCreateCombo("Alle Kapitel", 224, 24, 209, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    Else
    MsgBox(16,"SoA Mod Tool","Ungültiger Install-Wert(hör auf an der ini rumzufummeln!")
    EndIf
    $SelectedItem = 1
    ElseIf GUICtrlRead($Combo_main1) = 'Days of Ahoul' and Not $SelectedItem = 2 Then
    ConsoleWrite("Days of Ahoul" & @CRLF)
    $SelectedItem = 2
    GUICtrlSetState($Combo_main2,$GUI_ENABLE)
    If $DoAInstalled = 0 or $DoAInstalled = 1 Then
    GUICtrlDelete($Combo_main2)
    $Combo_main2 = GUICtrlCreateCombo("Kapitel 1", 224, 24, 209, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1,"Kapitel 2|Alle Kapitel")
    ElseIf $DoAInstalled = 2 Then
    GUICtrlDelete($Combo_main2)
    $Combo_main2 = GUICtrlCreateCombo("Alle Kapitel", 224, 24, 209, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
    Endif
    ElseIf GuiCtrlRead($Combo_main1) = 'Siege of Avalon' and not $SelectedItem = 0 Then
    ConsoleWrite("Siege of Avalon" & @CRLF)
    $SelectedItem = 0
    GUICtrlSetState($Combo_main2,$GUI_DISABLE)
    GUICtrlSetState($Button_main1,$GUI_ENABLE)
    GUICtrlSetData($Button_main1,"Aktivieren")

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

    EndIf
    WEnd

    [/autoit]


    Mfg Fliwatt

  • Hallo Fliwatt,

    warum so eine starre (und offensichtlich fehleranfällige) Implementierung für 2 Comboboxen mit Abhängigkeit der 2. von der 1.?
    Hier ein kleines Beispiel mit Hilfe einer Textdatei, so dass bei Erweiterungen nur die Textdatei ergänzt werden muss:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GuiComboBox.au3>
    #include <GUIConstantsEx.au3>
    #include <array.au3>
    #include <File.au3>

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

    Const $sCSV = @ScriptDir & "\2cbo.TXT"
    Const $sElect = "bitte auswählen"
    Dim $a_sCSV, $aSplit, $scboChr = ""
    _FileReadToArray($sCSV, $a_sCSV)
    Dim $aCSV[$a_sCSV[0]][2]
    For $i = 1 To UBound($a_sCSV) - 1
    ConsoleWrite($i & $a_sCSV[$i] & @CRLF)
    $aSplit = StringSplit($a_sCSV[$i], ";")
    If Not StringInStr($scboChr, $aSplit[1]) Then $scboChr &= $aSplit[1] & "|"
    $aCSV[$i - 1][0] = $aSplit[1]
    $aCSV[$i - 1][1] = $aSplit[2]
    Next
    ConsoleWrite($scboChr & @CRLF)

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

    $hGui = GUICreate("2 Comboboxen aus 1er CSV", 250, 120, 302, 218)
    $hcboChr = GUICtrlCreateCombo($sElect, 8, 8, 200, 25)
    GUICtrlSetData(-1, $scboChr)
    $hcboChrNr = GUICtrlCreateCombo("", 8, 35, 200, 25)
    $hbtnExit = GUICtrlCreateButton("Be&enden", 8, 65)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE, $hbtnExit
    Exit
    Case $hcboChr
    $sVal = GUICtrlRead($hcboChr)
    GUICtrlSetData($hcboChrNr, "")
    If $sVal <> $sElect Then
    $aSplit = _ArrayFindAll($aCSV, $sVal, 0, 0, True, True, 0)
    $scboChr = ""
    For $i = 0 To UBound($aSplit) - 1
    $scboChr &= $aCSV[$aSplit[$i]][1] & "|"
    Next
    ConsoleWrite($scboChr & @CRLF)
    GUICtrlSetData($hcboChrNr, $scboChr)
    _GUICtrlComboBox_SetCurSel($hcboChrNr, 0)
    EndIf
    EndSwitch
    WEnd

    [/autoit]

    Und hier noch die benötigte Datei:autoit.de/wcf/attachment/18407/

    mfg autoBert

  • Hi Bugfix,
    erstmal danke für deine Antwort,
    mein Problem ist nur, dass die ComboBox auch entsprechend der Variablen änderbar seien muss und das ist mit der Textdatei nur schwer realisierbar.
    Zum Beispiel wenn $PoAInstalled = 3 ist dann soll nur der Eintrag "Alle Kapitel" erscheinen und weiterhin soll dann der Button von "Installieren" auf "Aktivieren" geschaltet werden können.
    Mfg Fliwatt

  • du kannst doch auch die Combobox im Case aufführen.
    Dann bekommst du mit, wann der Benutzer was ändert und musst nicht immer überprüfen.
    außerdem solltest du für die Comboboxen den Stil $CBS_DROPDOWNLIST benutzen.

    So in etwa :

    Spoiler anzeigen
    [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Combo_main1
    Local $sData = GUICtrlRead($Combo_main1)
    if ($sData = "Siege of Avalon")
    if ($SoAInstalled = 0) Then
    GUICtrlSetState($Button_main1, $GUI_ENABLE)
    ContinueLoop
    EndIf
    GUICtrlSetData($Combo_main2, "") ; Kapitel da rein
    GUICtrlSetState($Combo_main2, $GUI_ENABLE)
    Case $Combo_main2
    ;;;;;;;;; hier für Combo2
    Case $Button_main1
    ;;;;;;;; hier das für button rein
    EndSwitch
    WEnd

    [/autoit]
  • ja, das ist Zeile 8 ist ein Fehler.
    Hab es net ausprobiert , sondern nur so ungefähr geschrieben.
    Und ob man um Ifs Klammern setzt ist egal, aber ich mache es geschätzt zu 75%.