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

nub question

P: n/a
I'm new to programming and alot of the tutorials and books i'm looking at
have things like
Public Sub, Private Sub, Public Function, etc what is the difference on the
3 and when should each one be used?
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You missed a 4th one: Private Function.

Function vs. Sub: A function returns a value from it. A sub does not
return a value. So the choice is of which to use obvious based on if you
need a value returned

Public vs. Private: This is a scope identifier. Public function/subs can be
called from outside the class. Private function/subs can be called only
inside the class. Use private unless you have a reason to make the function
aviable from outside the class. Any function you call such as
String.SubString(...) is marked as public.

Chris
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
I'm new to programming and alot of the tutorials and books i'm looking at
have things like
Public Sub, Private Sub, Public Function, etc what is the difference on
the
3 and when should each one be used?

Nov 21 '05 #2

P: n/a
Subs or subroutines are different from functions only in that a function
will return something, where a sub is not intended to return anything to the
caller.

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
I'm new to programming and alot of the tutorials and books i'm looking at
have things like
Public Sub, Private Sub, Public Function, etc what is the difference on
the
3 and when should each one be used?

Nov 21 '05 #3

P: n/a
Mike,

In C related languages
Void = Sub in VB(Net)
The rest is Function

In an otherway told
Sub does not return a value/object
Function should always have a as x, which is the return type.

Private, Friend, Public, Protected is about the access you give to those
methods.

http://msdn.microsoft.com/library/de...essibility.asp

I hope this helps?

Cor
"Mike" <Mi**@discussions.microsoft.com>
I'm new to programming and alot of the tutorials and books i'm looking at
have things like
Public Sub, Private Sub, Public Function, etc what is the difference on
the
3 and when should each one be used?

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.