|
-
May 22nd, 2001, 05:23 AM
#1
Thread Starter
Hyperactive Member
Subs and Functions
what is the difference between the 2 ? ohter than subs cant return any result While functions do ...
-
May 22nd, 2001, 05:28 AM
#2
That's it! I don't belive there are any differences besides that.
-
May 22nd, 2001, 05:28 AM
#3
Addicted Member
>subs cant return any result While functions do ...
That is the difference.
-
May 22nd, 2001, 05:28 AM
#4
Fanatic Member
There is no other difference
-
May 22nd, 2001, 06:02 AM
#5
Conquistador
Megatron knows the answer
-
May 22nd, 2001, 06:18 AM
#6
Originally posted by da_silvy
Megatron knows the answer
So do I .
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"))
-
May 22nd, 2001, 07:54 AM
#7
Thread Starter
Hyperactive Member
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 ...
-
May 22nd, 2001, 11:14 AM
#8
Hyperactive Member
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 ...
A very good question, indeed. I have often wondered about this myself.
I am speculating, but I would assume that functions require more resources(just thinking the MS way of things).
-
May 22nd, 2001, 04:17 PM
#9
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.
-
May 22nd, 2001, 04:21 PM
#10
Originally posted by da_silvy
Megatron knows the answer
That's right 
Sub's do not return a value, while functions do. If you don't explicitly specify a return value, it will return Empty.
-
May 22nd, 2001, 07:21 PM
#11
Registered User
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.
-
May 23rd, 2001, 02:13 AM
#12
Member
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
Matt Bradbury
An optimist will claim the glass is half full.
A pessimist that it is half empty.
I just think the glass is too big.
-
May 23rd, 2001, 02:48 AM
#13
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.
-
May 23rd, 2001, 02:42 PM
#14
Thread Starter
Hyperactive Member
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 ).
-
May 23rd, 2001, 11:45 PM
#15
Registered User
You either must use api create thread or make an ax exe.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|