timmy2 Posted November 30, 2018 Share Posted November 30, 2018 My program displays a list of "house rules" in a form, provides a checkbox for the user to agree to the rules, asks for the user's first and last name, and allows the user to either Cancel (bail out and log off) or OK it and continue on. I'm using OnEvent Mode to process the user's response to the form. As you'll see in the comments below I can't figure out how to return to the main body of my program after the user clicks the OK button. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; remember that when the above is enabled all variables declared within the Program region must be Global. #Region - Main Body (or at least I'd like it to be!) Opt("GUIOnEventMode", 1) Global $Form1, $idInput1, $idInput2, $Button2, $sFN, $sLN _DisplayForm() ; display agreement form ; next step in program (if I can get back here) MsgBox($MB_SYSTEMMODAL, "Results", "returned to main body") Exit #EndRegion - Main Body #Region - Functions Func _DisplayForm() $Form1 = GUICreate("Form1", 679, 438, 192, 124) ; ask firstname $idInput1 = GUICtrlCreateInput("", 56, 360, 169, 21) ; ask lastname $idInput2 = GUICtrlCreateInput("", 240, 360, 177, 21) ; add labels GUICtrlCreateLabel("Enter first name", 56, 336, 77, 17) GUICtrlCreateLabel("Enter last name", 240, 336, 77, 17) GUICtrlCreateLabel("I agree", 480, 336, 37, 17) ; checkbox for agreement GUICtrlCreateCheckbox("Checkbox1", 456, 336, 17, 17) GUICtrlSetOnEvent(-1, "Checkbox1Click") ; allow bail out GUICtrlCreateButton("Cancel", 464, 368, 73, 33) GUICtrlSetOnEvent(-1, "_CancelPressed") ; OK available only if checkbox checked $Button2 = GUICtrlCreateButton("Okay", 560, 368, 81, 33) GUICtrlSetOnEvent(-1, "_OKPressed") GUICtrlSetState($Button2, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd EndFunc ;==>_DisplayForm Func _CancelPressed() MsgBox($MB_SYSTEMMODAL, "Results", "Cancel pressed") Exit ; if no agreement then exit EndFunc ;==>_CancelPressed Func _OKPressed() ; THIS IS THE FUNCTION FROM WHICH I NEED TO RETURN TO MAIN BODY $sFN = GUICtrlRead($idInput1) $sLN = GUICtrlRead($idInput2) MsgBox($MB_SYSTEMMODAL, "Results", "firstname: " & $sFN & @CRLF & "lastname: " & $sLN) ; HOW DO I RETURN TO THE MAIN PROGRAM BODY? ; Return just takes me back to _DisplayForm instead of the main prog ; Setting a variable here and checking for it in _DisplayForm's While/WEnd loop doesn't work either EndFunc ;==>_OKPressed Func Checkbox1Click() GUICtrlSetState($Button2, $GUI_ENABLE) EndFunc ;==>Checkbox1Click #EndRegion - Functions I've Googled the topic of exiting a function early but have found nothing applicable to my situation. I even tried the techniques from this old post, to no avail. I have rewritten the form code using MessageLoop Mode, so I have a Plan B, but am curious if there's a solution. Link to comment Share on other sites More sharing options...
Subz Posted November 30, 2018 Share Posted November 30, 2018 You could just use a toggle example: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; remember that when the above is enabled all variables declared within the Program region must be Global. #Region - Main Body (or at least I'd like it to be!) Opt("GUIOnEventMode", 1) Global $Form1, $idInput1, $idInput2, $Button2, $sFN, $sLN, $bResult = False _DisplayForm() ; display agreement form ; next step in program (if I can get back here) MsgBox($MB_SYSTEMMODAL, "Results", "returned to main body") Exit #EndRegion - Main Body #Region - Functions Func _DisplayForm() $Form1 = GUICreate("Form1", 679, 438, 192, 124) ; ask firstname $idInput1 = GUICtrlCreateInput("", 56, 360, 169, 21) ; ask lastname $idInput2 = GUICtrlCreateInput("", 240, 360, 177, 21) ; add labels GUICtrlCreateLabel("Enter first name", 56, 336, 77, 17) GUICtrlCreateLabel("Enter last name", 240, 336, 77, 17) GUICtrlCreateLabel("I agree", 480, 336, 37, 17) ; checkbox for agreement GUICtrlCreateCheckbox("Checkbox1", 456, 336, 17, 17) GUICtrlSetOnEvent(-1, "Checkbox1Click") ; allow bail out GUICtrlCreateButton("Cancel", 464, 368, 73, 33) GUICtrlSetOnEvent(-1, "_CancelPressed") ; OK available only if checkbox checked $Button2 = GUICtrlCreateButton("Okay", 560, 368, 81, 33) GUICtrlSetOnEvent(-1, "_OKPressed") GUICtrlSetState($Button2, $GUI_DISABLE) GUISetState(@SW_SHOW) While $bResult = False Sleep(100) WEnd GUIDelete($Form1) EndFunc ;==>_DisplayForm Func _CancelPressed() MsgBox($MB_SYSTEMMODAL, "Results", "Cancel pressed") Exit ; if no agreement then exit EndFunc ;==>_CancelPressed Func _OKPressed() ; THIS IS THE FUNCTION FROM WHICH I NEED TO RETURN TO MAIN BODY $sFN = GUICtrlRead($idInput1) $sLN = GUICtrlRead($idInput2) MsgBox($MB_SYSTEMMODAL, "Results", "firstname: " & $sFN & @CRLF & "lastname: " & $sLN) $bResult = True ; HOW DO I RETURN TO THE MAIN PROGRAM BODY? ; Return just takes me back to _DisplayForm instead of the main prog ; Setting a variable here and checking for it in _DisplayForm's While/WEnd loop doesn't work either EndFunc ;==>_OKPressed Func Checkbox1Click() GUICtrlSetState($Button2, $GUI_ENABLE) EndFunc ;==>Checkbox1Click #EndRegion - Functions timmy2 1 Link to comment Share on other sites More sharing options...
timmy2 Posted November 30, 2018 Author Share Posted November 30, 2018 Thank you very much, @Subz. Such an obvious and simple solution! (now that I see it ) 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