Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
subs and functions
#1
how do u know if something should be

sub hi() or funtion hi()
Reply
#2
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.

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)