SoyEli Active Member Licensed User Longtime User May 17, 2013 #1 Hello: I need to exit a sub without a return value: If I use true, then it "eats" the MSG If I use false, then it continues to the end sub. How can I exit a sub ? Like on a "MessageReceived", I don't want the return true to "eat" the MSG, just exit the sub. Thank you:
Hello: I need to exit a sub without a return value: If I use true, then it "eats" the MSG If I use false, then it continues to the end sub. How can I exit a sub ? Like on a "MessageReceived", I don't want the return true to "eat" the MSG, just exit the sub. Thank you:
Erel B4X founder Staff member Licensed User Longtime User May 17, 2013 #2 If I use true, then it "eats" the MSG Click to expand... Is this your sub or a specific event? Upvote 0
SoyEli Active Member Licensed User Longtime User May 17, 2013 #3 A sub "GetMsg_MessageReceived(From As String,Body As String) As Boolean" Upvote 0
JesseW Active Member Licensed User Longtime User May 17, 2013 #4 SoyEli said: ...How can I exit a sub ? Like on a "MessageReceived", I don't want the return true to "eat" the MSG, just exit the sub... Click to expand... Use the Return keyword without any return values. I'm not quite certain if a False or Null will be returned, tho... Code: Sub GetMsg_MessageReceived(From As String,Body As String) As Boolean ' ' do some stuff ' ' return true to eat the msg ' Return True ' ' simply exit the sub ' Return End Sub Last edited: May 17, 2013 Upvote 0
SoyEli said: ...How can I exit a sub ? Like on a "MessageReceived", I don't want the return true to "eat" the MSG, just exit the sub... Click to expand... Use the Return keyword without any return values. I'm not quite certain if a False or Null will be returned, tho... Code: Sub GetMsg_MessageReceived(From As String,Body As String) As Boolean ' ' do some stuff ' ' return true to eat the msg ' Return True ' ' simply exit the sub ' Return End Sub
SoyEli Active Member Licensed User Longtime User May 17, 2013 #5 Thank you for the help: With above it will "eat" the MSG. and if no value is used I get a error. Upvote 0
agraham Expert Licensed User Longtime User May 18, 2013 #6 A Sub always returns a value even if it does not have an explicit "Return" statement. In the case of an "As Boolean" Sub the return can only be True or False. In the absence of an explicit "Return", or if the "Return" statement does not specify a value, the value of the returned value defaults to False. The "Not all return paths return a value" is only a warning, the code will still compile and run and the return value will be False for those paths missing an explicit "Return somevalue" statement. Upvote 0
A Sub always returns a value even if it does not have an explicit "Return" statement. In the case of an "As Boolean" Sub the return can only be True or False. In the absence of an explicit "Return", or if the "Return" statement does not specify a value, the value of the returned value defaults to False. The "Not all return paths return a value" is only a warning, the code will still compile and run and the return value will be False for those paths missing an explicit "Return somevalue" statement.