Class Variables

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

John

Hi

How should I define a variable in a class so that the variable is visible to
any code that is using the class?

Thanks

Regards
 
Public Variable As Type

or

Public Shared Variable As Type

The difference is the first is an instance member, which is valid for each
instance of the class. The second is a static member, and so does not
require an instance of the class and will not be different for each
instance.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: Hi
:
: How should I define a variable in a class so that the variable is visible
to
: any code that is using the class?
:
: Thanks
:
: Regards
:
:
:
 
You may want to create a public property for the class which would allow you
to validate the data that is being passed to the property.
 
John said:
How should I define a variable in a class so that the variable
is visible to any code that is using the class?

Should it read "that is using the class" or "that is using an instance of
the class"?

\\\
Public Class Foo
Private Shared m_Bar As String
Private m_Goo As String

Public Shared Property Bar() As String
Get
Return m_Bar
End Get
Set(ByVal Value As String)
m_Bar = Value
End Set
End Property

Public Property Goo() As String
Get
Return m_Goo
End Get
Set(ByVal Value As String
m_Goo = Value
End Set
End Property
End Class
///

The property 'Bar' can be accessed without creating an instance of the class
'Foo', 'Goo' requires an instance of the class.
 
Hi Herfried,

What happened to Bla? Has it been playing with the Swamp Thing? - It seems
to have got covered in Goo!!

Regards,
fergus
 
I thought it was: Foo, Bar, Baz, Moo, Goo

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: > What happened to Bla? Has it been playing with the Swamp
: > Thing? - It seems to have got covered in Goo!!
:
: ROFL
:
: --
: Herfried K. Wagner
: MVP · VB Classic, VB.NET
: <http://www.mvps.org/dotnet>
:
:
 
Hi Tom,

|| Foo, Bar, Baz, Moo, Goo

Isn't that a delicious Thai meal?



My sequence is Foo Bar The Elephant.

If it has to go further it's then Foo Bar The Elephant Went To Town ...

A wierd mixture of Babar the Elephant and a land-based Owl and Pussycat
;-)

Regards,
Fergus
 
Fergus Cooney said:
Isn't that a delicious Thai meal?

What? Foo? Goo?
My sequence is Foo Bar The Elephant.

If it has to go further it's then Foo Bar The Elephant
Went To Town ...

A wierd mixture of Babar the Elephant and a land-based
Owl and Pussycat
;-)

ROFL
 
: If it has to go further it's then Foo Bar The Elephant Went To Town
....
To say goodbye to the circus...


Have you seen Okeydoke, the Moomins or Pingu recently. I've just bought a
Pingu DVD (for my younger brother).

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"


: Hi Tom,
:
: || Foo, Bar, Baz, Moo, Goo
:
: Isn't that a delicious Thai meal?
:
:
:
: My sequence is Foo Bar The Elephant.
:
: If it has to go further it's then Foo Bar The Elephant Went To Town
....
:
: A wierd mixture of Babar the Elephant and a land-based Owl and
Pussycat
: ;-)
:
: Regards,
: Fergus
:
:
 
Hi Tom,

|| I've just bought a Pingu DVD

That's nice - plenty Pingu.

|| (for my younger brother).

Yeah, like I believe <that>. It's ok, you can tell us, you're among
friends. ;-)

The only Okeydoke I know is "Okey-diddly-dokey" - to quote Ned Flanders.

Regards,
Fergus
 
Tom Spink said:
If it has to go further it's then Foo Bar The Elephant
Went To Town
...
To say goodbye to the circus...

Have you seen Okeydoke, the Moomins or Pingu recently.
I've just bought a Pingu DVD (for my younger brother).

?!?
 
Back
Top