Jump to content

Checkboxes in a popup window. Wont work.


Recommended Posts

Hello,

I have a GUI, if i click the button in this GUI, a new GUI/popup shows up with checkboxes in it. In that popup there is another button, that button must create a msgbox(for now) when the checkbox is checked.

For the last button, i have created a new function, but for some reason i cannot read the checkbox variable. Probably doing it wrong ;)

Func ButtonServers()
$ServersPopup = GUICreate("Servers",200,200)
GUISetIcon("icon.ico")
TraySetIcon("icon.ico")
GUISetOnEvent($GUI_EVENT_CLOSE, "ClosePopup")

$btnServersOk = GUICtrlCreateButton("ButtonServersOk",10,180,90,20)
GUICtrlSetOnEvent($btnServersOk, "ButtonServersOk")

$Checkbox1 = GUICtrlCreateCheckbox("TS001",5,25)
GUISetState(@SW_SHOW, $ServersPopup)
EndFunc
Func ButtonServersOk()
$Checkbox1checked = GUICtrlRead($Checkbox1)
If $Checkbox1checked = $GUI_UNCHECKED Then MsgBox(0,"","Checked") EndIf
EndFunc

It keeps getting an error at the $checkbox1:

$Checkbox1checked = GUICtrlRead($Checkbox1)

Anyone who can help? :)

Link to comment
Share on other sites

Yes, that was only for a test. But still doesnt work this way.

For some reason it looks like it cannot read the variable in another function? The error says the error is in $Checkbox1

If i use another variable that is not in a function, like something from the main GUI, it does work.

Edited by JoshuaLoman
Link to comment
Share on other sites

This should work

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
Global $Checkbox1
ButtonServers()
Func ButtonServers()
$ServersPopup = GUICreate("Servers", 200, 200)
GUISetIcon("icon.ico")
TraySetIcon("icon.ico")
$btnServersOk = GUICtrlCreateButton("ButtonServersOk", 10, 180, 90, 20)
$Checkbox1 = GUICtrlCreateCheckbox("TS001", 5, 25)
GUISetState(@SW_SHOW, $ServersPopup)
While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
   Case $GUI_EVENT_CLOSE
    Exit
   Case $btnServersOk
    ButtonServersOk()
  EndSwitch
WEnd

EndFunc   ;==>ButtonServers
Func ButtonServersOk()
If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
  MsgBox(0, "", "Checked")
EndIf
EndFunc   ;==>ButtonServersOk
Func ClosePopup()
Exit
EndFunc   ;==>ClosePopup
Link to comment
Share on other sites

Cant get it to work with that script.. Also cannot close the gui's anymore with the X..

The only thing i cannot get working is to read the checkbox variable from another function.. a checkbox in the main gui that is not in a function works fine..

Edited by JoshuaLoman
Link to comment
Share on other sites

Unless $Checkbox1 was declared as a global variable somewhere else in your script the problem is that, to the second function, that variable doesn't exist. It only exists inside the function ButtonServers, once that function ends or you jump to another function the rest of your script won't see it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I would assume that this line "Unless $Checkbox1 was declared as a global variable somewhere else in your script " would give you a starting point to figure it out. Look in the help file if you don't understand what that means, look for Global/Local and see where/when and how to use them.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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