473,404 Members | 2,137 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,404 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 1330
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.