473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Question about OOP and Class Member in VB.net

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.
--
TC
Jul 21 '05 #1
4 1326
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.


"Terrance" <Te******@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
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.
--
TC

Jul 21 '05 #2
Thanks JohnFol. I'll give that a shot.

"JohnFol" wrote:
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.


"Terrance" <Te******@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...
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.
--
TC


Jul 21 '05 #3
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.EnableVisualStyle s()
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...
"Terrance" wrote:
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.
--
TC

Jul 21 '05 #4
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.

"Terrance" <Te******@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
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.EnableVisualStyle s()
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...
"Terrance" wrote:
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.
--
TC

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Casper Bang | last post by:
My question is fundamental I beleive but it has been teasing me for a while: I have two classes in my app. The first class is instantiated as a member of my second class. Within this first class,...
8
by: Gert Van den Eynde | last post by:
Hi all, I have a question on interface design: I have a set of objects that are interlinked in the real world: object of class A needs for example for the operator() an object of class B. On...
7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
4
by: Vagmi Mudumbai | last post by:
Hi, I am working on CodeDOM to generate a more usable class to serialize and deserialize WXS files. I have hit the wall at a pretty early stage. :-( I am attempting to change the member public...
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
1
by: Tony Johansson | last post by:
Hello! This is a question about Reflection. I have a small program below where the class are called Mymemberinfo. This class Mymemberinfo is used in GetMembers to get all the member for this...
5
by: Ben | last post by:
Hi, i defined a function in the base class 'ford' and the same function (with different output) in subclass "peugeot". I first put 'Overridable function' in the base class and 'Overrides...
14
by: Alexander Dong Back Kim | last post by:
Dear all, I used to use C++ programming language at all time but moved to C# and Java. Few days ago, I restarted studying about C++ with a very beginner's mind. I wrote a simple class and gcc...
7
by: WaterWalk | last post by:
Hello. I thought I understood member function pointers, but in fact I don't. Consider the following example: class Base { public: virtual ~Base() {} }; class Derived : public Base {
2
by: nicholas08 | last post by:
I am new to programming and trying to work on a simple console app. I am making a simple Library Management system where the user/admin can manage members and item. Attaching the menu so it's clear...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.