10-02-2007, 04:44 AM
Function returns a value, sub does not. In the end, it can do the same thing, it just depends on how you want to do it.
In the end, I = 2 * 2 both ways. The "ByRef" means that it is "By Reference" instead of "By Value". If you pass as ByRef, and change that value, it changes the variable used in the call.
Code:
Dim I as long
i = Multiply(2, 2)
Function Multiply(byval a as long, byval b as long) as long
Multiply = A * B
End Function
Code:
Dim I as Long
Multiply 2, 2, I
Sub Multiply(Byval A as long, byval B as long, byref Return as long)
Return = A * B
End Sub
In the end, I = 2 * 2 both ways. The "ByRef" means that it is "By Reference" instead of "By Value". If you pass as ByRef, and change that value, it changes the variable used in the call.