pixelsearch Posted January 21, 2019 Share Posted January 21, 2019 Hi everybody I have a script where a function can Return the string "retry" or alternatively simply Return to main (by using the word Return or reaching the end of the function) But it doesn't work as expected, as a simple Return displays the MsgBox in the following script, which is not what is expected. In fact, a few tests show that 4 different Return's fire the MsgBox, these are : Return, Return 0, Return "retry", Return True If test() = "retry" then MsgBox(0, "", "yes") Func test() Return ; Return 0 ; equivalent to Return (in UDF's) or end of function reached ; Return 1 ; Return "retry" ; Return True ; Return False EndFunc I found a strange way to fix this, it's to use == instead of = (though the help file states that "== should only be used if string comparisons need to be case-sensitive") If test() == "retry" then MsgBox(0, "", "yes") With == everything works perfectly as only "retry" will match, great ! Of course, I could have returned only numeric values (instead of "retry") and the issue would have disappeared. Is there something I am missing in this Return string behavior ? Thanks Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 21, 2019 Share Posted January 21, 2019 @pixelsearch The MsgBox() is displayed because, numerically, the string "retry" is equal to 0. Look in the example above: ; Returns 0 ConsoleWrite("retry = " & Number("retry") & @CRLF) ; Returns True, since 0 = 0 ConsoleWrite("Test() = " & (Test() = "retry") & @CRLF) ; The MsgBox is displayed If Test() = "retry" Then MsgBox(0, "", "Retry!") Func Test() Return ; The keyword Return will always return 0 if a different value is not specified EndFunc This behaviour is explained here, under the section "Comparing different datatypes" pixelsearch 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
pixelsearch Posted January 21, 2019 Author Share Posted January 21, 2019 Thanks Francesco Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 21, 2019 Share Posted January 21, 2019 @pixelsearch You're welcome Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette 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