Jump to content

Save Checkbox Status on ini file and read it - (Moved)


Recommended Posts

Hi There, 

I seek your help on the following issue, I have a GUI where a bunch of inputs will be saved on ini file (setting.ini)

I am getting an issue to save the checked Checkbox  state and then read it from ini file. other data got reflected when the gui is called to be edited except Checkbox Status remains always unchecked even it was saved as checked in ini file  

Data are saved as 1 or 4 which is correct but I want the box state to be saved as $GUI_CHECKED or $GUI_UNCHECKED also

Below is  logic of  saving the value of check box. (Extract of target code only)

 

While 1
        Other condition of code here

xxx
xxx
xx


                    Case $Button_SaveSettings; By pressing save button below variable data will be saved In ini file 
                       Global $collect_Checkbox1 = GUICtrlRead($Checkbox1)
                    
                       IniWrite($IniFile, "Data", "Status ", $collect_Checkbox1); save the input in ini file
                       


                       GUIDelete($Setting_GUI)
                       GUICtrlSetState($ButtonSetting, $GUI_ENABLE)


                EndSwitch
        EndSwitch
    WEnd
EndFunc   ;

Func Settingform()

xxxx
xxxx

$IniFile = @ScriptDir & "\Setting.ini"
Global $Read_Checkbox1 = IniRead($IniFile, "Data", "Status ", ""); Read from Ini file and reflect it on Setting for GUI

$AdditionalOption = GUICtrlCreateLabel("Take snapshot and save picture", 40, 434, 165, 17); Label
$Checkbox1 = GUICtrlCreateCheckbox($Read_Checkbox1, 24, 434, 17, 17)
GUICtrlSetState($Checkbox1, $GUI_UNCHECKED); Unchecked by default


Other code part 
xxx
xxx

Any help is really appreciated 

 

Mike

checkbox.png

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

I'm using following functions with the checkboxes:

Func _IsChecked($idControlID)
    ;Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED     ;Returns true or false (oneliner)
    ;The lines below convert true and false to numbers - 1 and 0
    local $x=BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
    If $x = True Then Return 1
    Return 0
EndFunc   ;==>_IsChecked

Func _CheckUncheck($id, $nr)
    If $nr = 0 Then
        GUICtrlSetState($id, $GUI_UNCHECKED)
    Else
        GUICtrlSetState($id, $GUI_CHECKED)
    EndIf
EndFunc   ;==>_CheckUncheck

eventually (additionally to the @mikell's change) you should change the default value of the following line

Global $Read_Checkbox1 = IniRead($IniFile, "Data", "Status ", ""); Read from Ini file and reflect it on Setting for GUI

If the Ini file is not available then you may want to have the last , "" changed into True/False or 1/0 depending which value type you are using.

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Hi Guys, 

Sorry Melba 23 for posting on the wrong category. 

Mikemell: It worked perfectly, It is so simple and I don't understand how I miss it :blink: Thank you Man:bye:

Dan_555: Your function will fit a combo box I have also with slight modification. 

 

Thank you guys, you really saved my day! Great Autoit and great contributors

 

Mike

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...