what is the difference between the 2 ? ohter than subs cant return any result While functions do ...
Printable View
what is the difference between the 2 ? ohter than subs cant return any result While functions do ...
That's it! I don't belive there are any differences besides that.
>subs cant return any result While functions do ...
That is the difference.
There is no other difference :D
Megatron knows the answer
Quote:
Originally posted by da_silvy
Megatron knows the answer
So do I :rolleyes:.
A sub is code that does not need to return anything.
(Example:
Private Sub Message(msg)
Msgbox msg
End Sub
Usage
Message "Hello" )
And a function returns something.
(Example:
Private Function Message(msg As String) As String
Message = msg
End Function
Usage
Msgbox Message("Hello"))
i know that already .but functions dont need to return anything.
they can , but they dont have too. so question is.
in terms of Memory Usage , Processing speed etc ...
A very good question, indeed. I have often wondered about this myself.Quote:
Originally posted by razzaj
i know that already .but functions dont need to return anything.
they can , but they dont have too. so question is.
in terms of Memory Usage , Processing speed etc ...
I am speculating, but I would assume that functions require more resources(just thinking the MS way of things).:p
Functions ALWAYS returns something!!
It just a matter of what, if you are changing the value, the function will either return false, "", 0 or nothing, which depends on the function declaration. So it returns something.
If you call a function, either by Call or just by its name, it will still return something, the return value just won't be stored, and consequensly therefore be destroyed.
So functions will ofcourse use more resources then subs.
That's right ;)Quote:
Originally posted by da_silvy
Megatron knows the answer
Sub's do not return a value, while functions do. If you don't explicitly specify a return value, it will return Empty.
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 variable declaration
that may be returned to the calling program.
a function will always take up more memory than a sub will, when you declare a function you are also declaring a variable, if you don't set the functions return type then it is set as a variant. Either way it declares a variable by the same name as the function therefore taking up more memory, if you do not need a block of code to return something then use a sub. and BTW, subs can return values also, just not the same way functions do :)
Subs CAN'T return values.
They can however modify varibles parsed on to them with the byref statement, but so can functions.
Modidifying a variable parsed on by referece is not the same as returning a value from a function call.
since we all agree on this. now is ther a way to call a sub , and not without having VB wait for it finish ( this could be a sub or a function ).
You either must use api create thread or make an ax exe.