473,594 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shared Method Problem With "Global" Storage

I have this nasty problem with Shared methods and what I think of as "global
storage" - i.e. storage declared outside of any subroutines or functions.
In the simple example below this "global" storage is ButtonHasBeenCl icked.
In this simple example code in Form1 calls a routine in Module1 which then
calls code back in Form1 (subroutine WhatEver). WhatEver needs to access
ButtonHasBeenCl icked but the reference to ButtonHasBeenCl icked results in
the error reflected in the comment. I don't see any ambiguity in what I am
trying to do. I suspect there is some syntatic solution but I have been
unable to find it.

Thanks much for whatever solution and/or understanding you can provide.

Bob

Public Class Form1
Inherits System.Windows. Forms.Form

Dim ButtonHasBeenCl icked As Boolean

#Region " Windows Form Designer generated code "
#End Region

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
ButtonHasBeenCl icked = True
End Sub

Public Shared Sub WhatEver()

If ButtonHasBeenCl icked Then ' Cannot refer to an instance member
of a class from within a shared method or shared member initializer without
an explicit instance of the class.

'do one thing
Else 'do something else
End If

End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
CalculateSometh ing()

If ButtonHasBeenCl icked Then
'do something here; no problem referencing ButtonHasBeenCl icked
here
End If
End Sub

End Class

Module Module1
Public Sub CalculateSometh ing()
Form1.WhatEver( )
End Sub
End Module
Oct 19 '07 #1
11 3148
"eBob.com" <eB******@total lybogus.comschr ieb
I have this nasty problem with Shared methods and what I think of as
"global storage" - i.e. storage declared outside of any subroutines
or functions.
It's called a "field".
In the simple example below this "global" storage is
ButtonHasBeenCl icked. In this simple example code in Form1 calls a
routine in Module1 which then calls code back in Form1 (subroutine
WhatEver). WhatEver needs to access ButtonHasBeenCl icked but the
reference to ButtonHasBeenCl icked results in the error reflected in
the comment. I don't see any ambiguity in what I am trying to do. I
suspect there is some syntatic solution but I have been unable to
find it.

Thanks much for whatever solution and/or understanding you can
provide.

Bob

Public Class Form1
Inherits System.Windows. Forms.Form

Dim ButtonHasBeenCl icked As Boolean

If it is not Shared, every instance of the Form has it's own value in this
field.

Public Shared Sub WhatEver()

If ButtonHasBeenCl icked Then ' Cannot refer to an instance
member of a class from within a shared method or shared member
initializer without an explicit instance of the class.

In a shared Sub, you can not access an instance field withouth having a
reference to the object. The field of which instance do you want to access?
Or maybe not even one instance has been created. Therefore this fails. Don't
declare the Sub as Shared.

'do one thing
Else 'do something else
End If

End Sub
Module Module1
Public Sub CalculateSometh ing()
Form1.WhatEver( )
End Sub
End Module
If you wanted to access a Form in a Module, you would have to pass the Form
to the procedure. It is better not to access the Form in a Module. Why don't
you put the code into the Form? If the code in the Module is to be reused,
make an abstract definition of the procedure's purpose, pass in and out the
data needed, and call it from the Form.
Armin

Oct 19 '07 #2
On Oct 19, 11:01 am, "eBob.com" <eBob....@total lybogus.comwrot e:
I have this nasty problem with Shared methods and what I think of as "global
storage" - i.e. storage declared outside of any subroutines or functions.
In the simple example below this "global" storage is ButtonHasBeenCl icked.
In this simple example code in Form1 calls a routine in Module1 which then
calls code back in Form1 (subroutine WhatEver). WhatEver needs to access
ButtonHasBeenCl icked but the reference to ButtonHasBeenCl icked results in
the error reflected in the comment. I don't see any ambiguity in what I am
trying to do. I suspect there is some syntatic solution but I have been
unable to find it.

Thanks much for whatever solution and/or understanding you can provide.

Bob

Public Class Form1
Inherits System.Windows. Forms.Form

Dim ButtonHasBeenCl icked As Boolean

#Region " Windows Form Designer generated code "
#End Region

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
ButtonHasBeenCl icked = True
End Sub

Public Shared Sub WhatEver()

