thawee Posted April 25, 2010 Share Posted April 25, 2010 (edited) Hi, All I have been working on saving check box states to a configuration file. I have noticed that what is save is neither 0 or a 1. The problem I am having is I want to read the data in from the config file, and set the check box state back to what it was after the check boxes were checked or not checked. For example IniWrite("C:\Config.txt","Section1","sec1",$Checkbox1) $Checkbox1 = IniRead("C:\Config.txt","Section1","sec1",$Checkbox1) Is there anything more i need to do to set the state of the check box to checked. Please advise, Thanks Thawee Edited April 25, 2010 by thawee Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 25, 2010 Moderators Share Posted April 25, 2010 thawee,You are saving the ControlID of the checkbox, not its state. When you create a control, AutoIt returns its ControlID, an integer value you then use to identify the control. If you want to know the state of a control, you need to use GUIGetState.Here is a short example to help you see what I mean:#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $hButton_1 = GUICtrlCreateButton("Test", 10, 10, 80, 30) ; $hButton is the ControlId $hCheckBox = GUICtrlCreateCheckBox(" Check me!", 10, 80, 100, 20) $hButton_2 = GUICtrlCreateButton("Read", 10, 110, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 ; The ControlID is used here MsgBox(0, "ControlID", "The ControlID of this button is " & $hButton_1) Case $hButton_2 ; The ControlID is used here $sMsg = "The ControlID of this button is " & $hButton_2 & @CRLF & @CRLF & _ "The state of the checkbox is " & GUICtrlRead($hCheckBox) ; Read the STATE of the checkbox MsgBox(0, "ControlID", $sMsg) EndSwitch WEndSo you need to save the return value from GUICtrlRead and then use that value with GUICtrlSetState to get it as it was.Ask if anything is unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
thawee Posted April 25, 2010 Author Share Posted April 25, 2010 (edited) Thanks for the reply! So, I would assume that to write the state of the Check box to a ini file I would need to do something similar to this. $CBox-State = GUICtrlRead($hCheckBox) ; Writing IniWrite("C:\Config.txt","Section1","sec1",$CBox-State) ; Reading and setting state $CBox-State = IniRead("C:\Config.txt","Section1","sec1","Not Found") GuictrlSetState($hCheckBox,$CBox-State) Does that seem like what would need to happen to successfully preserve the state of a check box in a ini file? Edited April 25, 2010 by thawee Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 25, 2010 Moderators Share Posted April 25, 2010 thawee, Have you tried? M23 Fix the syntax errors and it should work! Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
thawee Posted April 25, 2010 Author Share Posted April 25, 2010 Not yet, I will give it a shot, and let you know the results. thx Link to comment Share on other sites More sharing options...
GEOSoft Posted April 25, 2010 Share Posted April 25, 2010 (edited) Here's another little trick for you $CBox_State = BitAND(GUICtrlGetState($hCheckBox), $GUI_Checked) = $GUI_Checked IniWrite("C:\Config.txt","Section1","sec1",$CBox_State) That will write it as 1 or 0 Then you can just use $CBox_State = IniRead("C:\Config.txt","Section1","sec1","") If $CBox_State Then GuictrlSetState($hCheckBox,$CBox_State) Note: You can't use a hyphen in a variable name, stick with letters, digits or the underscore character for best success. EDIT: Fix the spellink before M23 has something to pick on me about. Edited April 25, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
RogerH Posted May 28, 2010 Share Posted May 28, 2010 Thawee, I'm having the same questions... I think this part (cleaned up of course) would be more elegant than doing another conversion... how did this turn out? I'm leaning toward doing it into the registry, but otherwise I'd like to do the same thing. Thanks for the reply! So, I would assume that to write the state of the Check box to a ini file I would need to do something similar to this. $CBox-State = GUICtrlRead($hCheckBox) ; Writing IniWrite("C:\Config.txt","Section1","sec1",$CBox-State) ; Reading and setting state $CBox-State = IniRead("C:\Config.txt","Section1","sec1","Not Found") GuictrlSetState($hCheckBox,$CBox-State) Does that seem like what would need to happen to successfully preserve the state of a check box in a ini file? Link to comment Share on other sites More sharing options...
GEOSoft Posted May 28, 2010 Share Posted May 28, 2010 It should be working but I just noticed a mistake in the code he posted back $CBox-State = IniRead("C:\Config.txt","Section1","sec1","Not Found") GuictrlSetState($hCheckBox,$CBox-State) Would be better as $CBox-State = IniRead("C:\Config.txt","Section1","sec1", 4);; Set a default value here GuictrlSetState($hCheckBox,$CBox-State) OR $CBox-State = IniRead("C:\Config.txt","Section1","sec1", 0);; Set a default value of 0 here If $CBox-State Then GuictrlSetState($hCheckBox,$CBox-State) Also If I were you, I would try to avoid the registry. It already becomes bloated enough as it is so it's prone to being a bit slower and remember most of that registry will also be read at system startup whether or not it's needed. I would stay with the ini and in order to avoid write permission issues store the ini in @AppDataDir or @AppDataCommonDir George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" 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