daten aus ini-datei in combo

  • hallo ich mal wieder.. ;)

    es geht um folgendes:

    in eine eine combo soll man beliebige werte eintragen können
    ein "safe" button ermittelt den wert in der combo und speichert ihn in einer ini-datei
    beim öffnen der ini sollen alle in der ini gespeicherten werte als auswahlmöglichkeit sein

    ist dies möglich?
    wenn ja, wie würdet ihr diese sache angehn?

    ich danke euch schon jetzt herzlich

    gruß Inferior

    Einmal editiert, zuletzt von Inferior (3. Juli 2010 um 00:03)

  • danke schon mal stayawayknight,

    sehr nett:)
    also wie das mit der ini geht weiß ich und auch wie man etwas ausließt
    nur ich bekomm das nicht gebacken vor allem mit der aktualliserung

    man hat also dann 2 eingabefelder? input und combo
    hmm nicht sehr praktisch für mich aber es wäre zumindest ein anfang

    gruß Inferior

    PS: ach ja, an sich muss es gar keine ini-datei sein... es kann auch eine txt oder sonst was sein.. ich dachte nur ini sei besser..

    • Offizieller Beitrag

    Hier mal ein Beispiel, wo man die Daten in das Combo-Control einträgt:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    Global $sInifile = @ScriptDir & '\prog.ini'
    Global $sComboContent = IniRead($sInifile, 'Config', 'Combo', '')
    GUICreate('Test', 280, 80)
    $hCombo = GUICtrlCreateCombo('', 10, 10, 200, 20)
    GUICtrlSetData(-1, $sComboContent)
    $hSave = GUICtrlCreateButton('Save', 211, 10, 60, 20)
    GUISetState()
    While True
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    Case $hSave
    $sTmp = GUICtrlRead($hCombo)
    $sComboContent &= '|' & $sTmp
    IniWrite($sInifile, 'Config', 'Combo', $sComboContent)
    GUICtrlSetData($hCombo, $sComboContent, $sTmp)
    EndSwitch
    WEnd

    [/autoit]
  • Hier wär meins:

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <File.au3>

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

    $Form1 = GUICreate("Form1", 615, 438, 192, 124)
    $Combo1 = GUICtrlCreateCombo("", 24, 160, 297, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
    $Input1 = GUICtrlCreateInput("Gib was ein", 384, 160, 185, 21)
    $Button1 = GUICtrlCreateButton("Safe", 384, 216, 185, 41)
    GUISetState(@SW_SHOW)

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

    refresh()

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

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If FileExists(@ScriptDir & "\test.ini") Then
    $number = IniReadSectionNames(@ScriptDir & "\test.ini")
    IniWrite(@ScriptDir & "\test.ini", "Combo", $number[0] + 1, GUICtrlRead($Input1))
    Else
    IniWrite(@ScriptDir & "\test.ini", "Combo", 1, GUICtrlRead($Input1))
    EndIf
    refresh()

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

    EndSwitch
    WEnd

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

    Func refresh()
    GUICtrlSetData($Combo1, "")
    If FileExists(@ScriptDir & "\test.ini") Then
    For $i = 1 To _FileCountLines(@ScriptDir & "\test.ini") - 1
    $read = IniRead(@ScriptDir & "\test.ini", "Combo", $i, "")
    GUICtrlSetData($Combo1, $read & "|")

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

    Next
    EndIf
    EndFunc ;==>refresh

    [/autoit]
  • vielen dank an euch beide oscar das ist genau das was ich gesucht hab!!
    funktioniert mehr als klasse und das so einfach gehalten
    und vor allem in einer combo

    dennoch herzlichen dank auch an dich stayawayknight
    deines ist bisschen umständlicher und irgendwie kommt das script auch glaub ich nicht damit klar wenn man manuell etwas in die combo schreibt und versucht zu save´en

    mir stellt sich noch eine frage:
    bei inbut-boxen kann man mit dem style relativ einfach festlegen, dass man dort nur zahlen eingeben kann (mit $ES_NUMBER)
    jedoch kann ich nichts finden wie man die combo einschränken kann
    weißt das jemand zufällig?

    • Offizieller Beitrag

    Hier eine erweiterte Version (nur Zahlen bei der Eingabe erlaubt):

    Spoiler anzeigen
    [autoit]


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

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

    Global $sInifile = @ScriptDir & '\prog.ini'
    Global $sComboContent = IniRead($sInifile, 'Config', 'Combo', '')
    GUICreate('Test', 280, 80)
    $hCombo = GUICtrlCreateCombo('', 10, 10, 200, 20)
    GUICtrlSetData(-1, $sComboContent)
    $hSave = GUICtrlCreateButton('Save', 211, 10, 60, 20)
    GUISetState()
    GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
    While True
    If GUICtrlRead($hCombo) <> '' Then
    If BitAND(GUICtrlGetState($hSave), $GUI_DISABLE) Then GUICtrlSetState($hSave, $GUI_ENABLE)
    Else
    If BitAND(GUICtrlGetState($hSave), $GUI_ENABLE) Then GUICtrlSetState($hSave, $GUI_DISABLE)
    EndIf
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    Case $hSave
    $sTmp = GUICtrlRead($hCombo)
    If $sComboContent <> '' Then $sComboContent &= '|'
    $sComboContent &= $sTmp
    IniWrite($sInifile, 'Config', 'Combo', $sComboContent)
    GUICtrlSetData($hCombo, '')
    GUICtrlSetData($hCombo, $sComboContent, $sTmp)
    EndSwitch
    WEnd

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

    Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $nNotifyCode, $nID
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $hCombo And $nNotifyCode = 5 Then _GUICtrlComboBox_SetEditText($hCombo, StringRegExpReplace(GUICtrlRead($hCombo), '[^0-9]', ''))
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit]
  • wow klasse oscar funktioniert wieder mal optimal ;)

    ich mächte ja nicht all zu viele ansprüche stellen aber
    wäre es ein großer aufwand die zahlen die man letztendlich eingeben darf auf max. 6 zu beschränken?

    • Offizieller Beitrag

    Dazu muss man nur einen weiteren Befehl einfügen:

    Spoiler anzeigen
    [autoit]


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

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

    Global $sInifile = @ScriptDir & '\prog.ini'
    Global $sComboContent = IniRead($sInifile, 'Config', 'Combo', '')
    GUICreate('Test', 280, 80)
    $hCombo = GUICtrlCreateCombo('', 10, 10, 200, 20)
    GUICtrlSetData(-1, $sComboContent)
    $hSave = GUICtrlCreateButton('Save', 211, 10, 60, 20)
    GUISetState()
    GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
    While True
    If GUICtrlRead($hCombo) <> '' Then
    If BitAND(GUICtrlGetState($hSave), $GUI_DISABLE) Then GUICtrlSetState($hSave, $GUI_ENABLE)
    Else
    If BitAND(GUICtrlGetState($hSave), $GUI_ENABLE) Then GUICtrlSetState($hSave, $GUI_DISABLE)
    EndIf
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    Case $hSave
    $sTmp = GUICtrlRead($hCombo)
    If $sComboContent <> '' Then $sComboContent &= '|'
    $sComboContent &= $sTmp
    IniWrite($sInifile, 'Config', 'Combo', $sComboContent)
    GUICtrlSetData($hCombo, '')
    GUICtrlSetData($hCombo, $sComboContent, $sTmp)
    EndSwitch
    WEnd

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

    Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $nNotifyCode, $nID
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $hCombo And $nNotifyCode = 5 Then _GUICtrlComboBox_SetEditText($hCombo, StringRegExpReplace(StringLeft(GUICtrlRead($hCombo), 6), '[^0-9]', ''))
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit]
  • hallo oscar,

    sry für die späte antwort! wirklich genial. konnte das in meinem script einmanfrei mit einbauen.
    funktioniert genau so wie ich es mir vorgestellt hab
    ganz großes lob an dich

    gruß Inferior