473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
13 1788
"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

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
"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
"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
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
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
"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
>
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
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
"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
"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

"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Johnny | last post by:
Hi, I wonder what is the difference between the built-in function getattr() and the normal call of a function of a class. Here is the details: getattr( object, name) Return the value of...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
12
by: z. f. | last post by:
what's the difference between using the VB.NET function IIF or the c# operator ? VB.NET: a = iif ( b=c, d, e) C#: a= (b==c)?d:e TIA, z.
5
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
6
by: JonathanOrlev | last post by:
Hello everyone, I have a newbe question: In Access (2003) VBA, what is the difference between a Module and a Class Module in the VBA development environment? If I remember correctly, new...
2
by: dolphin | last post by:
What is the different between c++ call convention and c call convention?Can some give some examples?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.