BitByte Posted September 4, 2009 Posted September 4, 2009 I'm new to AutoIt and i'm still learning on it. i got problem in read/write for a checkbox. need advice. #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Checkbox1 = IniRead("myfile.ini", "section2", "key", "1") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 141, 47, 192, 124) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 14, 14, 97, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE inwrite() Exit EndSwitch WEnd func inwrite() IniWrite("myfile.ini", "section2", "key", GUICtrlRead($Checkbox1)) EndFunc can someone guide me and correct my error? thank you
Moderators Melba23 Posted September 4, 2009 Moderators Posted September 4, 2009 BitByte,I presume you want to save the state of your checkbox to the ini file and then read in the value to reset the checkbox on start. The code you have is nearly there... Let us talk about the IniWrite first. When you use GUICtrlRead on a Checkbox it returns the state of the checkbox, which can be a whole range of numbers - look in the Help file for GUICtrlRead. So we really need to extract the checked/unchecked value from this composite with BitAND. You code it like this:If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then $CheckboxChecked = 1 Else $CheckboxChecked = 0 EndIfI know it looks overcomplicated, but it is the only way when you deal with states. Then when you write your ini file, you use $CheckboxChecked as the value and you get 1 = checked, 0 = unchecked.So, now we have the ini file written in a way we can use, let us look at how we can get the checkbox to reflect the ini value on start. Alas, your $Checkbox1 = IniRead line will not work! We need to get the stored value into a variable and then tell the checkbox what state to adopt. Take a look at this version of your code:#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Initial_State = IniRead("myfile.ini", "section2", "key", "1") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 141, 47, 192, 124) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 14, 14, 97, 17) If $Initial_State = 1 Then GUICtrlSetState($Checkbox1, $GUI_CHECKED) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE inwrite() Exit EndSwitch WEnd Func inwrite() If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then $CheckboxChecked = 1 Else $CheckboxChecked = 0 EndIf IniWrite("myfile.ini", "section2", "key", $CheckboxChecked) EndFunc ;==>inwriteI hope everything is clear - please ask if not.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
BitByte Posted September 5, 2009 Author Posted September 5, 2009 thanks a lot.. that what i need. now i'm clear
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