stick3r Posted November 12, 2019 Share Posted November 12, 2019 Hi, I have a code, where I start my script with func GUI(), hide GUi with GUISetState(@SW_Hide) and then call Main(), doing stuff in Main() and then in some cases I call GUI() again. Func GUI() While 1 GUISetState(@SW_SHOW) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnGo GUISetState(@SW_Hide) Main() EndSwitch WEnd EndFunc Func Main() . . . GUI() EndFunc My question is: How many While loops are looping after I call GUI() second time from Main()? Am I creating second While 1..... loop, or does it open the same loop? And what if I Return something from func GUI(). Then I believe I exit func completely - therefore While loop ends for sure and next time I call Main, it starts func GUI() from scratch? Func Main() $arrGuiReturnData = GUI() . . Main() . . EndFunc Func GUI() While 1 GUISetState(@SW_SHOW) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnGo GUISetState(@SW_HIDE) Return $arrGuiReturnData EndSwitch WEnd EndFunc Link to comment Share on other sites More sharing options...
Nine Posted November 12, 2019 Share Posted November 12, 2019 Only one loop is performing at a given time. You are using recursion which you shouldn't use if you do not understand it completely. There a risk of stack overflow... In your first snippet, what happen is the first loop is stopped at the call to Main (). A second loop is started when you call GUI (). BTW, GUISetState(@SW_SHOW) should be outside the loop, there is no need to constantly call this statement. “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...
stick3r Posted November 13, 2019 Author Share Posted November 13, 2019 What about second code? Is it better way? Link to comment Share on other sites More sharing options...
Nine Posted November 13, 2019 Share Posted November 13, 2019 Still using recursion, but I don't see any reason for it. The code is too incomplete to be able to justify its usage... “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...
Zedna Posted November 13, 2019 Share Posted November 13, 2019 Main() Func Main() While True ; main nonGUI loop . . If ... Then $arrGuiReturnData = GUI() . . Sleep(10) WEnd EndFunc Func GUI() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnGo GUISetState(@SW_HIDE) Return $arrGuiReturnData EndSwitch WEnd EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
stick3r Posted November 13, 2019 Author Share Posted November 13, 2019 Basically, what I need to do is, in case of wrong input from user, I want to come back to GUI() and give a chance for user to correct input and start again. In theory user might input some info many times in the row to GUI(), which can only be verified in the system. i.e. I check if input is 10 digits, but if it is legit number, only a system can tell. Something like below: Func Main() $arrGuiReturnData = GUI() $returnData = DataFromSystem($arrGuiReturnData) If @error = 1 Then Main() EndFunc Func GUI() While 1 GUISetState(@SW_SHOW) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnGo GUISetState(@SW_HIDE) Return $arrGuiReturnData EndSwitch WEnd EndFunc What is the best way to come back to GUI() and give a chance to user to correct input? Link to comment Share on other sites More sharing options...
Zedna Posted November 13, 2019 Share Posted November 13, 2019 (edited) Main() Func Main() While True ; main nonGUI loop . . If ... Then While 1 ; loop until data are correct $arrGuiReturnData = GUI() $returnData = DataFromSystem($arrGuiReturnData) If @error = 0 Then ExitLoop WEnd EndIf . Sleep(10) WEnd EndFunc Func GUI() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnGo GUISetState(@SW_HIDE) Return $arrGuiReturnData EndSwitch WEnd EndFunc Edited November 13, 2019 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search 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