AasimPathan Posted March 15, 2019 Share Posted March 15, 2019 Hi, I need help with the following. I am creating a script that displays a GUI for selection, I want the user to have the option of pressing Yes/No to confirm whether he/she wants to select that checkbox, If he/she presses yes then select if they press No then unselect. and the unselect is what i am not able to get to work. Can someone help me finalize this? expandcollapse popup#include <AutoItConstants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <GUIConstantsEx.au3> #include <GUIConstants.au3> SelectComputer() Func SelectComputer() Local $hGUI = GUICreate("Select Computer", 300, 300) Opt("GUICoordMode", 0) ;1=absolute, 0=relative, 2=cell Local $idCheckbox1 = GUICtrlCreateCheckbox("022", 10, 10) Local $idCheckbox2 = GUICtrlCreateCheckbox("023", -1, 25) Local $idCheckbox3 = GUICtrlCreateCheckbox("024", -1, 25) Local $idCheckbox4 = GUICtrlCreateCheckbox("025", -1, 25) Local $idCheckbox5 = GUICtrlCreateCheckbox("027", -1, 25) Local $idCheckbox6 = GUICtrlCreateCheckbox("080", -1, 25) Local $idCheckbox7 = GUICtrlCreateCheckbox("113", -1, 25) Local $idCheckbox8 = GUICtrlCreateCheckbox("114", -1, 25) Local $idCheckbox9 = GUICtrlCreateCheckbox("116", -1, 25) Local $idCheckbox10 = GUICtrlCreateCheckbox("119", -1, 25) Local $idButton_Insert = GUICtrlCreateButton("Done", 150, 10) Local $idButton_Close = GUICtrlCreateButton("Close", 50, 0) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop Case $idCheckbox1 If _IsChecked($idCheckbox1) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 022", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No _IsUnChecked($idCheckbox1) EndSelect Else EndIf Case $idCheckbox2 If _IsChecked($idCheckbox2) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 023", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No EndSelect Else ;If uncheck what should it do? EndIf Case $idCheckbox3 If _IsChecked($idCheckbox3) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 024", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No EndSelect Else ;If uncheck what should it do? EndIf Case $idCheckbox4 If _IsChecked($idCheckbox4) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 025", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No EndSelect Else ;If uncheck what should it do? EndIf Case $idCheckbox5 If _IsChecked($idCheckbox5) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 027", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No EndSelect Else ;If uncheck what should it do? EndIf Case $idCheckbox6 If _IsChecked($idCheckbox6) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 080", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No EndSelect Else ;If uncheck what should it do? EndIf Case $idCheckbox7 If _IsChecked($idCheckbox7) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 113", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No EndSelect Else ;If uncheck what should it do? EndIf Case $idCheckbox8 If _IsChecked($idCheckbox8) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 114", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No EndSelect Else ;If uncheck what should it do? EndIf Case $idCheckbox9 If _IsChecked($idCheckbox9) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 116", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No EndSelect Else ;If uncheck what should it do? EndIf Case $idCheckbox10 If _IsChecked($idCheckbox10) Then MsgBox($MB_YESNO, "", "Do you want to run the procedure over 119", 0, $hGUI) Select Case MsgBox = 6 ;Yes ;Run the procedure Case MsgBox = 7 ;No EndSelect Else ;If uncheck what should it do? EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Func _IsUnChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_UNCHECKED EndFunc ;==>_IsUnChecked Link to comment Share on other sites More sharing options...
Nine Posted March 15, 2019 Share Posted March 15, 2019 look at GUICtrlSetState () $GUI_CHECKED (1) Radio, Checkbox or ListViewItem will be checked. $GUI_UNCHECKED (4) Radio, Checkbox or ListViewItem will be unchecked. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Jfish Posted March 15, 2019 Share Posted March 15, 2019 (edited) Also have a look at whether or not your select statements are being triggered. There is a lot of repetitive code that you could probably do with a function - but this is a snippet with a debug msgbox to see if the function is being triggered and then un-checking it if it is a "no": $response=MsgBox($MB_YESNO, "", "Do you want to run the procedure over 022", 0, $hGUI) if $response=6 then ;Run the procedure else MsgBox(0,'','you selected no') _IsUnChecked($idCheckbox1) EndIf ;then I changed the other function to this: Func _IsUnChecked($idControlID) GUICtrlSetState($idControlID,$GUI_UNCHECKED) EndFunc ;==>_IsUnChecked I didn't test this very much, but here is an example of reducing some of the code into a function: expandcollapse popupWhile 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop Case $idCheckbox1 _buttonResponse($idCheckbox1) Case $idCheckbox2 _buttonResponse($idCheckbox2) Case $idCheckbox3 _buttonResponse($idCheckbox3) Case $idCheckbox4 _buttonResponse($idCheckbox4) Case $idCheckbox5 _buttonResponse($idCheckbox5) Case $idCheckbox6 _buttonResponse($idCheckbox6) Case $idCheckbox7 _buttonResponse($idCheckbox7) Case $idCheckbox8 _buttonResponse($idCheckbox8) Case $idCheckbox9 _buttonResponse($idCheckbox9) Case $idCheckbox10 _buttonResponse($idCheckbox10) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example func _buttonResponse($idControlID) If _IsChecked($idControlID) Then $response=MsgBox($MB_YESNO, "", "Do you want to run the procedure over 022", 0, $hGUI) if $response=6 then ;Run the procedure else MsgBox(0,'','you selected no') _IsUnChecked($idControlID) EndIf Else ;If uncheck what should it do? EndIf EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Func _IsUnChecked($idControlID) GUICtrlSetState($idControlID,$GUI_UNCHECKED) EndFunc ;==>_IsUnChecked Edited March 15, 2019 by Jfish AasimPathan 1 Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Nine Posted March 15, 2019 Share Posted March 15, 2019 If you really want to reduce redundancy, you could do something like : While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop Case $idCheckbox1 to $idCheckbox10 _buttonResponse($nMsg) EndSwitch Wend AasimPathan and Jfish 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AasimPathan Posted March 19, 2019 Author Share Posted March 19, 2019 Hi, Thanks it looks like though we are gonna go for a pull rather than using this push script. as we really want a single step install of our code base. So I am going to create a new post for that. Thanks for all your efforts it really helped me get close to a solution although I didn't get to implement it due to the different direction the company wants me to work on. 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