Shared means that it is "shared" accross all instances of a class and
therefore, you don't need any particular instance to use it.
Here's an example:
The System.Windows.Forms.MessagBox class is very popular in Windows
applications. To use it, you just type:
MessageBox.Show(message, etc.)
But, you don't have to create an instance of the class to use it first (Dim
MessageBox as New MessageBox). You can just call the Show method of the
MessageBox class because the Show method is declared "shared".
With properties that are declared as "shared", it means 2 things. One is
that the value of the property is shared accross all instances of the class,
so take this example:
Dim x as New Foo
x.SomeSharedProperty = 17
Dim y as New Foo
MessageBox.Show(y.SomeSharedProperty)
What will the MessageBox wind up showing? You guessed it, 17! The 2
instances of the class "share" the value of the shared property. If on
instance of the class changes the property value, then the value changes for
all of the instances of the class.
Now the second meaning of shared on a shared property is the same as
described in the first example. You don't even need an instance of the
class to access the property. So, I could have set the SomeSharedProperty
value to 17 on the "type" Foo, without having to create an instance of it.
Lastly, the keyword "Public" just means that the element will be available
outside of the class module it was created in.
Hope that helps.
Scott M.
"Chris" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
Hello,
I'm just getting started with VB and am new to the group,
so please excuse what may seem to be a rudimentary
question.
I've been writing basic programs and have noticed that the
syntax for some of these functions have been set up with
the keywords "Public Shared Function" (for example, the
Trim function) and others are set up just as "Public
Function" (for example, the IsNumeric function).
Before I came here, I tried to answer my own question,
thinking that the reason for the "Shared" keyword was that
the function would be available no matter where I went in
VB. But it works this way for both types.
Why do some functions include the "shared" keyword, and
others do not?
Thanks in Advance,
Chris