If ButtonHasBeenCl icked Then ' Cannot refer to an instance member
of a class from within a shared method or shared member initializer without
an explicit instance of the class.
The error message means EXACTLY what it says. You are trying to refer
to an instance variable - a variable that is associated with a
specific instance of a class, in a shared method. A shared method is
NOT associated with any particular instance of a class. It is
associated with the class itself. VB sort of hides this distinction
with it's dubious feature of allowing you to call shared methods via
instance variables (an honor that C# will share as of version 3.0).

Anyway, what all of the above means is that you can not access
ButtonHasBeenCl icked in the manner you are attempting, since a shared
method has NO knowledge of which version of ButtonHasBeenCl icked to
reference...

What this means is that you need to:

1) declare ButtonHasBeenCl icked as shared, which means if you have
multiple instances of your form - all of them will share the same
ButtonHasBeenCl icked, which is probably not what you want.

2) Remove the shared modifier from the sub, so that it is a member
method (this means that there is an implicit Me reference passed to
the sub/function - which means you can then refer to the
ButtonHasBeenCl icked variable as your doing now.

3) Keep your sub/function shared, but make it take a parameter that
specifies the instance you are interested in: sub somesub (byval
theForm as myform). Then you can use that instance variable to get a
hold of ButtonHasBeenCl icked.

Personally, I would probably use #2 if this sub/function has no
utility beyond your specific form. And don't think that this will
cause multiple versions of the funciton/sub to be in memory at once
(I've seen people concerned by this before) - because it won't. All
instances of the class still call the same code, but the compiler adds
a additional parameter to the funciton sub, that takes the
instance....

Anyway, HTH

--
Tom Shelton

Oct 19 '07 #3
Hi Armin, Thanks for your response. Please see my further question below
interspersed with the code and your comments ...

----- Original Message -----
From: "Armin Zingler" <az*******@free net.de>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
Sent: Friday, October 19, 2007 1:19 PM
Subject: Re: Shared Method Problem With "Global" Storage

"eBob.com" <eB******@total lybogus.comschr ieb
>I have this nasty problem with Shared methods and what I think of as
"global storage" - i.e. storage declared outside of any subroutines
or functions.

It's called a "field".
>In the simple example below this "global" storage is
ButtonHasBeenC licked. In this simple example code in Form1 calls a
routine in Module1 which then calls code back in Form1 (subroutine
WhatEver). WhatEver needs to access ButtonHasBeenCl icked but the
reference to ButtonHasBeenCl icked results in the error reflected in
the comment. I don't see any ambiguity in what I am trying to do. I
suspect there is some syntatic solution but I have been unable to
find it.

Thanks much for whatever solution and/or understanding you can
provide.

Bob

Public Class Form1
Inherits System.Windows. Forms.Form

Dim ButtonHasBeenCl icked As Boolean


If it is not Shared, every instance of the Form has it's own value in this
field.

> Public Shared Sub WhatEver()

If ButtonHasBeenCl icked Then ' Cannot refer to an instance
member of a class from within a shared method or shared member
initializer without an explicit instance of the class.


In a shared Sub, you can not access an instance field withouth having a
reference to the object. The field of which instance do you want to
access?
Or maybe not even one instance has been created. Therefore this fails.
Don't
declare the Sub as Shared.
But if I don't make WhatEver Shared then I can't call it from the Module1
code.

Two things probably contribute to my confusion in this area. 1) In the real
project I am working on
I am using Modules simply to keep the code more manageable. The application
is mining some web sites
and I use a different Module for each site. Code which is common to all
sites is in the Form1.vb code.
And 2) apparently there can be more than one Form1, but I see Form1 as being
associated with my running
application. It's the "topmost thing". It wouldn't make any sense, for the
(admitedly simple) applications I've written, to have
more than one.

What I don't get is that if I refer to ButtonHasBeenCl icked in a subroutine
in the Form1.vb
code there is no question about which instance is being referenced. But
when I call (from the Form1.vb code) a subroutine
in a Module, .Net suddenly has no knowledge of what instance the code is
working on. I can
solve this problem by simply cutting and pasting the subroutine in the
Module to the Form1.vb code,
right? (But then my Form1.vb code would get unmanageably large.)

