sliceofpie Posted September 12, 2010 Share Posted September 12, 2010 Hi, I'd like to use radio buttons for my script. The problem is that the rest of my script depends on Opt("GUIonEventMode", 1). When I set GUIonEventMode to 0 then everything works fine. Is there a way to integrate both? Here's my sample code: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Opt("GUIonEventMode", 1) Global $Radio[2] $Form2 = GUICreate("Form2", 413, 298, 255, 208) $Radio[0] = GUICtrlCreateRadio("Radio1", 88, 64, 113, 17) $Radio[1] = GUICtrlCreateRadio("Radio2", 88, 184, 113, 17) $Button1 = GUICtrlCreateButton("Button1", 88, 112, 75, 25, $WS_GROUP) GUICtrlSetState (-1, $GUI_DISABLE) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 80, 232, 97, 17) GUICtrlSetState (-1, $GUI_DISABLE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch For $i = 0 To UBound($Radio) - 1 If $nmsg = $Radio[$i] And BitAND(GUICtrlRead($radio[$i]), $GUI_CHECKED) = $GUI_CHECKED Then ReSet($i) Next WEnd Func ReSet($num) For $i = 1 To UBound($Radio) - 1 GUICtrlSetState($Radio[$i], $GUI_UNCHECKED) GUICtrlSetState($Button1, $GUI_DISABLE) GUICtrlSetState($Checkbox1, $GUI_DISABLE) ConsoleWrite ($num) Next If $num = 0 Then GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetState($Radio[0], $GUI_CHECKED) ElseIf $num = 1 Then GUICtrlSetState($Checkbox1, $GUI_ENABLE) GUICtrlSetState($Radio[1], $GUI_CHECKED) Endif EndFunc ;==>ReSet Link to comment Share on other sites More sharing options...
jaberwacky Posted September 12, 2010 Share Posted September 12, 2010 Personally, I am unable to make out what the problem is based on what you posted. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
sliceofpie Posted September 12, 2010 Author Share Posted September 12, 2010 I don't think I exlained that right.. sorry about that. The current script is set to disable two options and only show them when one of the radio buttons is selected.When selecting Radio[0] , it enables Button1When selecting Radio[1], it enables Checkbox1The problem that I'm having is that if Opt("GUIonEventMode", 1) then those two options stay disabled. When setting Opt("GUIonEventMode", 0) this sample script above works perfectly but I'm not able to insert it into my actual script since Opt("GUIonEventMode", 0) disables other controls that I have.I'm doing something wrong.. is there some way to disable/enable items using Opt("GUIonEventMode", 1)?Any help is appreciated. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 12, 2010 Moderators Share Posted September 12, 2010 sliceofpie,You need to decide before starting your script whether to use OnEvent or GetMessage modes - you cannot use them both in the same script (see note below). Go and read the Help file section <GUI Reference> to understand better the difference between the 2 modes. Here is your script properly coded in OnEvent mode: expandcollapse popup#include <GUIConstantsEx.au3> Opt("GUIonEventMode", 1) Global $Radio[2] $Form2 = GUICreate("Form2", 413, 298, 255, 208) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $Radio[0] = GUICtrlCreateRadio("Radio1", 88, 64, 113, 17) GUICtrlSetOnEvent(-1, "_Radio") $Radio[1] = GUICtrlCreateRadio("Radio2", 88, 184, 113, 17) GUICtrlSetOnEvent(-1, "_Radio") $Button1 = GUICtrlCreateButton("Button1", 88, 112, 75, 25) GUICtrlSetState (-1, $GUI_DISABLE) $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 80, 232, 97, 17) GUICtrlSetState (-1, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func _Radio() If GUICtrlRead($Radio[0]) = 1 Then GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetState($Checkbox1, $GUI_DISABLE) Else GUICtrlSetState($Checkbox1, $GUI_ENABLE) GUICtrlSetState($Button1, $GUI_DISABLE) EndIf EndFunc Func _Exit() Exit EndFuncRead the Help file as I suggested and ask if you have any questions. M23Note: You can mix the 2 modes if you are very careful, but normally you should stick to just the one. If you do find yourself having to use both, you should have alarm bells going off and you should seriously consider recasting the code. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
sliceofpie Posted September 12, 2010 Author Share Posted September 12, 2010 Thanks M23. This explains why I see posts use GUISetOnEvent instead of GUICtrlSetState. I did check out the GUI OnEvent Mode in the help file. I understand what the difference between them are but it didn't say when it is better to use one or the other. Maybe when programs do multiple functions, you don't want your script stuck in a loop? Just a guess.. anyhow thanks again M23. Your knowledge has given me the right information to keep going. Link to comment Share on other sites More sharing options...
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