September 4th, 2003, 10:46 PM
Sub vs Function
Can we create functions (not subs) in VB? If so, what is the diff between FUNCTION and SUB?
private sub cmd_click
private function cmd_click
September 5th, 2003, 12:15 AM
you can create functions in vb. however, an event is not a function. it is always a sub. the difference between a sub and a function is a function can return a value.
Private Function Multiply(X As Integer, Y As Integer) As Integer
' inside the function you can use the function
' name as a variable. this is how you return
' a value from a function.
Multiply = X * Y
' an example call
Dim product As Integer
product = Multiply(5, 4)
September 5th, 2003, 11:13 AM
LOL, is that the only diff between sub and function? As I vaguely remember, other modern languages like java do not differentiate sub/function/method?
September 5th, 2003, 04:29 PM
well functions are a little slower. "modern" languages do have a sub/function difference only they do not use a different word for it. you would specify void for a sub that doesn't return a value and any other data type if it does return a value. that isn't an issue of being "modern" as vb.net uses the sub and function keywords. it's all a mater of syntax and BASIC vs C.