18.1. Declaration of subroutines and function

[<<<] [>>>]

You can declare a function like

FUNCTION MyFunction(var1, var2, var3)
 REM function body
END FUNCTION

You can call the function in any expression, like

A = MyFunction(1,2,3)

Subroutine declaration is almost the same:

SUB MySub(Var1,Var2, Var3)
 REM subroutine body
END SUB

You can call the subroutine using the CALL statement:

CALL MySub(1,2,3)

The major difference between functions and subroutines is that subroutines do not have values returned. However ScriptBasic does not differentiate between functions and subroutines. SUB and FUNCTION are just two keywords that you can use almost interchangeable. A subroutine can return a value and functions may be called using the call statement, although this is not recommended.


[<<<] [>>>]