Part of my problem, I see now, is that I have misunderstood and am misusing
the Module concept. Right? But what do you do to
keep the size and organization of code files more manageable? I need some
way to segregate the code which is unique to mining web site A from the
code which is unique to mining web site B.

Sorry to be crying on your shoulder. What I know about VB.Net is
self-taught and there are major holes in my understanding.

Thanks, Bob
>
> 'do one thing
Else 'do something else
End If

End Sub

>Module Module1
Public Sub CalculateSometh ing()
Form1.WhatEver( )
End Sub
End Module

If you wanted to access a Form in a Module, you would have to pass the
Form
to the procedure. It is better not to access the Form in a Module. Why
don't
you put the code into the Form? If the code in the Module is to be reused,
make an abstract definition of the procedure's purpose, pass in and out
the
data needed, and call it from the Form.
Armin

Oct 19 '07 #4
Hi Tom, Thanks very much for your response. Please see my further
questions below interspersed with your reply. Also, I hope you will look at
my
reply to Armin's response.

"Tom Shelton" <to*********@co mcast.netwrote in message
news:11******** **************@ k35g2000prh.goo glegroups.com.. .
On Oct 19, 11:01 am, "eBob.com" <eBob....@total lybogus.comwrot e:
>I have this nasty problem with Shared methods and what I think of as
"global
storage" - i.e. storage declared outside of any subroutines or functions.
In the simple example below this "global" storage is
ButtonHasBeenC licked.
In this simple example code in Form1 calls a routine in Module1 which
then
calls code back in Form1 (subroutine WhatEver). WhatEver needs to access
ButtonHasBeenC licked but the reference to ButtonHasBeenCl icked results in
the error reflected in the comment. I don't see any ambiguity in what I
am
trying to do. I suspect there is some syntatic solution but I have been
unable to find it.

Thanks much for whatever solution and/or understanding you can provide.

Bob

Public Class Form1
Inherits System.Windows. Forms.Form

Dim ButtonHasBeenCl icked As Boolean

#Region " Windows Form Designer generated code "
#End Region

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button1.Click
ButtonHasBeenCl icked = True
End Sub

Public Shared Sub WhatEver()

If ButtonHasBeenCl icked Then ' Cannot refer to an instance
member
of a class from within a shared method or shared member initializer
without
an explicit instance of the class.

The error message means EXACTLY what it says. You are trying to refer
to an instance variable - a variable that is associated with a
specific instance of a class, in a shared method. A shared method is
NOT associated with any particular instance of a class. It is
associated with the class itself. VB sort of hides this distinction
with it's dubious feature of allowing you to call shared methods via
instance variables (an honor that C# will share as of version 3.0).

Anyway, what all of the above means is that you can not access
ButtonHasBeenCl icked in the manner you are attempting, since a shared
method has NO knowledge of which version of ButtonHasBeenCl icked to
reference...

What this means is that you need to:

1) declare ButtonHasBeenCl icked as shared, which means if you have
multiple instances of your form - all of them will share the same
ButtonHasBeenCl icked, which is probably not what you want.
In my heart of hearts I KNOW that there will only be one instance of the
Form1 class.
So actually his solution works. But I don't like the estethics of it. It
seems to be a serious
misuse of the intended use of Shared.
2) Remove the shared modifier from the sub, so that it is a member
method (this means that there is an implicit Me reference passed to
the sub/function - which means you can then refer to the
ButtonHasBeenCl icked variable as your doing now.
But if I remove Shared from the subroutine then I can't call it from the
Module1 code.
>
3) Keep your sub/function shared, but make it take a parameter that
specifies the instance you are interested in: sub somesub (byval
theForm as myform). Then you can use that instance variable to get a
hold of ButtonHasBeenCl icked.
I think that I will probably go this way. This problem will come up again
when I implement
my one and only message logger for my one and only Form1 application, so I
might as well
get used to it. Thanks again for your response. Bob

