RAMzor Posted January 5, 2009 Share Posted January 5, 2009 (edited) Hello! I have confused with recursion. How can I return value (@error in my case) from function after some self calling? 1. Run code 2. For "Test Passed?" message answer "NO" 3. For "Communication ERROR" message answer "Retry" 4. Perform step 2 and 3 several times and then click "Cancel" _Test() If @error Then MsgBox(16, "", "::: Communication ERROR :::") Else MsgBox(0, "", "Test successfull") EndIf Func _Test() $AnswTest = MsgBox(4, "TEST", "Test Passed?") If $AnswTest = 7 Then ; NO (Test Failed) $Answ = MsgBox(21, "Error", "Communication ERROR") Select Case $Answ = 4 ;Retry _Test() Case $Answ = 2 ;Cancel Return SetError(1) EndSelect EndIf ConsoleWrite("Test Passed" & @LF) Return EndFunc ;==>_Test Edited January 5, 2009 by RAMzor Link to comment Share on other sites More sharing options...
Developers Jos Posted January 5, 2009 Developers Share Posted January 5, 2009 (edited) you need to return and pass the @error after _Test returns. _Test() If @error Then MsgBox(16, "", "::: Communication ERROR :::") Else MsgBox(0, "", "Test successfull") EndIf Func _Test() $AnswTest = MsgBox(4, "TEST", "Test Passed?") If $AnswTest = 7 Then; NO (Test Failed) $Answ = MsgBox(21, "Error", "Communication ERROR") Select Case $Answ = 4;Retry _Test() return SetError(@error) Case $Answ = 2;Cancel Return SetError(1) EndSelect EndIf ConsoleWrite("Test Passed" & @LF) Return EndFunc ;==>_Test I would avoid the recursion in this case and make the _Test func like this: Func _Test() While MsgBox(4, "TEST", "Test Passed?") = 7 If MsgBox(21, "Error", "Communication ERROR") = 2 Then Return SetError(1) WEnd ConsoleWrite("Test Passed" & @LF) Return EndFunc ;==>_Test Edited January 5, 2009 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
RAMzor Posted January 5, 2009 Author Share Posted January 5, 2009 Thank you very much! All works! In my example I used the "aaa" for illustrative purposes only, in reality, instead, there are a lot of code. Therefore, the second example does not fit me. 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