Sign in to follow this  
Followers 0
historypsi

Help with checkboxes and ini files

7 posts in this topic

Hello,

I'm trying to create a checklist that when saved will go to an ini file. No problem, that much I can get. The problem i'm running into is when I reopen the checklist I can't get the $GUI_Checked to work based on the INI file.

Say I have a GUI asking if the trash has been taken out. I have a check box labeled yes and on labeled no. When the yes is checked the output to the INI file is:

[Trash]

Yes=1

No=4

But how do I bring the list back up with the box checked?

Share this post


Link to post
Share on other sites



example

#include <GUIConstants.au3>

Global $start
Global $way1x, $way1y
$showGUI = 0 ; setting the GUI condition

HotKeySet("{F6}", "show") ; using hotkey to show menu

Read()

GUICreate("Testscript", 300, 420)
$savebotbutt = GUICtrlCreateButton("Save", 160, 390, 60, 30) ; show the Save button
$exitbotbutt = GUICtrlCreateButton("Exit", 220, 390, 80, 30) ; show the Exit button
GUICtrlCreateTab(0, 0, 300, 390)
$tab2 = GUICtrlCreateTabItem("WayPoints")
GUICtrlCreateLabel("Training Ground Location", 10, 30, 200, 20)
$checkCN = GUICtrlCreateCheckbox("", 20, 50, 20, 20) ; 1st checkbox location
GUICtrlCreateLabel("X : ", 60, 50, 15, 20)
;~ $way1x = Int(IniRead(".\testscript.ini","Waypoints","1x","-1"))
$input_x = GUICtrlCreateInput($way1x, 80, 50, 50, 20)
GUICtrlCreateLabel("Y : ", 150, 50, 15, 20)
;~ $way1y = Int(IniRead(".\testscript.ini","Waypoints","1y","-1"))
$input_y = GUICtrlCreateInput($way1y, 170, 50, 50, 20)
GUISetState(@SW_HIDE)


While 1 ; main body of program, loop till condition met
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE ; when the top right cancel button is pressed
            Exit
        Case $msg = $savebotbutt ; pressing the Save button
            Write()
            MsgBox(64, "Test Box", "You clicked on Save!")
        Case $msg = $exitbotbutt ; pressing the Exit button
            Exit
    EndSelect
WEnd

;;-------------------------------------- Functions --------------------------------

Func show()
    If $showGUI = 0 Then
        Read()
        GUISetState(@SW_SHOW) ; show the menu when hotkey pressed
        $showGUI = 1
    Else
        GUISetState(@SW_HIDE) ; hide the menu when hotkey pressed
        $showGUI = 0
    EndIf
EndFunc   ;==>show

Func Write()
    IniWrite(".\testscript.ini", "Waypoints", "1x", GUICtrlRead($input_x))
    IniWrite(".\testscript.ini", "Waypoints", "1y", GUICtrlRead($input_y))
EndFunc   ;==>Write

Func Read()
    $way1x = Int(IniRead(".\testscript.ini", "Waypoints", "1x", "-1"))
    $way1y = Int(IniRead(".\testscript.ini", "Waypoints", "1y", "-1"))
EndFunc   ;==>Read

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

example

#include <GUIConstants.au3>

Global $start
Global $way1x, $way1y
$showGUI = 0 ; setting the GUI condition

HotKeySet("{F6}", "show") ; using hotkey to show menu

Read()

GUICreate("Testscript", 300, 420)
$savebotbutt = GUICtrlCreateButton("Save", 160, 390, 60, 30) ; show the Save button
$exitbotbutt = GUICtrlCreateButton("Exit", 220, 390, 80, 30) ; show the Exit button
GUICtrlCreateTab(0, 0, 300, 390)
$tab2 = GUICtrlCreateTabItem("WayPoints")
GUICtrlCreateLabel("Training Ground Location", 10, 30, 200, 20)
$checkCN = GUICtrlCreateCheckbox("", 20, 50, 20, 20) ; 1st checkbox location
GUICtrlCreateLabel("X : ", 60, 50, 15, 20)
;~ $way1x = Int(IniRead(".\testscript.ini","Waypoints","1x","-1"))
$input_x = GUICtrlCreateInput($way1x, 80, 50, 50, 20)
GUICtrlCreateLabel("Y : ", 150, 50, 15, 20)
;~ $way1y = Int(IniRead(".\testscript.ini","Waypoints","1y","-1"))
$input_y = GUICtrlCreateInput($way1y, 170, 50, 50, 20)
GUISetState(@SW_HIDE)
While 1 ; main body of program, loop till condition met
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE ; when the top right cancel button is pressed
            Exit
        Case $msg = $savebotbutt ; pressing the Save button
            Write()
            MsgBox(64, "Test Box", "You clicked on Save!")
        Case $msg = $exitbotbutt ; pressing the Exit button
            Exit
    EndSelect
