VBA Code Protection > Supported VBA syntax by compiler > function and sub declaration
Declaration of functions and subs are similar to basic. In functions to return function values, use implicit declared variable which has the same name of the function, or use Return statement. Parameters by reference can also be used, using BYREF directive.
TodayAsString = DateToStr(Date)
IF A>B THEN
MAX = A
MAX = B
SUB SwapValues(BYREF A, B)
TEMP = A
A = B
B = TEMP
You can also declare subs and functions as private or public using the following syntax:
PRIVATE SUB Hello
PUBLIC FUNCTION Hello
Subs and functions are public by default.
You can use Return statement to exit subs and functions. For functions, you can also return a valid value.
SUB UpcaseMessage(Msg) ShowMessage(Uppercase(Msg))
'This line will be never reached
Copyright © 2021 G.D.G. Software