Re: Public Variables
- From: <joisey@xxxxxxxxxxxxxx>
- Date: Mon, 5 Sep 2005 00:47:32 -0400
Scott:
Are you saying that there is no circumstance in which a person should ever
declare a variable as public?
Are you stating that I should ALWAYS declare ALL variables as private?
>>> Variables should always be private and accessed through correctly
>>> structured get/set accessor properties.
That seems like a lot of work for 20 variables in a one module program of
only 1500 lines.
My object is not to learn programming style as I only wrote this one program
because no comercial programs
existed that performed this task. My only interest is to get code that
works.
I come to this news group because when I have had questions on how to solve
specific problems, many people
have come to my assistance.
(The little utility I wrote has been purchased by over 600 people and used
for almost a year and with no complaints.)
I would still like to know:
Since almost every procedure in my program contains the line If
FileExists="True" then......etc etc etc,
why I should not declare 'FileExists' as a public string at the top of the
Main module?
If one of the proceedures changes the value to "false", why would I make
this private to that proceedure,
when every other proceedure needs to know the new value.
thanx......
......joisey
"Scott M." <s-mar@xxxxxxxxxxxxx> wrote in message
news:uJwa0TcsFHA.3604@xxxxxxxxxxxxxxxxxxxxxxx
> The answer to your question is "go learn what OOP programming is and you
> will understand" because there is way to much to explain at the level you
> seem to be at.
>
>
> <joisey@xxxxxxxxxxxxxx> wrote in message
> news:%230HZcMbsFHA.1960@xxxxxxxxxxxxxxxxxxxxxxx
>> >
>>> Variables should always be private and accessed through correctly
>>> structured get/set accessor properties.
>>>
>>> In certain, very limited cases, you can use the shared keyword to
>>> provide methods and properties that are globally available. These should
>>> however be completely self-contained and not rely on any stored data
>>> such as a static method referring to a static property and other such
>>> bad habits. The Math class is the perfect example of where the Shared
>>> keyword is properly used.
>>>
>>> If you want to develop good OOP techniques throw out just about
>>> everything you learned from VB6.
>>> Bob Powell [MVP]
>>> Visual C#, System.Drawing
>>
>> I have never used VB6. I purchased VB.Net for the purpose of writing a
>> game management program.
>>
>> The first thing the progam does is read-in and store about 20 pieces of
>> information
>> about the game configuration files.
>> These are storred in variables, mostly as true/false but some as
>> integers.
>>
>> The program consists of 2 forms, and about 12 routines I wrote.
>> Almost all of these routines need to be able to check the state of any or
>> all of these
>> variables. If a routine changes a variable, The next routine called MUST
>> know the
>> current state of any or all of the variables.
>>
>> While writing the program I got sick and tired of constantly being warned
>> that these
>> variable had not been declared. I was repeatedly told to add dim
>> statements.
>>
>> I finally moved ALL of these variables to the "Main" module as PUBLIC!!!
>>
>> If the ONLY PURPOSE of the program is to ascertain if 20 conditions are
>> true or false,
>> and if EVERY (repeat EVERY) subroutine needs access to this information,
>> are you
>> asking me pass all 20 back and forth for every single subroutine????
>>
>> If my progam discovers that a certain configuration file "exists" and I
>> set the flag
>> "FileExists=true" why the hell should I declare this variable private so
>> that not even one
>> of the routines I write can check this?
>>
>> How much routine should be written to protect the access to a variable in
>> a 2 form
>> program that is only 4 pages long?
>>
>> ....joisey
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
.
- Follow-Ups:
- Re: Public Variables
- From: Scott M.
- Re: Public Variables
- References:
- Public Variables
- From: thomasp
- Re: Public Variables
- From: Bob Powell [MVP]
- Re: Public Variables
- From: joisey
- Re: Public Variables
- From: Scott M.
- Public Variables
- Prev by Date: Re: Me vs. MyClass
- Next by Date: Adding to the Explorer right-click menu
- Previous by thread: Re: Public Variables
- Next by thread: Re: Public Variables
- Index(es):
Relevant Pages
|