Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
cpjamloki
Level 7

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
Komag
Level 9

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
Level 7

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
Level 7

Re: difference b/w Sub and Function

thanx guys for sharing your nice views.
0 Kudos