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 / January 2005

Tip: Looking for answers? Try searching our database.

Question about OOP and Class Member in VB.net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Terrance - 27 Jan 2005 12:51 GMT
Hello, everyone. I was hoping if someone could help me out with a problem
that I'm trying to solve? I have a project that I'm working on. As the
splashscreen launches for an application I check the directory for the
location of a file and I assign that directory path to a class member in my
main module; so, I have the following syntax cClass.mydirectory = (path of
file). However, when I Load a form I have to recreate the class object cClass
and the member mydirectory is now blank. I was under the impression that once
a class object is created it's stored in memory and the code should be able
to access that class member from memory. Am I wrong in assuming this? Can a
class be made global or referenced for access from all forms? Thanks.
Signature

TC

JohnFol - 27 Jan 2005 13:15 GMT
The code behind the splash screen creates an instance of the class that is
"In scope" of the splash screen. If a.n.other form / module / class creates
an instance then you have multiple instances, all with different
.MyDirectory properties.

You could have a Sub Main that holds a single  instance of the class, ant it
becomes responsbile for launching the splash screen and the subsequent form.
Then there is only 1 instance and the property is retained.

> Hello, everyone. I was hoping if someone could help me out with a problem
> that I'm trying to solve? I have a project that I'm working on. As the
[quoted text clipped - 11 lines]
> a
> class be made global or referenced for access from all forms? Thanks.
Terrance - 27 Jan 2005 15:19 GMT
Thanks JohnFol. I'll give that a shot.

> The code behind the splash screen creates an instance of the class that is
> "In scope" of the splash screen. If a.n.other form / module / class creates
[quoted text clipped - 20 lines]
> > a
> > class be made global or referenced for access from all forms? Thanks.
Terrance - 27 Jan 2005 21:43 GMT
Ok, I placed the class in the main sub but I still loose scope when I go to a
form. Here is what my main sub looks like:
Imports System.IO
Imports System.Data.OleDb

Module MainModule
   Dim vfClass As New FoxConnectionClass 'create class
   Public Sub Main()
       'Dim vfClass As New FoxConnectionClass 'create class
       'declare object for each form.
       Dim frmSplash As New fclsSplash
       Dim mainForm As New fclsMain
       Dim SqlLogin As New frmLogin

       'Directory structure to fox table.
       vfClass.mydirectory = Directory.GetCurrentDirectory & _
       "\sysconn.dbf"

       Try
           System.Windows.Forms.Application.EnableVisualStyles()
           System.Windows.Forms.Application.Run(frmSplash)
          (Remaining Code.....)

Unfortunately, when I try to access  the vfClass.mydirectory method from my
sqlLogin form it finds vfClass as not being declared. Any help would be
greatly appreciated...

> Hello, everyone. I was hoping if someone could help me out with a problem
> that I'm trying to solve? I have a project that I'm working on. As the
[quoted text clipped - 6 lines]
> to access that class member from memory. Am I wrong in assuming this? Can a
> class be made global or referenced for access from all forms? Thanks.
Sean Hederman - 28 Jan 2005 06:29 GMT
Terrance,

Keep in mind the difference between a class and an object. A class is what
you wrote, and an object is an instance of that class. So if you create two
instances of the class:
Dim vfObject1 As New FoxConnectionClass
Dim vfObject2 As New FocConnectionClass

They are totally different classes. Any properties set on one, will not
propagate to the other. However, the declaration (Dim) is actually declaring
a reference to the class (New FoxConnectionClass), so if you did:

Dim vfObject1 As New FoxConnectionClass
...
Dim vfObject2 = vfObject1

Now, both the vfObject1 reference and the vfObject2 reference are pointing
to the same object.

In your case, you're going to have to pass a reference to your vfClass into
your frmSplash.

So you could change your frmSplash constructor to be:
Public frmSplash(ByVal vfConnection As FoxConnectionClass)...

And then assign the passed-in reference to a local reference.

> Ok, I placed the class in the main sub but I still loose scope when I go
> to a
[quoted text clipped - 41 lines]
>> a
>> class be made global or referenced for access from all forms? Thanks.

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.