Zobu Posted January 13, 2021 Posted January 13, 2021 Hi Guys, I want to set the state of the Checkboxes automatically if the .ini from the Combobox is selected the script underneath is just an example first combobox item = checkbox 1 is checked second combobox item = checkbox 2 is checked third combobox item = checkbox 3 is checked ( I know how to insert .ini in the combobox , i just want to read and set the data from the ini if selcted in combobox) #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 254, 124) $Combo1 = GUICtrlCreateCombo("Combo1", 40, 16, 249, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 40, 40, 121, 33) $Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 40, 72, 105, 25) $Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 40, 96, 113, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd i hope someone can help me with that
Nine Posted January 13, 2021 Posted January 13, 2021 What have you tried so far ? In your example, the combo box is not even filled. I would like to see you make an attempt to solve your problem. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Zobu Posted January 13, 2021 Author Posted January 13, 2021 hey Nine, as u can see i managed the save a file and load a file part but i want to load the file with selcting them from the combobox so without an extra button. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> #include <GuiButton.au3> #include <GUiConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 254, 124) Global Const $aChecked[2] = [$GUI_UNCHECKED, $GUI_CHECKED] Global $Combo = GUICtrlCreateCombo("No Selection", 40, 16, 150, 25) _GUICtrlComboBox_BeginUpdate($Combo) _GUICtrlComboBox_AddDir($Combo, @ScriptDir & "\testAction" & "\*.ini") _GUICtrlComboBox_EndUpdate($Combo) Global $Check1 = GUICtrlCreateCheckbox("Checkbox1", 40, 40, 121, 33) Global $Check2 = GUICtrlCreateCheckbox("Checkbox2", 40, 72, 105, 25) Global $Check3 = GUICtrlCreateCheckbox("Checkbox3", 40, 96, 113, 33) Global $B1 = GUICtrlCreateButton("Save Selection", 40, 150) Global $B2 = GUICtrlCreateButton("Load Selection", 150, 150) #EndRegion ### END Koda GUI section ### GUISetState(@SW_SHOW, $Form1) _createDir() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $B1 save() Case $B2 load() EndSwitch WEnd Func _IsChecked($iCtrl) Return BitAND(GUICtrlRead($iCtrl), 1) = 1 EndFunc ;==>_IsChecked Func _createDir() Local Const $sFilePath = @ScriptDir & "\testAction" If FileExists($sFilePath) Then Return False EndIf DirCreate($sFilePath) EndFunc ;==>_createDir Func save() Local $ini_file, $workingdir Local Const $sFilePath = @ScriptDir & "\testAction" $workingdir = @WorkingDir $ini_file = FileSaveDialog('Save', $sFilePath, 'Ini (*.ini)|All (*.*)', 1, 'Selection', $Form1) If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf #Region ; Checkboxes IniWrite IniWrite($ini_file, "Checkbox", "1", _IsChecked($Check1)) IniWrite($ini_file, "Checkbox", "2", _IsChecked($Check2)) IniWrite($ini_file, "Checkbox", "3", _IsChecked($Check3)) #EndRegion ; Checkboxes IniWrite FileChangeDir($workingdir) EndFunc ;==>save Func load() Local $ini_file, $workingdir Local Const $sFilePath = @ScriptDir & "\testAction" $workingdir = @WorkingDir $ini_file = FileOpenDialog('Open', $sFilePath, 'Ini (*.ini)|All (*.*)', 1, 'Selection', $Form1) If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf #Region ; Checkboxes IniRead $iniValue = _Bool(IniRead($ini_file, "Checkbox", "1", False)) GUICtrlSetState($Check1, $aChecked[$iniValue]) $iniValue = _Bool(IniRead($ini_file, "Checkbox", "2", False)) GUICtrlSetState($Check2, $aChecked[$iniValue]) $iniValue = _Bool(IniRead($ini_file, "Checkbox", "3", False)) GUICtrlSetState($Check3, $aChecked[$iniValue]) #EndRegion ; Checkboxes IniRead FileChangeDir($workingdir) EndFunc Func _Bool($data) If Not IsString($data) Then Return $data = True If (StringIsDigit($data) Or StringIsFloat($data)) And Number($data) > 0 Then Return True Switch StringLower($data) Case "true", "j", "y", "yes", "ja" Return True Case Else Return False EndSwitch EndFunc ;==>_Bool
Subz Posted January 13, 2021 Posted January 13, 2021 Maybe something like: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> #include <GuiButton.au3> #include <GUiConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 254, 124) Global Const $aChecked[2] = [$GUI_UNCHECKED, $GUI_CHECKED] Global $sCombo, $sIniDir = @ScriptDir & "\testAction" Global $Combo = GUICtrlCreateCombo("No Selection", 40, 16, 150, 25) _GUICtrlComboBox_BeginUpdate($Combo) _GUICtrlComboBox_AddDir($Combo, $sIniDir & "\*.ini") _GUICtrlComboBox_EndUpdate($Combo) Global $Check1 = GUICtrlCreateCheckbox("Checkbox1", 40, 40, 121, 33) Global $Check2 = GUICtrlCreateCheckbox("Checkbox2", 40, 72, 105, 25) Global $Check3 = GUICtrlCreateCheckbox("Checkbox3", 40, 96, 113, 33) Global $B1 = GUICtrlCreateButton("Save Selection", 40, 150) Global $B2 = GUICtrlCreateButton("Load Selection", 150, 150) #EndRegion ### END Koda GUI section ### GUISetState(@SW_SHOW, $Form1) _createDir() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $B1 $sCombo = GUICtrlRead($Combo) If $sCombo = "No Selection" Then $sCombo = "" save($sCombo) Case $Combo $sCombo = GUICtrlRead($Combo) If $sCombo = "No Selection" Then $sCombo = "" load($sCombo) Case $B2 $sCombo = GUICtrlRead($Combo) If $sCombo = "No Selection" Then $sCombo = "" load($sCombo) EndSwitch WEnd Func _IsChecked($iCtrl) Return BitAND(GUICtrlRead($iCtrl), 1) = 1 EndFunc ;==>_IsChecked Func _createDir() Local Const $sFilePath = @ScriptDir & "\testAction" If FileExists($sFilePath) Then Return False EndIf DirCreate($sFilePath) EndFunc ;==>_createDir Func save($_sIniFile = "") Local $sIniFile = $sIniDir & "\" & $_sIniFile If $sIniFile = $sIniDir & "\" Then Local Const $sFilePath = @ScriptDir & "\testAction" $sIniFile = FileSaveDialog('Save', $sFilePath, 'Ini (*.ini)|All (*.*)', 1, 'Selection', $Form1) If @error Or $sIniFile == '' Then Return SetError(1, 0, '') EndIf EndIf #Region ; Checkboxes IniWrite IniWrite($sIniFile, "Checkbox", "1", _IsChecked($Check1)) IniWrite($sIniFile, "Checkbox", "2", _IsChecked($Check2)) IniWrite($sIniFile, "Checkbox", "3", _IsChecked($Check3)) #EndRegion ; Checkboxes IniWrite EndFunc ;==>save Func load($_sIniFile = "") Local $sIniFile = $sIniDir & "\" & $_sIniFile If $sIniFile = $sIniDir & "\" Then Local Const $sFilePath = @ScriptDir & "\testAction" $sIniFile = FileOpenDialog('Open', $sFilePath, 'Ini (*.ini)|All (*.*)', 1, 'Selection', $Form1) If @error Or $sIniFile == '' Then Return SetError(1, 0, '') EndIf EndIf #Region ; Checkboxes IniRead $iniValue = _Bool(IniRead($sIniFile, "Checkbox", "1", False)) GUICtrlSetState($Check1, $aChecked[$iniValue]) $iniValue = _Bool(IniRead($sIniFile, "Checkbox", "2", False)) GUICtrlSetState($Check2, $aChecked[$iniValue]) $iniValue = _Bool(IniRead($sIniFile, "Checkbox", "3", False)) GUICtrlSetState($Check3, $aChecked[$iniValue]) #EndRegion ; Checkboxes IniRead EndFunc Func _Bool($data) If Not IsString($data) Then Return $data = True If (StringIsDigit($data) Or StringIsFloat($data)) And Number($data) > 0 Then Return True Switch StringLower($data) Case "true", "j", "y", "yes", "ja" Return True Case Else Return False EndSwitch EndFunc ;==>_Bool
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