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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
cashdeskmac said:
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
 
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
 
m.posseth said:
well with byref parameters a sub can also return values ,,,,

Even a 'ByVal' parameter of a reference type can do that ;-).
 
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
 
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
 
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
 
Cor,

Cor Ligthert said:
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.
 
Herfried K. Wagner said:
Cor,



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
 
Armin Zingler said:
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 :-).
 

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.
 
Michael D. Ober said:
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
 
it is NOT a way to return a value... since you dont actually "return" a value but u change the value of a object(since ur using a reference) ... as already mentioned this is "side effect programming" and if u dont seriously need to, DONT DO IT !!!!

p.s.: i just noticed that this thread hasn't been answered to in years, it just made me, well, angry... :mad:
 
Last edited:
Back
Top