Well I have to wonder why you would have ANY instruction (either Function or Sub) where you don't care how it went. If you don't care, then why even run it? If it does not matter whether it worked properly (or not), then why not simply not run it? As Skip mentions errors - what if there IS an error?
In any case,
generally functions are used to return a single value. They don't have to, but generally that is what they are used for. Functions of course can, and do, have multiple instructions. But they are generally used to return a single value.
Subs are simply chunks of instructions.
So:
myFunction a, b
really is acting somewhat as a Sub. I am not sure why you would change it to a function. If it is a chunk of instructions - taking parameters "a" and "b" and
doing something with them - and you don't care about getting any return value, then really it is a sub.
In practical terms....it doesn't matter. If a function does not have an explicitly defined value to return, it will do the instructions within the function anyway. For example:
Code:
Function DoThis()
Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdStory
End Function
Sub testFunction()
MsgBox DoThis
End Sub
If you run the
Sub testFunction you will get a blank messagebox - as there is no VALUE for DoThis. The
instructions within DoThis will be carried out - the Selection will be moved to the start of the document, then moved to the end of the document.
In the above, again, general practice would have those instructions as a Sub, not a Function.
Code:
Function DoThis() As String
Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdStory
DoThis = "Selection is now at the end of the document."
End Function
Sub testFunction()
MsgBox DoThis
End Sub
Running the Sub testFunction would display a messagebox with the VALUE of the function (defined as a String).
Another example:
Code:
Function DoThis() As Long
Selection.GoTo What:=wdGoToTable, _
Which:=wdGoToFirst, Count:=3, Name:=""
DoThis = Selection.Range.Start
End Function
Sub testFunction()
MsgBox DoThis
End Sub
In this case, running the Sub testFunction will action the instructions of the Function (move the Selection to the start of the third table in the document), and display the VALUE of the returned function. In this case the numeric location of the Selection point - ie. the location, as Long, of the first charcter, in cell (1,1) of the third table in the document.
There is nothing
wrong with having a function with no explicit return value. IMHO though...you may as well use a Sub. The purpose of functions, again IMHO, is in fact to return a value. Subs, in themselves, do NOT return a value. Of course they can be used to SET a value.
Functions on the other hand are/were designed specifically to return a value.
Bottom line? There is nothing wrong with using:
myFunction a,b
I, however, prefer to use Subs as chunks of instructions, and Functions as chunks of instructions that tell me something afterwords.
Gerry
My paintings and sculpture