Personally, I would probably use #2 if this sub/function has no
utility beyond your specific form. And don't think that this will
cause multiple versions of the funciton/sub to be in memory at once
(I've seen people concerned by this before) - because it won't. All
instances of the class still call the same code, but the compiler adds
a additional parameter to the funciton sub, that takes the
instance....

Anyway, HTH

--
Tom Shelton

Oct 19 '07 #5
On Oct 19, 3:07 pm, "eBob.com" <eBob....@total lybogus.comwrot e:
Hi Tom, Thanks very much for your response. Please see my further
questions below interspersed with your reply. Also, I hope you will look at
my
reply to Armin's response.

"Tom Shelton" <tom_shel...@co mcast.netwrote in message

news:11******** **************@ k35g2000prh.goo glegroups.com.. .
On Oct 19, 11:01 am, "eBob.com" <eBob....@total lybogus.comwrot e:
I have this nasty problem with Shared methods and what I think of as
"global
storage" - i.e. storage declared outside of any subroutines or functions.
In the simple example below this "global" storage is
ButtonHasBeenCl icked.
In this simple example code in Form1 calls a routine in Module1 which
then
calls code back in Form1 (subroutine WhatEver). WhatEver needs to access
ButtonHasBeenCl icked but the reference to ButtonHasBeenCl icked results in
the error reflected in the comment. I don't see any ambiguity in what I
am
trying to do. I suspect there is some syntatic solution but I have been
unable to find it.
Thanks much for whatever solution and/or understanding you can provide.
Bob
Public Class Form1
Inherits System.Windows. Forms.Form
Dim ButtonHasBeenCl icked As Boolean
#Region " Windows Form Designer generated code "
#End Region
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
ButtonHasBeenCl icked = True
End Sub
Public Shared Sub WhatEver()
If ButtonHasBeenCl icked Then ' Cannot refer to an instance
member
of a class from within a shared method or shared member initializer
without
an explicit instance of the class.
The error message means EXACTLY what it says. You are trying to refer
to an instance variable - a variable that is associated with a
specific instance of a class, in a shared method. A shared method is
NOT associated with any particular instance of a class. It is
associated with the class itself. VB sort of hides this distinction
with it's dubious feature of allowing you to call shared methods via
instance variables (an honor that C# will share as of version 3.0).
Anyway, what all of the above means is that you can not access
ButtonHasBeenCl icked in the manner you are attempting, since a shared
method has NO knowledge of which version of ButtonHasBeenCl icked to
reference...
What this means is that you need to:
1) declare ButtonHasBeenCl icked as shared, which means if you have
multiple instances of your form - all of them will share the same
ButtonHasBeenCl icked, which is probably not what you want.

In my heart of hearts I KNOW that there will only be one instance of the
Form1 class.
So actually his solution works. But I don't like the estethics of it. It
seems to be a serious
misuse of the intended use of Shared.
2) Remove the shared modifier from the sub, so that it is a member
method (this means that there is an implicit Me reference passed to
the sub/function - which means you can then refer to the
ButtonHasBeenCl icked variable as your doing now.

But if I remove Shared from the subroutine then I can't call it from the
Module1 code.
3) Keep your sub/function shared, but make it take a parameter that
specifies the instance you are interested in: sub somesub (byval
theForm as myform). Then you can use that instance variable to get a
hold of ButtonHasBeenCl icked.

