Mirage Source
subs and functions - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: General (https://mirage-engine.uk/forums/forumdisplay.php?fid=17)
+---- Thread: subs and functions (/showthread.php?tid=728)



subs and functions - Ramsey - 10-02-2007

how do u know if something should be

sub hi() or funtion hi()


- Spodi - 10-02-2007

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.