return with no value

SoyEli

Active Member
Licensed User
Longtime User
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:
 

JesseW

Active Member
Licensed User
Longtime User
...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...

Use the Return keyword without any return values. I'm not quite certain if a False or Null will be returned, tho...

B4X:
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:
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
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
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…