WEnd

;;-------------------------------------- Functions --------------------------------

Func show()
    If $showGUI = 0 Then
        Read()
        GUISetState(@SW_SHOW) ; show the menu when hotkey pressed
        $showGUI = 1
    Else
        GUISetState(@SW_HIDE) ; hide the menu when hotkey pressed
        $showGUI = 0
    EndIf
EndFunc   ;==>show

Func Write()
    IniWrite(".\testscript.ini", "Waypoints", "1x", GUICtrlRead($input_x))
    IniWrite(".\testscript.ini", "Waypoints", "1y", GUICtrlRead($input_y))
EndFunc   ;==>Write

Func Read()
    $way1x = Int(IniRead(".\testscript.ini", "Waypoints", "1x", "-1"))
    $way1y = Int(IniRead(".\testscript.ini", "Waypoints", "1y", "-1"))
EndFunc   ;==>Read

8)

I'ved looked at that but it doesn't check the one check box that was there. It only brings the values for the input boxes back.

I want to be able to have the boxes checked that were previously checked at the save point.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I want to be able to have the boxes checked that were previously checked at the save point.

So what exactly IS the problem?

Add checkbox state read/write to global var in Read() and Write() fucntions.

When creating control, set it's state from variable:

$checkCN = GUICtrlCreateCheckbox("", 20, 50, 20, 20)

GUICtrlSetState(-1, $state)

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

Global $start
Global $way1x, $way1y, $Checker
$showGUI = 0 ; setting the GUI condition

HotKeySet("{F6}", "show") ; using hotkey to show menu

Read()

GUICreate("Testscript", 300, 420)
$savebotbutt = GUICtrlCreateButton("Save", 160, 390, 60, 30) ; show the Save button
$exitbotbutt = GUICtrlCreateButton("Exit", 220, 390, 80, 30) ; show the Exit button
GUICtrlCreateTab(0, 0, 300, 390)
$tab2 = GUICtrlCreateTabItem("WayPoints")
GUICtrlCreateLabel("Training Ground Location", 10, 30, 200, 20)
$checkCN = GUICtrlCreateCheckbox("", 20, 50, 20, 20) ; 1st checkbox location
If $Checker Then GUICtrlSetState( -1, $GUI_CHECKED)
GUICtrlCreateLabel("X : ", 60, 50, 15, 20)
;~ $way1x = Int(IniRead(".\testscript.ini","Waypoints","1x","-1"))
$input_x = GUICtrlCreateInput($way1x, 80, 50, 50, 20)
GUICtrlCreateLabel("Y : ", 150, 50, 15, 20)
;~ $way1y = Int(IniRead(".\testscript.ini","Waypoints","1y","-1"))
$input_y = GUICtrlCreateInput($way1y, 170, 50, 50, 20)
GUISetState(@SW_HIDE)


While 1 ; main body of program, loop till condition met
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE ; when the top right cancel button is pressed
            Exit
        Case $msg = $savebotbutt ; pressing the Save button
            Write()
            MsgBox(64, "Test Box", "You clicked on Save!")
        Case $msg = $exitbotbutt ; pressing the Exit button
            Exit
    EndSelect
WEnd

;;-------------------------------------- Functions --------------------------------

Func show()
    If $showGUI = 0 Then
        Read()
        GUISetState(@SW_SHOW) ; show the menu when hotkey pressed
        $showGUI = 1
    Else
        GUISetState(@SW_HIDE) ; hide the menu when hotkey pressed
        $showGUI = 0
    EndIf
EndFunc   ;==>show

Func Write()
    IniWrite(".\testscript.ini", "Waypoints", "Checkbox",_IsChecked($checkCN))
    IniWrite(".\testscript.ini", "Waypoints", "1x", GUICtrlRead($input_x))
    IniWrite(".\testscript.ini", "Waypoints", "1y", GUICtrlRead($input_y))
