Zag8888 Posted April 28, 2019 Posted April 28, 2019 (edited) Hey folks, I have a little problem with my script. I have no experience with these things, and I know for sure that my code is not the best, but please be lenient, thanks 😅 The User should first choose 1 of the 2 Options to actually start the script. If 1 of the 2 Option is choosen then the User should click start again and all should work. I have already commented the problem, If the button Start is clicked before, the User will select just 1 of the 2 option and the program will start (Without clicking start).How can I set $Start to $GUI_UNCHECKED? I have already tried to use GuiCtrlSetState, but didnt worked. $Start = GuiCtrlCreateButton("Start", 20, 200, 90, 50,bitor($BS_CENTER,0,0)) GUICtrlSetOnEvent($Start,"Startallrun") Func Startallrun() If ((GUICtrlRead($Option1) = $GUI_UNCHECKED) And (GUICtrlRead($Option2) = $GUI_UNCHECKED)) Then MsgBox($MB_OK, "Error", "You have to select 1 Option") While (GUICtrlRead($Option1) = $GUI_UNCHECKED) Sleep(10) If (GUICtrlRead($Option1) = $GUI_CHECKED) Or (GUICtrlRead($Option2) = $GUI_CHECKED) Then GUICtrlSetState($Start,$GUI_UNCHECKED) ; This doesen't work for Buttons While (GUICtrlRead($Start) = $GUI_UNCHECKED) Sleep(10) If ($Start = $GUI_CHECKED) Then ; That's the problem. The script will start if I click one of the 2 options (because start was already checked before) ExitLoop EndIf WEnd ExitLoop EndIf WEnd Else If (GUICtrlRead($Option1) = $GUI_CHECKED) Then MsgBox($MB_OK, "Starting", "Start") Start() EndIf EndIf EndFunc Edited April 28, 2019 by Zag8888 Solved
Moderators Melba23 Posted April 28, 2019 Moderators Posted April 28, 2019 Zag8888, Firstly, how about posting some runnable code rather then a snippet. Then, how about explaining what you are trying to do and what is not working so we can see how we might help you. At the moment it is a bit hard to offer suggestions when we have no idea where the problem actually lies. M23 Zag8888 1 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
Zag8888 Posted April 28, 2019 Author Posted April 28, 2019 (edited) Hello Melba23, I have added some more info in the thread. I really don't understand how to Uncheck a button, I have tried to use GUICtrlSetState, but it doesen't worked for me Edited April 28, 2019 by Melba23 Merged and quotes removed
Moderators Melba23 Posted April 28, 2019 Moderators Posted April 28, 2019 Zag8888, I did say "runnable" code - all we have is a function and button creation/assignment. Where are the GUI. the $StoryMode and $Option1 controls, etc? And what exactly do you mean by "unchecking" a button - you check/uncheck radios and checkboxes, not normal buttons. M23 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
Zag8888 Posted April 28, 2019 Author Posted April 28, 2019 15 minutes ago, Melba23 said: Zag8888, I did say "runnable" code - all we have is a function and button creation/assignment. Where are the GUI. the $StoryMode and $Option1 controls, etc? And what exactly do you mean by "unchecking" a button - you check/uncheck radios and checkboxes, not normal buttons. M23 $StoryMode,$Option1 and $Option2 are just Radio. When I click Start the Function Start() will run, but only if 1 of these 3 radio are selected, after I select 1 option the code will start immediately (Without waiting for the click start again).
Subz Posted April 28, 2019 Posted April 28, 2019 Just disable the $Start button, then use an GuiSetOnEvent for $Option1 and $Option2 to enable the start button e.g. this way, they must choose one of the options before pushing the start button. Also for the Startallrun() function you only need to know which option is checked see example below. nb: I've prefixed my variables with $id to show that they're control ids. idOption1 = GUICtrlCreateRadio("Option 1", 10, 10, 120, 20) GUICtrlSetOnEvent($idOption1,"_EnableStart") $idOption2 = GUICtrlCreateRadio("Option 2", 10, 40, 120, 20) GUICtrlSetOnEvent($idOption2,"_EnableStart") $idStart = GuiCtrlCreateButton("Select Radio Above", 10, 70, 120, 50,bitor($BS_CENTER,0,0)) GUICtrlSetOnEvent($idStart,"Startallrun") GUICtrlSetState($idStart, $GUI_DISABLE) Func _EnableStart() GUICtrlSetState($idStart, $GUI_ENABLE) EndFunc Func Startallrun() If GUICtrlRead($idOption1) = $GUI_CHECKED Then MsgBox(4096, "Starting", "Running Option 1") ElseIf GUICtrlRead($idOption2) = $GUI_CHECKED Then MsgBox(4096, "Starting", "Running Option 2") EndIf EndFunc Zag8888 1
Zag8888 Posted April 28, 2019 Author Posted April 28, 2019 3 minutes ago, Subz said: Just disable the $Start button, then use an GuiSetOnEvent for $Option1 and $Option2 to enable the start button e.g. this way, they must choose one of the options before pushing the start button. Also for the Startallrun() function you only need to know which option is checked see example below. nb: I've prefixed my variables with $id to show that they're control ids. idOption1 = GUICtrlCreateRadio("Option 1", 10, 10, 120, 20) GUICtrlSetOnEvent($idOption1,"_EnableStart") $idOption2 = GUICtrlCreateRadio("Option 2", 10, 40, 120, 20) GUICtrlSetOnEvent($idOption2,"_EnableStart") $idStart = GuiCtrlCreateButton("Select Radio Above", 10, 70, 120, 50,bitor($BS_CENTER,0,0)) GUICtrlSetOnEvent($idStart,"Startallrun") GUICtrlSetState($idStart, $GUI_DISABLE) Func _EnableStart() GUICtrlSetState($idStart, $GUI_ENABLE) EndFunc Func Startallrun() If GUICtrlRead($idOption1) = $GUI_CHECKED Then MsgBox(4096, "Starting", "Running Option 1") ElseIf GUICtrlRead($idOption2) = $GUI_CHECKED Then MsgBox(4096, "Starting", "Running Option 2") EndIf EndFunc I have already resolved my problem using $GUI_DISABLE, but thanks for the help, I appreciate
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