I know a the difference between a function and a sub, but when do I use function instead of a sub is confusing...
Best Regards!
Eric
Printable View
I know a the difference between a function and a sub, but when do I use function instead of a sub is confusing...
Best Regards!
Eric
just use a function if you want to return a value. if you just want a bunch of code to do stuff, use a sub.
You use a function when you need to return a value. If you don't need anything returned, use a sub.
or if i only use function. What will happen then?
The difference between a subroutine and a function is that the
name of a subroutine is a way for the subroutine to be identified and called.
For a function, its name doubles as a variable declaration
that may be returned to the calling program.
If you use a function in the following way
VB Code:
Private Sub Command1_Click() Dim a As Double a = test MsgBox a End Sub Function test() As Double MsgBox "hgi" End Function
The function executes the msgbox command and returns a double.
My point was that a function returns a value even if you treat it like a sub and don't assign a return value, in response to:
My interpretation was he was asking what would happen if you only ever used functions and not subs.Quote:
or if i only use function. What will happen then?
I was trying to illustrate (with code rather than words) that even when you use a function like a sub and don't explicitly assign a retrun value, it still returns a value.
I knew what I was saying :p
LOL.
I hate writing. Watch how scarce I become if I ever hear the words: help files or documentation :eek: !
thanx for the help, but how would that affect the speed?:confused:
As a guess, I would say function to do the same thing vs sub, then the sub would use a little less memory and perhaps run a simgde slower.
In reality it doesn't really matter as other parts of your code will be the performance bottleneck and not this issue.