Chetwood Posted October 23, 2004 Posted October 23, 2004 I'm trying to duplicate a checkbox/input combination I've seen often in programs. When the checkbox 'play sound' is unchecked, the input box below is grayed out and vice versa. To do this I do a Gui(read) on that checkbox but instead of giving back the values '1' for checked and '0' for unchecked (kinda what I expected) I always get '3'. Where does this value come from and why do I get it on both actions? TIA! expandcollapse popup#include "GUIConstants.au3" #include <Constants.au3> $playsound = 0 $soundfile= @WindowsDir & "\media\notify.wav" ;open dialogbox GUICreate("Sound", 310, 150) ;tick checkboxes according to default values $chk_playsound = GUICtrlCreateCheckbox("Play sound when done", 10, 50, 200, 20) IF $playsound = 1 then GUICtrlSetState ($chk_playsound, $GUI_CHECKED) ;input field and buttons for sound $soundfileinput = GUICtrlCreateInput ("", 28, 75, 150, 20) GUICtrlSetState($soundfileinput,$GUI_ACCEPTFILES) $browse = GUICtrlCreateButton ("...", 190, 75, 20, 20) $play = GUICtrlCreateButton (">", 215, 75, 20, 20,$BS_Icon) GUICtrlSetImage($play,"mmsys.cpl",36,0) If $playsound = 0 Then GuiCtrlSetState ($soundfileinput,$GUI_DISABLE) GuiCtrlSetState ($browse,$GUI_DISABLE) GuiCtrlSetState ($play,$GUI_DISABLE) EndIf GUISetState() ; created windows are initially hidden, now it's made visible ; run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = -3 ExitLoop Case $msg = $chk_playsound GUIRead($chk_playsound) MsgBox(0, "checkbox", $chk_playsound) If $chk_playsound = 1 Then GuiCtrlSetState ($soundfileinput,$GUI_ENABLE) GuiCtrlSetState ($browse,$GUI_ENABLE) GuiCtrlSetState ($play,$GUI_ENABLE) GUICtrlSetData ($soundfileinput,$soundfile) EndIf If $chk_playsound = 0 Then MsgBox(0, "checkbox", $chk_playsound) GuiCtrlSetState ($soundfileinput,$GUI_DISABLE) GuiCtrlSetState ($browse,$GUI_DISABLE) GuiCtrlSetState ($play,$GUI_DISABLE) GUICtrlSetData ($soundfileinput,"") EndIf Case $msg = $browse $soundfile = FileOpenDialog("Select wav-file to play", @ScriptDir , "Windows Waveform (*.wav)", 1 + 2 ) If @error Then ;continue Else GUICtrlSetData($soundfileinput,$soundfile) EndIf Case $msg = $play If $soundfileinput <> "" Then SoundPlay($soundfile,0) EndIf EndSelect Wend Exit MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch
Developers Jos Posted October 23, 2004 Developers Posted October 23, 2004 I'm trying to duplicate a checkbox/input combination I've seen often in programs. When the checkbox 'play sound' is unchecked, the input box below is grayed out and vice versa. To do this I do a Gui(read) on that checkbox but instead of giving back the values '1' for checked and '0' for unchecked (kinda what I expected) I always get '3'. Where does this value come from and why do I get it on both actions? TIA!<{POST_SNAPBACK}>When you do a GUIRead you need to store the result into a variable like:$Status = GUIRead($chk_playsound)and then test the value of that variable. You are now getting back the Handle for the checkbox. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Chetwood Posted October 23, 2004 Author Posted October 23, 2004 When you do a GUIRead you need to store the result into a variable like:$Status = GUIRead($chk_playsound)and then test the value of that variable. You are now getting back the Handle for the checkbox.<{POST_SNAPBACK}>OK cool, I did it and it works when ticking the checkbox. The GuiRead command gives back a value of '1'. However, when I uncheck it, the value returned is '4' instead of '0'. What am I overlooking?Case $msg = $chk_playsound $status_chk_playsound=GUIRead($chk_playsound) MsgBox(0, "checkbox", $status_chk_playsound) If $status_chk_playsound = 1 Then GuiCtrlSetState ($soundfileinput,$GUI_ENABLE) GuiCtrlSetState ($browse,$GUI_ENABLE) GuiCtrlSetState ($play,$GUI_ENABLE) GUICtrlSetData ($soundfileinput,$soundfile) EndIf If $status_chk_playsound = 0 Then GuiCtrlSetState ($soundfileinput,$GUI_DISABLE) GuiCtrlSetState ($browse,$GUI_DISABLE) GuiCtrlSetState ($play,$GUI_DISABLE) GUICtrlSetData ($soundfileinput,"") EndIf MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller Übersetzer von DVD Shrink deutsch
Developers Jos Posted October 23, 2004 Developers Posted October 23, 2004 OK cool, I did it and it works when ticking the checkbox. The GuiRead command gives back a value of '1'. However, when I uncheck it, the value returned is '4' instead of '0'. What am I overlooking?<{POST_SNAPBACK}>Nothing ..... State Comments No Change 0 $GUI_UNCHECKED Radio or Checkbox will be unchecked $GUI_CHECKED same but CheckedGlobal $GUI_CHECKED = 1Global $GUI_INDETERMINATE = 2Global $GUI_UNCHECKED = 4 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
megahyperion Posted October 24, 2004 Posted October 24, 2004 (edited) I am having the same problem as well. I changed the GUIconstrants file to Global $GUI_UNCHECKED = 0 and that didnt work. I also added GUICtrlSetState(-1,$GUI_UNCHECKED) with no luck as well. Here is my simple test script, I would like checked to =1 (which it does) unchecked to =0 (it equals 4 currently) My undetermined state is also 4, I would like it to =0 as well. #include <GUIConstants.au3> GUICreate("My GUI group"); will create a dialog box that when displayed is centered GUICtrlCreateGroup ("My staggered Radio", 178, 80, 160, 100) $res1 = GUICtrlCreateRadio ("item 1", 200, 100, 60, 20) $res2 = GUICtrlCreateRadio ("item 2", 223, 125, 60, 20) $res3 = GUICtrlCreateRadio ("item 3", 245, 150, 60, 20) GUICtrlCreateGroup ("",-99,-99,1,1) $OK = GUICtrlCreateButton ("OK", 188, 325, 60, 25) GUISetState () While 1 $msg = GUIGetMsg() $Statusres1 = GUIRead($res1) $Statusres2 = GUIRead($res2) $Statusres3 = GUIRead($res3) If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $OK Then Msgbox(0,"NFO","test" & @CRLF & $statusres1 & @CRLF & $statusres2 & @CRLF & $statusres3) Wend thanks in advance Edited October 24, 2004 by megahyperion
Developers Jos Posted October 24, 2004 Developers Posted October 24, 2004 I am having the same problem as well.I changed the GUIconstrants file toGlobal $GUI_UNCHECKED = 0-snip-My undetermined state is also 4, I would like it to =0 as well.thanks in advance<{POST_SNAPBACK}>Don't change anything in GUIconstants.au3 since it contains CONSTANTS.It is a given that an unchecked checkbox/radio returns a 4!Just use an IF if you want a Variable to contain a 1 or 0 like:$Statusres1 = GUIRead($res1) If $Statusres1 = 4 then $Statusres1 = 0 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
SlimShady Posted October 24, 2004 Posted October 24, 2004 Asd JdeB said: You may add/delete things from the GUIConstants file, but do not change anything. If you did I suggest you download a new copy. I'll edit your script. expandcollapse popup#include <GUIConstants.au3> GUICreate("My GUI group"); will create a dialog box that when displayed is centered GUICtrlCreateGroup ("My staggered Radio", 178, 80, 160, 100) $res1 = GUICtrlCreateRadio ("item 1", 200, 100, 60, 20) $res2 = GUICtrlCreateRadio ("item 2", 223, 125, 60, 20) $res3 = GUICtrlCreateRadio ("item 3", 245, 150, 60, 20) GUICtrlCreateGroup ("",-99,-99,1,1) $OK = GUICtrlCreateButton ("OK", 188, 325, 60, 25) GUISetState () While 1 $msg = GUIGetMsg() If $msg = $res1 OR $msg = $res2 OR $msg = $res3 Then If GUIRead($res1) = $GUI_CHECKED Then $statusres1 = " checked " Else $statusres1 = " unchecked " EndIf If GUIRead($res2) = $GUI_CHECKED Then $statusres2 = " checked " Else $statusres2 = " unchecked " EndIf If GUIRead($res3) = $GUI_CHECKED Then $statusres3 = " checked " Else $statusres3 = " unchecked " EndIf EndIf If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $OK Then Msgbox(0,"NFO","test" & @CRLF & $statusres1 & @CRLF & $statusres2 & @CRLF & $statusres3) Wend
megahyperion Posted October 24, 2004 Posted October 24, 2004 My script is huge, but I managed to pull it off with If GUIRead($res1) > 3 Then $statusres1 = GUIRead($res1) - 4 ElseIf GUIRead($res1) < 3 Then $statusres1 = GUIRead($res1) EndIf my radio button is $res1, instead of using $res1 for the 1 and 0 i now use $statusres1 slopy, but it works with 2 weeks of programing under my belt I'm gonna have to go ahead and give myself a pat on the back for that one
Developers Jos Posted October 24, 2004 Developers Posted October 24, 2004 My script is huge, but I managed to pull it off with If GUIRead($res1) > 3 Then $statusres1 = GUIRead($res1) - 4 ElseIf GUIRead($res1) < 3 Then $statusres1 = GUIRead($res1) EndIfmy radio button is $res1, instead of using $res1 for the 1 and 0 i now use $statusres1slopy, but it workswith 2 weeks of programing under my belt I'm gonna have to go ahead and give myself a pat on the back for that one <{POST_SNAPBACK}>yeap.. but this should work too and is less confusing:$Statusres1 = GUIRead($res1) If $Statusres1 = 4 then $Statusres1 = 0 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
CyberSlug Posted October 24, 2004 Posted October 24, 2004 You could create a function that returns 1 and 0 instead of 1 and 4 #include <GuiConstants.au3> ;.... $statusres1 = checkStatus($res1) ;... Exit Func checkStatus($ref) If GuiRead($ref) = $GUI_CHECKED Then Return 1 Return 0;otherwise EndFunc Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now