05-28-2025, 09:53 AM
Guys, I don't know why you like to overthink these things. Let me give you some simple truths about SUBS and FUNCTIONS:
1) SUBS and FUNCTIONS perform in exactly the same way. Anything you do with one, you can do with the other. The *ONLY* difference is that a FUNCTION returns a value via the NAME, while a SUB doesn't. There is absolutely nothing stopping you from swapping between a SUB or FUNCTION interchangably.
The only caveat to that is that FUNCTIONS can be passed as parameters or operators and SUBS can't. A SUB has to be a stand-alone process and can't be part of the same line segment or passed as a parameter or operator.
X = X + Foo(whatever) <-- Foo is a Function, it can be used in the formula to the left with no issue.
FUNCTION Foo (whatever)
Foo = whatever * whatever
END FUNCTION
You can't do something like:
X = X + Foo whatever, return <-- Trying to call this sub will generate errors and die on you.
SUB Foo (whatever, return)
return = whatever * whatever
END SUB
Foo whatever, return: X = X + return <-- Note that this *WILL* work just fine for you.
SUB Foo (whatever, return)
return = whatever * whatever
END SUB
There's honestly no real magic difference between one or the other. The only real difference is that FUNCTIONS return a value from their name, and they can be used as a parameter or operator. That's it. Otherwise, the two follow 100% of the same rules and behavior with each other.
1) SUBS and FUNCTIONS perform in exactly the same way. Anything you do with one, you can do with the other. The *ONLY* difference is that a FUNCTION returns a value via the NAME, while a SUB doesn't. There is absolutely nothing stopping you from swapping between a SUB or FUNCTION interchangably.
The only caveat to that is that FUNCTIONS can be passed as parameters or operators and SUBS can't. A SUB has to be a stand-alone process and can't be part of the same line segment or passed as a parameter or operator.
X = X + Foo(whatever) <-- Foo is a Function, it can be used in the formula to the left with no issue.
FUNCTION Foo (whatever)
Foo = whatever * whatever
END FUNCTION
You can't do something like:
X = X + Foo whatever, return <-- Trying to call this sub will generate errors and die on you.
SUB Foo (whatever, return)
return = whatever * whatever
END SUB
Foo whatever, return: X = X + return <-- Note that this *WILL* work just fine for you.
SUB Foo (whatever, return)
return = whatever * whatever
END SUB
There's honestly no real magic difference between one or the other. The only real difference is that FUNCTIONS return a value from their name, and they can be used as a parameter or operator. That's it. Otherwise, the two follow 100% of the same rules and behavior with each other.