I think that I will probably go this way. This problem will come up again
when I implement
my one and only message logger for my one and only Form1 application, so I
might as well
get used to it. Thanks again for your response. Bob
Personally, I would probably use #2 if this sub/function has no
utility beyond your specific form. And don't think that this will
cause multiple versions of the funciton/sub to be in memory at once
(I've seen people concerned by this before) - because it won't. All
instances of the class still call the same code, but the compiler adds
a additional parameter to the funciton sub, that takes the
instance....
Anyway, HTH
--
Tom Shelton- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Bob, reading both replys I'm begining to get a better understanding of
what your trying to accomplish, and let me say your desire to separate
common code, from implementation specific code is the correct one.
But, with all due respect, you're approching it the wrong way....

First, I would separate ALL logic involved in mining the websites from
the UI. That logic is more appropriately placed in a Class. In fact,
I would most likely move it to it's own class library, so that the
logic is able to be used from multiple different applications/
interfaces.

Second, as for separating out the logic... There are several ways to
approach this, but I think the simplest at this point would to be
through inheritance. In that case, I would probably create somthing
looked like (air code follows!):

public mustinherit class WebMinerBase

public overridable sub
DoCoolStuffButA llowSubClassesT oAlterBehavior( )
' common code
end sub

public mustoveride sub
DoCoolStuffAndI nsistSubClasses ProvideAnImplem entation()

' factory method to create subclass to handle the address
public shared function CreateWebMiner (byval address as string) as
WebMinerBase
if address = google then
retrun new GoogleMiner()
else if address = ebay then
return new EbayMiner()
endif
end function
end class

public class GoogleMiner
inherits WebMinerBase

public override sub
DoCoolStuffAndI nsistSubClasses ProvideAnImplem entation()
' google specific implementation
end sub
end class

public class EbayMiner
inherits WebMinerBase

public override sub
DoCoolStuffAndI nsistSubClasses ProvideAnImplem entation()
' Ebay specific implementation
end sub
end class

' client code in form

private sub button_click (byval sender as object, byval e as
eventargs) handles button.click
dim webminer as WebMinerBase = WebMinerBase.Cr eateWebMiner(ad dres)
webminer.DoCool StuffButAllowSu bClassesToAlter Behavior()
webminer.DoCool StuffAndInsistS ubClassesProvid eAnImplementati on()
end sub

Anyway, the point is to abstract common logic into tthe base class,
and the implementation specific into subclasses. Then you can use a
generic interface, and through polymorphism get specific behavior...

Anyway, just a thought.

--
Tom Shelton

Oct 19 '07 #6
Tom, Thanks very much for sharing your knowledge and taking the time to do
so. I reallly! like your solution/approach. It would never have occurred
to me as I have done very little OO programming. I have written only a few
very simple classes and have never written a class which is then inherited.
But I understand the concepts of your approach. I don't know if I can
justify restructuring my current project. New function always seems to
trump improving the structure. Thanks again for all of your help. Bob

"Tom Shelton" <to*********@co mcast.netwrote in message
news:11******** **************@ e34g2000pro.goo glegroups.com.. .
On Oct 19, 3:07 pm, "eBob.com" <eBob....@total lybogus.comwrot e:
>Hi Tom, Thanks very much for your response. Please see my further
questions below interspersed with your reply. Also, I hope you will look
at
my
reply to Armin's response.

"Tom Shelton" <tom_shel...@co mcast.netwrote in message

news:11******* *************** @k35g2000prh.go oglegroups.com. ..
On Oct 19, 11:01 am, "eBob.com" <eBob....@total lybogus.comwrot e:
I have this nasty problem with Shared methods and what I think of as
"global
storage" - i.e. storage declared outside of any subroutines or
functions.
In the simple example below this "global" storage is
ButtonHasBeenC licked.
In this simple example code in Form1 calls a routine in Module1 which
then
calls code back in Form1 (subroutine WhatEver). WhatEver needs to
access
ButtonHasBeenC licked but the reference to ButtonHasBeenCl icked results
in
the error reflected in the comment. I don't see any ambiguity in what
I
am
trying to do. I suspect there is some syntatic solution but I have
been
unable to find it.
>Thanks much for whatever solution and/or understanding you can
provide.
>Bob
>Public Class Form1
Inherits System.Windows. Forms.Form
> Dim ButtonHasBeenCl icked As Boolean
>#Region " Windows Form Designer generated code "
#End Region
> Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As
System.EventAr gs) Handles Button1.Click
ButtonHasBeenCl icked = True
End Sub
> Public Shared Sub WhatEver()
> If ButtonHasBeenCl icked Then ' Cannot refer to an instance
member
of a class from within a shared method or shared member initializer
without
an explicit instance of the class.
The error message means EXACTLY what it says. You are trying to refer
to an instance variable - a variable that is associated with a
specific instance of a class, in a shared method. A shared method is
NOT associated with any particular instance of a class. It is
associated with the class itself. VB sort of hides this distinction
with it's dubious feature of allowing you to call shared methods via
instance variables (an honor that C# will share as of version 3.0).
Anyway, what all of the above means is that you can not access
ButtonHasBeenCl icked in the manner you are attempting, since a shared
method has NO knowledge of which version of ButtonHasBeenCl icked to
reference...
What this means is that you need to:
1) declare ButtonHasBeenCl icked as shared, which means if you have
multiple instances of your form - all of them will share the same
ButtonHasBeenCl icked, which is probably not what you want.

