Jump to content


Photo

[Solved] Checkbox Test Without G-Label


  • Please log in to reply
2 replies to this topic

#1 avineyard

avineyard
  • Members
  • 73 posts

Posted 24 October 2012 - 10:47 PM

I have a checkbox in my gui that I don't want to immediately trigger an event, but rather have a button trigger the event based on the checkbox status. I cannot seem to trigger anything related to the test. All examples that I have seen use a g-label which I don't think is quite what I want since it immediately triggers an event. So really what needs to happen is I need to figure out how to trigger the check in a function.


Gui, Add, Button, , Test
Gui, Add, CheckBox, vCheck1, Enable 'Save and Close'
Gui, show
Return

GuiEscape:
GuiClose:
ExitApp

ButtonTest:
{
TrySaveAndClose()
}

TrySaveAndClose()
{
if vCheck1 = 1
  msgbox, checked
else if vCheck1 = 0
  msgbox, unchecked
else
  msgbox, this gets triggered every time
return
}

Can I get the function to test the status of a checkbox, or am I going to have to figure this out using a g-label triggered when the checkbox changes?


I also tried it with a g-label just for giggles and it still is failing so I don't know what I'm doing wrong.

Gui, Add, Button, gCheckIt, Test
Gui, Add, CheckBox, vCheck1, Enable 'Save and Close'
Gui, show
Return

GuiEscape:
GuiClose:
ExitApp

CheckIt:
{
if vCheck1 = 1
  msgbox, checked
else if vCheck1 = 0
  msgbox, unchecked
else
  msgbox, not sure why it triggers this
return
}


#2 Coco

Coco
  • Members
  • 590 posts

Posted 24 October 2012 - 11:50 PM

I altered a few lines: (Just a note: If you want to refer to a variable that has been given a value outside a function, state it as global. And also use "Gui, Submit, [NoHide]" or "GuiControlGet" to retrieve the variables' content(s))
Gui, Add, Button, , Test
Gui, Add, CheckBox, vCheck1, Enable 'Save and Close'
Gui, show
Return

GuiEscape:
GuiClose:
ExitApp

ButtonTest:
Gui, Submit, NoHide ; this will retrieve the checkbox's associated variable's content
TrySaveAndClose(Check1) ; now we pass the variable as a parameter
return

TrySaveAndClose(check)
{
	MsgBox, % check ? "Checked" : "Unchecked" ; if check is true(1), the messages is "Checked", "Unchecked" otherwise.
}


#3 avineyard

avineyard
  • Members
  • 73 posts

Posted 25 October 2012 - 02:20 PM

Awesome thank you so much. I modified it slightly to fit my needs.

Gui, Add, Button, , Test
Gui, Add, CheckBox, vCheck1, Enable 'Save and Close'
Gui, show
Return

GuiEscape:
GuiClose:
ExitApp

ButtonTest:
TrySaveAndClose()
return

TrySaveAndClose()
{
  global
Gui, Submit, NoHide ; this will retrieve the checkbox's associated variable's content
if(Check1) ;is checked
  msgbox, checked
else ;is unchecked
  msgbox, unchecked
return
}