Re: Public Variables

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>


.



Relevant Pages

  • Re: Alberts MultiSelect Form Question #1
    ... This whole issue centers around what we call scope. ... are private to that ONE MODULE). ... functions and routines within that module (they default to private, ... to be used outside of that module, then I must declare them as public. ...
    (microsoft.public.access.formscoding)
  • Re: Public Variables
    ... The program consists of 2 forms, and about 12 routines I wrote. ... and if EVERY (repeat EVERY) subroutine needs access to this information, ... "FileExists=true" why the hell should I declare this variable private so ...
    (microsoft.public.dotnet.languages.vb)
  • Re: newbie- Variables in DLL
    ... > all routines called by that routine, ... > private or local variables. ... >> Another person told me to declare ALL variables as PRIVATE ... >> PRIVATE lnTotal, lnSales, lnAmount ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Trigger CAPS LOCK ON When Wk Bk is Opened?
    ... Private Type OSVERSIONINFO ... Private Declare Function GetVersionEx Lib "kernel32" _ ... Public Sub CapsOn() ... Dim ScrollLockState As Boolean ...
    (microsoft.public.excel.programming)
  • Re: cant use udt in a class?
    ... Private Sub Command1_Click ... Another quirk is that you can declare Properties in a .BAS module, ... So you could actually expose functions from modules and hide the ... This would be essential when you went to exposing these modules in libraries ...
    (microsoft.public.vb.general.discussion)