Public vs Shared

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

What is the difference between a public and a shared sub?

Thanks

Regards
 
John said:
Hi

What is the difference between a public and a shared sub?

Thanks

Regards

You are comparing apples and bananas there.

Public vs. Private
Shared vs. Not Shared

A shared sub is one that can be called without instantiating the class.
For example you can call messagebox.show without creating a messagebox
class. A shared sub must be public to be called.

Chris
 
Chris said:
A shared sub must be public to be called.

.... or 'Friend' or 'Protected Friend' -- it depends on which place you are
calling the method from.
 
: Hi
:
: What is the difference between a public and a shared sub?
:
: Thanks
:
: Regards


A shared sub is one that is not associated with a specific instance of a
class. For example, when you write to the console, you don't have to
create an instance of the 'System.Console' class in order to generate
the desired output.


Ralf
 
John,

In the documentation about program languages is mostly used Static and
Public.

The first tells something about the way how members in memory are handled
the other about the rights how to use those.

VB has already a keyword Static (Shortly described: A value inside a
procedure that goes not out of scope at the end of a procedure)

In other words Shared is used in VBNet where mostly C derived languages use
Static.

I can understand your confusion, I find sharing not so a nice name, maybe
was the translation. Sharing the memory by all members of an application. In
fact is a Module a kind of Shared (Static) Class.

Public has the normal meanings for Public, which means that a member in a
class can be reached by "EveryBody". For this are extra keywords to limit
this again.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top