By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,742 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,742 IT Pros & Developers. It's quick & easy.

What's the difference between a function and a sub?

P: n/a
I am a newbie to C# and have come across some VB .NET code in my studies. I
notice that VB uses functions and subs, and was wondering what the difference
was. Is it that one has a return value and the other doesn't?
Nov 21 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
"cashdeskmac" <ca*********@discussions.microsoft.com> schrieb
I am a newbie to C# and have come across some VB .NET code in my
studies. I
notice that VB uses functions and subs, and was wondering what the
difference was. Is it that one has a return value and the other
doesn't?


Yes, it is.

Armin
Nov 21 '05 #2

P: n/a

well with byref parameters a sub can also return values ,,,,

maybe a better explanation if you can follow me , is that a sub is a
method that doesn`t return values by its method name , and a function is a
method that can return values by it`s method name
"Armin Zingler" <az*******@freenet.de> wrote in message
news:uq**************@TK2MSFTNGP14.phx.gbl...
"cashdeskmac" <ca*********@discussions.microsoft.com> schrieb
I am a newbie to C# and have come across some VB .NET code in my
studies. I notice that VB uses functions and subs, and was wondering
what the
difference was. Is it that one has a return value and the other
doesn't?


Yes, it is.

Armin

Nov 21 '05 #3

P: n/a
"m.posseth" <mi*****@nohausystems.nl> schrieb

well with byref parameters a sub can also return values ,,,,
Yes, but not as the function value. That's what he meant (probably).
maybe a better explanation if you can follow me , is that a sub is
a method that doesn`t return values by its method name , and a
function is a method that can return values by it`s method name
"Armin Zingler" <az*******@freenet.de> wrote in message
news:uq**************@TK2MSFTNGP14.phx.gbl...
"cashdeskmac" <ca*********@discussions.microsoft.com> schrieb
I am a newbie to C# and have come across some VB .NET code in my
studies. I notice that VB uses functions and subs, and was
wondering what the
difference was. Is it that one has a return value and the
other doesn't?


Yes, it is.

Armin

Nov 21 '05 #4

P: n/a
"m.posseth" <mi*****@nohausystems.nl> schrieb:
well with byref parameters a sub can also return values ,,,,


Even a 'ByVal' parameter of a reference type can do that ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #5

P: n/a
Herfried,

Even a 'ByVal' parameter of a reference type can do that ;-).

No it does not "return" a value, those can be set.

A sub is just a void function.

Cor
Nov 21 '05 #6

P: n/a
Michel.

I don't agree with you, a void function (in VBNet a Sub) does not "return" a
value. You can set values, however those are not returned.

You can use them afterwards, however that I see as a complete different
approach, as there are than more possibilities. (By instance set values in
modules or whatever)

Just my thought,

Cor
Nov 21 '05 #7

P: n/a
"Cor Ligthert" <no************@planet.nl> schrieb:
Even a 'ByVal' parameter of a reference type can do that ;-).

No it does not "return" a value, those can be set.


It depends on how you define "returing a value".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #8

P: n/a
>
It depends on how you define "returing a value".


Maybe in Thuringen however for the rest of the world it is well knowed.

A = B where B returns a value to A.

Cor

Nov 21 '05 #9

P: n/a
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
It depends on how you define "returing a value".


Maybe in Thuringen however for the rest of the world it is well knowed.

A = B where B returns a value to A.


I still believe that using output parameters is one technique to "return"
values.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #10

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
It depends on how you define "returing a value".


Maybe in Thuringen however for the rest of the world it is well
knowed.
A = B where B returns a value to A.


I still believe that using output parameters is one technique to
"return" values.

Yes, but talking about the difference between subs and functions, the
statement "Is it that one has a return value and the other doesn't?" it's
for sure related to the function return value. I think you know this. :-)

Armin

Nov 21 '05 #11

P: n/a
"Armin Zingler" <az*******@freenet.de> schrieb:
It depends on how you define "returing a value".

Maybe in Thuringen however for the rest of the world it is well
knowed.
A = B where B returns a value to A.


I still believe that using output parameters is one technique to
"return" values.


Yes, but talking about the difference between subs and functions, the
statement "Is it that one has a return value and the other doesn't?" it's
for sure related to the function return value. I think you know this. :-)


Yeah, I know this :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #12

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eO**************@TK2MSFTNGP12.phx.gbl...
"Armin Zingler" <az*******@freenet.de> schrieb:

I still believe that using output parameters is one technique to
"return" values.


This is also referred to as "side-effect" programming. There are times when
it's necessary, but as a general rule, it is harder to maintain code that
returns values in parameters. The most common usage for this is in a
function that returns a status code and puts a value (usually a string or
byte array) in a passed parameter. The windows API is full of these.

Mike Ober.

Nov 21 '05 #13

P: n/a

"Michael D. Ober" <mdo.@.wakeassoc..com> escribió en el mensaje
news:ei****************@TK2MSFTNGP14.phx.gbl...
This is also referred to as "side-effect" programming. There are times
when
it's necessary, but as a general rule, it is harder to maintain code that
returns values in parameters.


Java? ;-)

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
Nov 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.