05-21-2025, 02:33 AM
SUBS *do* something. FUNCTIONS *return* something. <--That's the difference between the two.
CLS, PRINT, BEEP, and SLEEP all *do* something for you; they're all SUBS. CLS will clear the screen. PRINT will print something to the screen. BEEP makes your wife go crazy at 2 AM. SLEEP, contrary to the name doesn't help you cure insomnia....
On the other hand, COS, ABS, INT, and RND are all FUNCTIONS, as they return *something* to us. COS returns the cosine value of the angle we give it. ABS returns the absolute value of a number. INT tells you what someone's IQ is, and RND is good for random pickup lines at a bar.. (Or something like that.
)
To use a function, you need two basic things:
1) To give the function a NAME
2) To assign a value to that function's NAME before exiting the function
FUNCTION foo&
foo& = 3
END FUNCTION
Function Steve$
Steve$ = "Steve is Awesome"
END FUNCTION
Notice that the function name is important in marking what TYPE of return value we want. foo& is a LONG. Steve$ is a STRING. It's that simple to make your function.
Parameters are simply passed so that you can do something more useful than what I'm doing above with those pitiful functions.
Function AddString$ (first$, second$)
AddString$ = first$ + " " + second$
End Function
And then to make use of it is to either assign it to a return value, or else use it as an operation for a SUB.
MyName$ = AddString$("Steve","McNeill")
PRINT MyName$
Or just: PRINT AddString$("Steve","McNeill")
The first MyName$ is assigning the return to the variable MyName$. The second is sending it to a SUB to do something directly. (Print, in this case.)
That's all there is to it. Nothing complex or complicated to see here.
CLS, PRINT, BEEP, and SLEEP all *do* something for you; they're all SUBS. CLS will clear the screen. PRINT will print something to the screen. BEEP makes your wife go crazy at 2 AM. SLEEP, contrary to the name doesn't help you cure insomnia....
On the other hand, COS, ABS, INT, and RND are all FUNCTIONS, as they return *something* to us. COS returns the cosine value of the angle we give it. ABS returns the absolute value of a number. INT tells you what someone's IQ is, and RND is good for random pickup lines at a bar.. (Or something like that.

To use a function, you need two basic things:
1) To give the function a NAME
2) To assign a value to that function's NAME before exiting the function
FUNCTION foo&
foo& = 3
END FUNCTION
Function Steve$
Steve$ = "Steve is Awesome"
END FUNCTION
Notice that the function name is important in marking what TYPE of return value we want. foo& is a LONG. Steve$ is a STRING. It's that simple to make your function.
Parameters are simply passed so that you can do something more useful than what I'm doing above with those pitiful functions.

Function AddString$ (first$, second$)
AddString$ = first$ + " " + second$
End Function
And then to make use of it is to either assign it to a return value, or else use it as an operation for a SUB.
MyName$ = AddString$("Steve","McNeill")
PRINT MyName$
Or just: PRINT AddString$("Steve","McNeill")
The first MyName$ is assigning the return to the variable MyName$. The second is sending it to a SUB to do something directly. (Print, in this case.)
That's all there is to it. Nothing complex or complicated to see here.
