Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / March 2008

Tip: Looking for answers? Try searching our database.

.NET VB WinForms reference to the class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick - 11 Mar 2008 22:24 GMT
Hi,

In C++, if there's a class named clsMyForm, which has a static
("shared" in VB.NET) member variable named "Total" , and an instance
(object) of the class named oMyForm, the static member of the class,
can be referenced thru the instance as follows:
oMyForm::clsMyForm.Total

In VB .NET, if I have a Windows Form class named clsMyForm, which has
a shared member variable named "Total" , and an instance of the class
named oMyForm, how do I reference the shared members of the class thru
the instance oMyForm?

Thanks in advance,

Rick
Jon Skeet [C# MVP] - 11 Mar 2008 22:31 GMT
> In C++, if there's a class named clsMyForm, which has a static
> ("shared" in VB.NET) member variable named "Total" , and an instance
[quoted text clipped - 6 lines]
> named oMyForm, how do I reference the shared members of the class thru
> the instance oMyForm?

Regardless of whether you *can* do this in VB.NET (which I believe you
can, although these days it might produce a warning) it's a bad idea.

It leads the reader to think that it's an *instance* member. Just use
the type name, which makes it obvious that you're accessing a static
member.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Rick - 12 Mar 2008 14:46 GMT
I still would like to know how to do this in VB .NET, if anyone knows.

Thank you in adavance
Jon Skeet [C# MVP] - 12 Mar 2008 16:02 GMT
> I still would like to know how to do this in VB .NET, if anyone knows.

I believe you just reference it as if it were an instance member.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.