In my heart of hearts I KNOW that there will only be one instance of the
Form1 class.
So actually his solution works. But I don't like the estethics of it.
It
seems to be a serious
misuse of the intended use of Shared.
2) Remove the shared modifier from the sub, so that it is a member
method (this means that there is an implicit Me reference passed to
the sub/function - which means you can then refer to the
ButtonHasBeenCl icked variable as your doing now.

But if I remove Shared from the subroutine then I can't call it from the
Module1 code.
3) Keep your sub/function shared, but make it take a parameter that
specifies the instance you are interested in: sub somesub (byval
theForm as myform). Then you can use that instance variable to get a
hold of ButtonHasBeenCl icked.

I think that I will probably go this way. This problem will come up
again
when I implement
my one and only message logger for my one and only Form1 application, so
I
might as well
get used to it. Thanks again for your response. Bob
Personally, I would probably use #2 if this sub/function has no
utility beyond your specific form. And don't think that this will
cause multiple versions of the funciton/sub to be in memory at once
(I've seen people concerned by this before) - because it won't. All
instances of the class still call the same code, but the compiler adds
a additional parameter to the funciton sub, that takes the
instance....
Anyway, HTH
--
Tom Shelton- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Bob, reading both replys I'm begining to get a better understanding of
what your trying to accomplish, and let me say your desire to separate
common code, from implementation specific code is the correct one.
But, with all due respect, you're approching it the wrong way....

First, I would separate ALL logic involved in mining the websites from
the UI. That logic is more appropriately placed in a Class. In fact,
I would most likely move it to it's own class library, so that the
logic is able to be used from multiple different applications/
interfaces.

Second, as for separating out the logic... There are several ways to
approach this, but I think the simplest at this point would to be
through inheritance. In that case, I would probably create somthing
looked like (air code follows!):

public mustinherit class WebMinerBase

public overridable sub
DoCoolStuffButA llowSubClassesT oAlterBehavior( )
' common code
end sub

public mustoveride sub
DoCoolStuffAndI nsistSubClasses ProvideAnImplem entation()

' factory method to create subclass to handle the address
public shared function CreateWebMiner (byval address as string) as
WebMinerBase
if address = google then
retrun new GoogleMiner()
else if address = ebay then
return new EbayMiner()
endif
end function
end class

public class GoogleMiner
inherits WebMinerBase

public override sub
DoCoolStuffAndI nsistSubClasses ProvideAnImplem entation()
' google specific implementation
end sub
end class

public class EbayMiner
inherits WebMinerBase

public override sub
DoCoolStuffAndI nsistSubClasses ProvideAnImplem entation()
' Ebay specific implementation
end sub
end class

' client code in form

private sub button_click (byval sender as object, byval e as
eventargs) handles button.click
dim webminer as WebMinerBase = WebMinerBase.Cr eateWebMiner(ad dres)
webminer.DoCool StuffButAllowSu bClassesToAlter Behavior()
webminer.DoCool StuffAndInsistS ubClassesProvid eAnImplementati on()
end sub

Anyway, the point is to abstract common logic into tthe base class,
and the implementation specific into subclasses. Then you can use a
generic interface, and through polymorphism get specific behavior...

Anyway, just a thought.

--
Tom Shelton

Oct 20 '07 #7

"eBob.com" <fa******@total lybogus.comwrot e in message
news:%2******** *******@TK2MSFT NGP03.phx.gbl.. .
Tom, Thanks very much for sharing your knowledge and taking the time to
do so. I reallly! like your solution/approach. It would never have
occurred to me as I have done very little OO programming.
That's cool. I'm happy to share.
I have written only a few very simple classes and have never written a
class which is then inherited.
OOP done right, is a really good way to approach the building of software -
it is well worth studying/practicing. But, it's not always the right way
either - and it can be overdone.
But I understand the concepts of your approach. I don't know if I can
justify restructuring my current project. New function always seems to
trump improving the structure.
This I have to disagree with you. I think refactoring structure, can
actually lead to longer term benifits in maintainablity and extensability.
If I might, I'd suggest you take a look at Martin Fowler's "Refactorin g:
Improving the Design of Existing Code". It's actually a pretty light read,
it's only like the first 4 or 5 chapters that explain the concept - the main
bulk of the book is really just a bunch of suggested refactorings. Those
chapters are at least worth of a skim, to see the descriptions, so that you
can recognize them in your code - but each chapter can be read in detail as
you encounter that particluar "code smell" :)
Thanks again for all of your help. Bob
No problem. Happy to help.

