Think of it like this:
In simple terms, a subroutine (or procedure) is
exactly the same as a function apart from two things...
1. The way you call them.
2. How variables behave inside them.
Many people say you should always use functions rather than procedures, but off the top of my head I can't think of much you could do with a function that isn't possible with a procedure.
As far as speed is concerned, there's little if any difference between them so that isn't a factor in deciding which to use.
The way you call a function makes them good for creating your own commands. For example, take the following small snippet:
Ink RGB(255,0,0)
Text 100,100,"Red Text"
If you want to place lots of text in various colours at different positions on the screen, you could create a new command (function) to do it:
Function ColourText(X,Y,R,G,B,S$)
Ink RGB(R,G,B)
Text X,Y,S$
EndFunction
So, to print "Blue Text" in blue at 200 across and 200 down you would then use:
ColourText(200,200,0,0,255,"Blue Text")
You could still do the same with a procedure - you would just set the required variables up (remember they are global) and then use Gosub.
The function does allow you however, to include the call in a DB statement. If your function for example returns a value, it allows you to do things like:
If MyFunction(XPos, YPos) < 100 Then Gosub DoSomething
This would not be possible with a procedure.
Variables also have to be passed to a function in brackets because all variables inside a function are
local - in other words, are totally separate from those with the same name
outside the function. Compared to procedures (where all variables outside the procedure can be seen within it), this can be a hinderance in some situations.
The big downer with functions is that you can only pass a single variable back from a function, though you can 'cheat' using arrays. Procedures on the other hand can modify ANY variables and they remain altered on exiting from the procedures .
At the end of the day, it doesn't really matter which you use.
Personally I always use procedures unless using a function makes a task easier, in which case I use them instead.
TDK