jameson Posted August 30, 2010 Share Posted August 30, 2010 (edited) Hy, I'm a new student. I just try to learn how to use a combobox on autoit and i have a big problem with it.. i can't imagine how it can read value from ini file. this is my problem, i'd like to make a combobox with more than 3 value so user can select one of it. and the script will automatically read / write into config.ini It's my unfinished work : expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $Checkbox_value; = true;false Global $Combo_value; = 1;2;3 Global $ini_save_file = @ScriptDir & "\config.ini" if FileExists($ini_save_file) = 0 then FileWrite($ini_save_file, "") IniWrite($ini_save_file, "Changes", "Checkbox_value", "false") IniWrite($ini_save_file, "Master", "Combo_value", "1") EndIf if IniRead($ini_save_file, "Options", "Checkbox_value", "true") = "true" Then $Checkbox_value = True Else $Checkbox_value = False EndIf if IniRead($ini_save_file, "Master", "Combo_value", "1") = "1" Then $Combo_value = 1 Else $Combo_value = 0 EndIf $Form = GUICreate("test", 203, 212, 192, 124) $Checkbox = GUICtrlCreateCheckbox("Checkbox", 12, 8, 157, 17) $Combo = GUICtrlCreateCombo("", 12, 32, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1,"1|2|3","1") GUISetState(@SW_SHOW) if $Checkbox_value = true Then GUICtrlSetState($Checkbox, $GUI_CHECKED) EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE If GUICtrlRead($Checkbox) = $GUI_CHECKED Then $Checkbox_value = true IniWrite($ini_save_file, "Options", "Checkbox_value", "true") Else $Checkbox_value = false IniWrite($ini_save_file, "Options", "Checkbox_value", "false") EndIf If GUICtrlRead($Combo) = Exit EndSwitch WEnd What should i do for next.. thank's.. Edited August 30, 2010 by jameson Link to comment Share on other sites More sharing options...
exodius Posted August 30, 2010 Share Posted August 30, 2010 (edited) If you want to read in the values from an ini file, do something like this: expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #Include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $Checkbox_value; = true;false Global $Combo_value; = 1;2;3 Global $ini_save_file = @ScriptDir & "\config.ini" If Not FileExists($ini_save_file) Then IniWrite($ini_save_file, "Changes", "Checkbox_value", "false") IniWrite($ini_save_file, "Master", "Combo_value1", "1") IniWrite($ini_save_file, "Master", "Combo_value2", "2") IniWrite($ini_save_file, "Master", "Combo_value3", "3") IniWrite($ini_save_file, "Master", "Combo_value4", "4") IniWrite($ini_save_file, "Master", "Combo_value5", "5") IniWrite($ini_save_file, "Master", "Combo_value6", "6") IniWrite($ini_save_file, "Master", "Combo_value7", "7") EndIf If IniRead($ini_save_file, "Options", "Checkbox_value", "true") = "true" Then $Checkbox_value = True Else $Checkbox_value = False EndIf If IniRead($ini_save_file, "Master", "Combo_value", "1") = "1" Then $Combo_value = 1 Else $Combo_value = 0 EndIf $Form = GUICreate("test", 203, 212, 192, 124) $Checkbox = GUICtrlCreateCheckbox("Checkbox", 12, 8, 157, 17) $Combo = GUICtrlCreateCombo("", 12, 32, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) _ReadComboOptions_FromINI() GUISetState(@SW_SHOW) If $Checkbox_value = True Then GUICtrlSetState($Checkbox, $GUI_CHECKED) EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE If GUICtrlRead($Checkbox) = $GUI_CHECKED Then $Checkbox_value = True IniWrite($ini_save_file, "Options", "Checkbox_value", "true") Else $Checkbox_value = False IniWrite($ini_save_file, "Options", "Checkbox_value", "false") EndIf Exit EndSwitch WEnd Func _ReadComboOptions_FromINI() _GUICtrlComboBox_ResetContent($Combo) $aComboOptions = IniReadSection ($ini_save_file, "Master") For $x = 1 to $aComboOptions[0][0] GUICtrlSetData ($Combo, $aComboOptions[$x][1]) Next EndFunc Edited August 30, 2010 by exodius Link to comment Share on other sites More sharing options...
jameson Posted August 30, 2010 Author Share Posted August 30, 2010 If you want to read in the values from an ini file, do something like this: expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #Include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $Checkbox_value; = true;false Global $Combo_value; = 1;2;3 Global $ini_save_file = @ScriptDir & "\config.ini" If Not FileExists($ini_save_file) Then IniWrite($ini_save_file, "Changes", "Checkbox_value", "false") IniWrite($ini_save_file, "Master", "Combo_value1", "1") IniWrite($ini_save_file, "Master", "Combo_value2", "2") IniWrite($ini_save_file, "Master", "Combo_value3", "3") IniWrite($ini_save_file, "Master", "Combo_value4", "4") IniWrite($ini_save_file, "Master", "Combo_value5", "5") IniWrite($ini_save_file, "Master", "Combo_value6", "6") IniWrite($ini_save_file, "Master", "Combo_value7", "7") EndIf If IniRead($ini_save_file, "Options", "Checkbox_value", "true") = "true" Then $Checkbox_value = True Else $Checkbox_value = False EndIf If IniRead($ini_save_file, "Master", "Combo_value", "1") = "1" Then $Combo_value = 1 Else $Combo_value = 0 EndIf $Form = GUICreate("test", 203, 212, 192, 124) $Checkbox = GUICtrlCreateCheckbox("Checkbox", 12, 8, 157, 17) $Combo = GUICtrlCreateCombo("", 12, 32, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) _ReadComboOptions_FromINI() GUISetState(@SW_SHOW) If $Checkbox_value = True Then GUICtrlSetState($Checkbox, $GUI_CHECKED) EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE If GUICtrlRead($Checkbox) = $GUI_CHECKED Then $Checkbox_value = True IniWrite($ini_save_file, "Options", "Checkbox_value", "true") Else $Checkbox_value = False IniWrite($ini_save_file, "Options", "Checkbox_value", "false") EndIf Exit EndSwitch WEnd Func _ReadComboOptions_FromINI() _GUICtrlComboBox_ResetContent($Combo) $aComboOptions = IniReadSection ($ini_save_file, "Master") For $x = 1 to $aComboOptions[0][0] GUICtrlSetData ($Combo, $aComboOptions[$x][1]) Next EndFunc Owh, that not the point i'm looking. i mean, my problem just more simple. like this : #include <ButtonConstants.au3> #include <ComboConstants.au3> #Include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $Checkbox_value; = true;false Global $Combo_value; = 1;2;3 Global $ini_save_file = @ScriptDir & "\config.ini" If Not FileExists($ini_save_file) Then IniWrite($ini_save_file, "Master", "Combo_value1", "1") EndIf $Form = GUICreate("test", 203, 212, 192, 124) $Combo = GUICtrlCreateCombo("", 12, 32, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1,"1|2|3","1") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd there is already 3 option on the combo box, i just need to keep my changes on ini file. then when i open it first time, it will select the default value (in this case is "1") and i change it to "2" by selecting the value on the combo box, then when i close it.. << this is what i'm looking for, i need to keep my changes on config.ini so when i open the program back, i'll see, the value is not "1" anymore, but "2" cause i was change it before. i only need to keep my changes. not keep all of my value on config.ini sorry for my bad english, and sorry if i make you confused. ^,^ i just try to explain what i need. coz i'm not really good in english. Thank's.. Link to comment Share on other sites More sharing options...
exodius Posted August 30, 2010 Share Posted August 30, 2010 I gotcha, something like this then: #include <ButtonConstants.au3> #include <ComboConstants.au3> #Include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $Checkbox_value; = true;false Global $Combo_value; = 1;2;3 Global $ini_save_file = @ScriptDir & "\config.ini" If Not FileExists($ini_save_file) Then IniWrite($ini_save_file, "Master", "Combo_value1", "1") EndIf $Form = GUICreate("test", 203, 212, 192, 124) $Combo = GUICtrlCreateCombo("", 12, 32, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1,"1|2|3") _GUICtrlComboBox_SelectString($Combo, IniRead($ini_save_file, "Master", "Combo_value1", "")) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE IniWrite ($ini_save_file, "Master", "Combo_value1", GUICtrlRead ($Combo)) Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
jameson Posted August 30, 2010 Author Share Posted August 30, 2010 wow, thank you master.. it is what i looking for.. thank's.. ^^ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now