EndFunc   ;==>Write

Func Read()
    $checker = Int(IniRead(".\testscript.ini", "Waypoints", "Checkbox", "False"))
    $way1x = Int(IniRead(".\testscript.ini", "Waypoints", "1x", "-1"))
    $way1y = Int(IniRead(".\testscript.ini", "Waypoints", "1y", "-1"))
EndFunc   ;==>Read

Func _IsChecked($control)
    If BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Or simply..

$GUI_EVENT_CLOSE = -3
AutoItSetOption("GUIOnEventMode", 1)

$gui = GUICreate("My GUI", 75, 30)
GUISetOnEvent($GUI_EVENT_CLOSE, "DoQuit", $gui)

$ini_path = "my.ini"
$checkbox = GUICtrlCreateCheckbox("foo", 5, 5)
GUICtrlSetState(-1, IniRead($ini_path, "settings", "bar", 4)) 
GuiSetState()

while 1
    Sleep(50)
wend

func DoQuit()
    IniWrite($ini_path, "settings", "bar", GUICtrlRead($checkbox))
    exit
endfuncoÝ÷ جzl¨Â|+j^­û§rبÇè­È^rFèÅë,¢ØZ¶Ø^½©nz+,¶Þu«*ºuªê-¢º®¢Ý*ºh­ö¥±êZµëÞ­·jëªê-⫨¶+'¢Ö¥¢j[Úç­¢Ëh­è§jx§ø¥y·jëÝý²Z{^ÆÖ§vë¯l{^­§-Â+aÐh¶+j^uû§rبƫz)ì×®®

have fun!

;o)

(or


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites

include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 141, 225, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Global $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 35, 25, 97, 17)
Global $Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 35, 45, 97, 17)
Global $Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 35, 65, 97, 17)
Global $Save = GUICtrlCreateButton("Save", 30, 95, 75, 25, 0)
GUICtrlSetOnEvent(-1, "SaveClick")
Global $Load = GUICtrlCreateButton("Load", 30, 130, 75, 25, 0)
GUICtrlSetOnEvent(-1, "LoadClick")
Global $Clear = GUICtrlCreateButton("Clear", 30, 165, 75, 25, 0)
GUICtrlSetOnEvent(-1, "ClearClick")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func ClearClick()
 SetCheckedState($Checkbox1,0)
 SetCheckedState($Checkbox2,0)
 SetCheckedState($Checkbox3,0)
EndFunc

Func Form1Close()
 Exit
EndFunc

Func LoadClick()
    SetCheckedState($Checkbox1, IniRead(@ScriptDir&"\cktest.ini","checkboxes","Checkbox1",False))
    SetCheckedState($Checkbox2, IniRead(@ScriptDir&"\cktest.ini","checkboxes","Checkbox2",False))
    SetCheckedState($Checkbox3, IniRead(@ScriptDir&"\cktest.ini","checkboxes","Checkbox3",False))
EndFunc

Func SaveClick()
    IniWrite(@ScriptDir&"\cktest.ini","checkboxes","Checkbox1",IsChecked($Checkbox1))
    IniWrite(@ScriptDir&"\cktest.ini","checkboxes","Checkbox2",IsChecked($Checkbox2))
    IniWrite(@ScriptDir&"\cktest.ini","checkboxes","Checkbox3",IsChecked($Checkbox3))
EndFunc
 

; ===============================================================================================================================
; SetChecked State      : Set checked state of Checkbox or Radio button
; ===============================================================================================================================
Func SetCheckedState($nCtrl, $iState)
    If $iState > 0 Then
        GUICtrlSetState($nCtrl, $GUI_CHECKED)
    Else
        GUICtrlSetState($nCtrl, $GUI_UNCHECKED)
    EndIf
EndFunc   ;==>SetCheckedState

; ===============================================================================================================================
; IsChecked             :Get checked state of Checkbox or Radio button
; ===============================================================================================================================
Func IsChecked($nCtrl)
    If BitAND(GUICtrlRead($nCtrl), $GUI_CHECKED) = $GUI_CHECKED Then Return 1
    Return 0
EndFunc   ;==>IsChecked

Here's what I use.

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