--
Tom Shelton

Oct 20 '07 #8
Hi Armin,

I can see that you have now 2MB connection. Creating long messages with a
lot of non necessary stuff in it.

(Just a reminder to your own correct messages in past)

This is of course not only meant for Armin

:-)

Cor

Oct 20 '07 #9
"Cor Ligthert[MVP]" <no************ @planet.nlschri eb
Hi Armin,

I can see that you have now 2MB connection. Creating long messages
with a lot of non necessary stuff in it.
???

Not necessary stuff? I would say it's exactly the information he was
missing. Look at his post: There was a lack of understanding of shared and
instance members and what modules are. That's what I explained. Giving
detailled information about the internals can sometimes also be enlighting,
better than not knowing what's going on in the background forever.

As his answer shows it was not so bad.
(Just a reminder to your own correct messages in past)

This is of course not only meant for Armin

:-)
:-(
Armin

Oct 20 '07 #10

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

Similar topics

11
2692
by: mrbog | last post by:
I have an array/hash that stores path information for my app. As in, what directory this is in, what directory that's in, what the name of the site is, what the products are called, etc. It's called $glb. So, every function so far looks like this: function something() { global $glb; }
7
2680
by: Lyn | last post by:
Hi and Season's Greetings to all. I have a question regarding the use of a qualifier word "Global". I cannot find any reference to this in Access help, nor in books or on the Internet. "Global" seems to be recognised by Access in at least three cases:- 1) "Global Const". Recently someone in this group helped me resolve a problem, and it involved the use of a Global Const. By Googling "Global Const", I got plenty of hits -- but they...
5
3484
by: j | last post by:
Anyone here feel that "global variables" is misleading for variables whose scope is file scope? "global" seems to imply global visibility, while this isn't true for variables whose scope is file scope. If you have a variable whose scope is file scope in another translation unit, you have to provide a local declaration to access that variable from the other translation unit. Also, I don't see "global variable" used once in the standard....
4
3528
by: BB | last post by:
Hello all, I might be missing something here, but am trying to understand the difference between using application-level variables--i.e. Application("MyVar")--and global variables--i.e. public myVar as string, etc. It seems to me that the scope and duration are the same, as they both are there while the application is running, and both go away when it quits. I presume that one difference is that the application state can be "flushed," such...
5
2401
by: Graham Charles | last post by:
I've got several generic "library" routines that are used by many of my controls & applications (things like string manipulation, generic error handling, an "about" box generator, etc.). As I transition my apps from VB6 to VB.NET, I'm curious about the best, most efficient way to include those in my application. Here's what I'm considering: 1. My gut reaction is to compile these routines into separate class libraries...
4
1265
by: BobRoyAce | last post by:
I posted the post below in another newsgroup and it has been suggested that this may be a better place to post it. See below: ---ORIGINAL POST BEGINS--- I have an application which is comprised of, among many other things, a Main form which shows various user controls depending on which NavBar link they click on. In addition, there are many Entity classes that I created to support the application, one of which happens to be called User....
5
4930
by: dave | last post by:
If I have a class that hold, for instance, user settings that should be accessible to the entire program logic, what is a good paradigm to use? In C++, I would have made it a global object, protected if necessary for thread safety. In C#, of course, there are no global objects. The Program object is static, so cannot contain object instances. While I could store it in my main form pass it around, that seems cumbersome. I could do a...
7
1823
by: twang090 | last post by:
I find in other team member's project, they are referencing a type in following format " public static global::ErrorReport.Description Description = new global::ErrorReport.Description(); " I do not understand the usage of "global" here, could anyone please clarify its usage and what benift of using that. Thanks in advance.
1
3677
by: sap0321 | last post by:
This should be kindergarten stuff but for some reason I am having trouble with it. I do 99.9% web programming and this is the first windows app i've done in years - probably the first ever in C# ... anyway ... Here is what I am trying to do .... Windows app - with a main "navigation" form with 4 linkbuttons on it - each of them open a child form with a task to perform ... on the main form, there is a Label control for the "Active...
0
7954
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8260
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6671
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5837
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5416
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3908
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2391
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1222
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.