DigDeep Posted October 11, 2017 Share Posted October 11, 2017 (edited) Hi, I am definitely doing something wrong here that I am not able to figure out. I have the below GUI which has 2 radio buttons, 1 Input box and 1 OK Button. If OK button is pressed without selecting Radio and InputBox, it should throw error. (both radio and input text should be filled in mandatory, else error) If OK button is pressed by selecting both Radio and Input Text, then show the msgbox with Input Text and run the func of the Radio selected. Can someone help please? expandcollapse popup#Region #AutoIt3Wrapper_Run_Tidy=y #EndRegion #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $OK = 9999 #Region $Form2 = GUICreate("GUI", 496, 238, 1009, 394) $Input = GUICtrlCreateInput("", 40, 176, 241, 21) $Radio1 = GUICtrlCreateRadio("Option 1", 40, 40, 241, 17) $Radio2 = GUICtrlCreateRadio("Option 2", 40, 80, 241, 17) $OK = GUICtrlCreateButton("OK", 336, 176, 75, 25, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) #EndRegion While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK Switch GUICtrlRead($Input) Case $Radio1 Step1() Case $Radio2 Step2() Case "" MsgBox(16, "", "Select an option and click OK.") EndSwitch EndSwitch WEnd Func Step1() MsgBox(0, '', 'Running steps from Option 1') EndFunc ;==>Step1 Func Step2() MsgBox(0, '', 'Running steps from Option 2') EndFunc ;==>Step2 Edited October 11, 2017 by DigDeep Link to comment Share on other sites More sharing options...
kylomas Posted October 12, 2017 Share Posted October 12, 2017 (edited) DigDeep, One of many ways to do this... expandcollapse popup#Region #AutoIt3Wrapper_Run_Tidy=y #EndRegion #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $OK = 9999 #Region $Form2 = GUICreate("GUI", 496, 238, 1009, 394) $Input = GUICtrlCreateInput("", 40, 176, 241, 21) $Radio1 = GUICtrlCreateRadio("Option 1", 40, 40, 241, 17) $Radio2 = GUICtrlCreateRadio("Option 2", 40, 80, 241, 17) $OK = GUICtrlCreateButton("OK", 336, 176, 75, 25, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) #EndRegion While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK If GUICtrlRead($Input) = '' Then GUICtrlSetState($Input, $gui_focus) MsgBox(17, 'ERROR', 'Input required!', 3) ContinueLoop EndIf If BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) = $GUI_CHECKED Then Step1() If BitAND(GUICtrlRead($Radio2), $GUI_CHECKED) = $GUI_CHECKED Then Step2() EndSwitch WEnd Func Step1() MsgBox(0, '', 'Running steps from Option 1') EndFunc ;==>Step1 Func Step2() MsgBox(0, '', 'Running steps from Option 2') EndFunc ;==>Step2 kylomas edit: another way... expandcollapse popup#Region #AutoIt3Wrapper_Run_Tidy=y #EndRegion #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $OK = 9999 #Region $Form2 = GUICreate("GUI", 496, 238, 1009, 394) $Input = GUICtrlCreateInput("", 40, 176, 241, 21) $Radio1 = GUICtrlCreateRadio("Option 1", 40, 40, 241, 17) $Radio2 = GUICtrlCreateRadio("Option 2", 40, 80, 241, 17) GUISetState(@SW_SHOW) #EndRegion While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Radio1 If GUICtrlRead($Input) = '' Then GUICtrlSetState($Input, $gui_focus) MsgBox(17, 'ERROR', 'Input required!', 3) ContinueLoop EndIf Step1() Case $Radio2 If GUICtrlRead($Input) = '' Then GUICtrlSetState($Input, $gui_focus) MsgBox(17, 'ERROR', 'Input required!', 3) ContinueLoop EndIf Step2() EndSwitch WEnd Func Step1() MsgBox(0, '', 'Running steps from Option 1') EndFunc ;==>Step1 Func Step2() MsgBox(0, '', 'Running steps from Option 2') EndFunc ;==>Step2 Edited October 12, 2017 by kylomas DigDeep 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
DigDeep Posted October 12, 2017 Author Share Posted October 12, 2017 thank you @kylomas 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