Jump to content

Having trouble (re-)setting variables according to checkbox status


Moon
 Share

Recommended Posts

I'm not quite sure I'm getting the hang of GUI controls and how their status affects variables. I've created a preferences menu with several checkboxes. Their initial state when opening the menu is set by the default settings I've read from an ini file. Thus the checkbox "shutdown computer when done" is not checked.

OK, now when I check the checkbox and press cancel to leave the menu, the next time I open it the checkbox should be unchecked but unfortunately it isn't. What is wrong with this code?

$checkbox_shutdown = GUICtrlCreateCheckbox("", 19, 193, 17, 17)
IF $shutdown = 1 then GUICtrlSetState ($checkbox_shutdown, $GUI_CHECKED)
While 1
    $msg = GuiGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                        ExitLoop
            Case $msg = $checkbox_shutdown
                    ; no $GUICtrlSetState since the GUI does it automatically?
            Case $msg = $button_cancel
                        ExitLoop
            Case $msg = $button_ok
                        $shutdown=GUICtrlRead($checkbox_shutdown)
                        ExitLoop
            Case Else
        ;;;;;;;
        EndSelect
WEnd
GUIDelete()
Link to comment
Share on other sites

Exactly, however, when I press Cancel using this code the checkbox is checked.

Alright, I forgot to put in the ini code in my example but it doesn't change the outcome:

Case $msg = $button_ok
                        $shutdown=GUICtrlRead($checkbox_shutdown)
                        code_to_write_variable_to_ini_file
                        ExitLoop
Link to comment
Share on other sites

Exactly, however, when I press Cancel using this code the checkbox is checked.

Alright, I forgot to put in the ini code in my example but it doesn't change the outcome:

Case $msg = $button_ok
                        $shutdown=GUICtrlRead($checkbox_shutdown)
                        code_to_write_variable_to_ini_file
                        ExitLoop
Depending on what your writing to the ini file and how your handling the data read in from the ini file

$GUI_UNCHECKED = 4

$GUI_CHECKED = 1

IF $shutdown = 1 then GUICtrlSetState ($checkbox_shutdown, $GUI_CHECKED)

i'm guessing $shutdown is the value read in from the ini

also guessing the state is the value written to the ini

just guessing.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Your guess is ok. I'm not being too specific on this simply because my problem is the state of the checkbox. If I fire it up and it's uncheck, I check it and press cancel, the next time opening it should have it unchecked. That's not the case and I don't know why.

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