Sign in to follow this  
Followers 0
BitByte

need help in iniread/write and GUICtrlCreateCheckbox

3 posts in this topic

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

Share this post


Link to post
Share on other sites



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... :D

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
EndIf

I 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! :D 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   ;==>inwrite

I 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

thanks a lot.. that what i need. now i'm clear :D

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0