Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cpjamloki
Visitor

difference b/w Sub and Function

Hi
i am willing to know that what is the actual difference b/w Sub and Function. If i am not wrong Sub is using for return type void. But as a roku prospect i want to know that from where we should use SUB and where we should use FUNCTION keyword.
please suggest me with example.

and If i want to exit from function forcefully.what is the method there. if i use return keyword it should have some value.
0 Kudos
3 REPLIES 3
Komag
Roku Guru

Re: difference b/w Sub and Function

If you declare a function with type "as void" then you can exit it with "return" without any value
0 Kudos
malort
Visitor

Re: difference b/w Sub and Function

Basically, Sub() is a shortcut for Function() as Void. Staring from the docs
The statement "Sub" can be used instead of "function" as a shortcut to a function of Void return Type.


To exit early, you have some options. You do not need to have a return value (you can't) if you use Sub() or Function() as Void. If you don't specify a type, Function(), or use Function() as Dynamic, then you can return anything you'd like, but you must return something (invalid or not). If you do expect to always return a specific type, e.g. an integer, then use Function() as Integer, and return with valid integer.
0 Kudos
cpjamloki
Visitor

Re: difference b/w Sub and Function

thanx guys for sharing your nice views.
0 Kudos