Variables that I would like to make available to all forms and modules in my
program, where should I declare them? At the momment I just created a
module and have them all declared public there. What is the normal way to
do this?
Thanks,
Thomas
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05
27 2717
> 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=tru e" 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
I actually prefer to start with a form myself as well. My point was that
*if* you are going to use a Standard Module, then that will become the start
up object by default, so in that case making it be set as the start up
object makes sense.
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:OR******** ******@TK2MSFTN GP09.phx.gbl... Scott,
You are correct that the standard Module need not be set as the Startup Object in the project. I still recommend that it be set that way, as it is more self-documenting in terms of programmatic flow.
I prefer a MainForm as start object, because that is in my opinion the most self-documenting in terms of program flow, especially because most documentation is based on that.
However I respect your opinion in this of course, just showing that in fact it is a matter of preference.
Cor
> isn`t the purpose of OOP to reduce the cognitive load on the programming team and not to make code more efficient ?
No, not really. OOP is meant to make code more hierarchical and reusable.
In may cases, OOP means adding more code layers and structure, which can
actually reduce efficiency, but create more robust code and so that is a
worthwhile trade off.
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.
<jo****@mindspr ing.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. 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=tru e" 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
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="Tru e" 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-***@nospam.nosp am> wrote in message
news:uJ******** ******@tk2msftn gp13.phx.gbl... 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. <jo****@mindspr ing.com> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. > 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=tru e" 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
Joisey,
See responses inline:
<jo****@mindspr ing.com> wrote in message
news:Om******** ******@TK2MSFTN GP09.phx.gbl... Scott: Are you saying that there is no circumstance in which a person should ever declare a variable as public?
If you wanted to really follow the OOP paradigm, then probably not. The
whole premis of OOP is that each object be a "black box" of code and that
only code IN the black box can see the rest of the code IN the black box.
If the black box wanted to expose certain functions or data, the box should
have Public methods and Properties.
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.
Again, yes! You could make a class that exposes the 20 data fields as
Public properties. 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.
Ok fine. But, you asked your question in a forum full of people that do
care about programming style.
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.
If you are saying that you come here to get answers that don't include good
OOP style and concepts (and that you have gotten just that in the past), I
would simply say you should then start your posts off with "I'm not
interested in OOP programming style - I just need a way to [fill in question
here] that will work."
(The little utility I wrote has been purchased by over 600 people and used for almost a year and with no complaints.)
Great. But, why would a user complain about something that they will never
be able to see directly?
I never complained about my old 25" color television, but when I got a 42"
plasma, I realized that my other TV sucked by comparison.
Also, what will you do when you decide to release a new version of your
program and you'll want to add more features (which almost always happens)?
As your program grows, it will undoubtably become more complex. Building
something "properly" in the beginning makes it easier to add on to later.
I would still like to know: Since almost every procedure in my program contains the line If FileExists="Tru e" 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.
Again, if we are keeping this conversation to best OOP practices, you would
want to create a class with a Shared property that exposes your "FileExists "
Boolean data. If we are not, then what you've done "works" just fine. thanx...... .....joisey
"Scott M." <s-***@nospam.nosp am> wrote in message news:uJ******** ******@tk2msftn gp13.phx.gbl... 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.
<jo****@mindspr ing.com> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. > 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=tru e" 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
Scot: wrote: >>
Also, what will you do when you decide to release a new version of your
program and you'll want to add more features (which almost always happens)?
As your program grows, it will undoubtedly become more complex. Building
something "properly" in the beginning makes it easier to add on to later.>>
Scot, I am beginning to see you are correct!
They say "well begun is half done", and I am already looking at a new
more complex revision.
I never used VB6.
I came directly to VB.net with only the definition of a project and 6 weeks
to
complete it, while still holding down my day-job. (The programmer I planned
to use bailed out on me) I bought VB.net and 4 books, and with the help
of this forum made the release date on time.
(I looked at books on both C and VB, and found I could relate better to VB.
I had not written any code since 1986. I wrote a lot of utilities for the
1602,
(Atari 400,800,1200) using assembly, Basic, and Action!. I have some
knowledge of FORTRAN and "Logo". You really had to plan when everything
(compiler, program, data, screen memory, stacks) had to fit into just 16K
!!!
I guess it's just hard to get "gosub.....retu rn" out of my blood! LOL.
thanx....joisey
Good luck to you but I will say that I started out with BASIC myself and it
took a few years to just get line numbers out of my head (Read & Data / List
& Run, etc.).
<jo****@mindspr ing.com> wrote in message
news:ul******** ******@TK2MSFTN GP09.phx.gbl... Scot: wrote:>>> Also, what will you do when you decide to release a new version of your program and you'll want to add more features (which almost always happens)? As your program grows, it will undoubtedly become more complex. Building something "properly" in the beginning makes it easier to add on to later.>>>
Scot, I am beginning to see you are correct! They say "well begun is half done", and I am already looking at a new more complex revision.
I never used VB6. I came directly to VB.net with only the definition of a project and 6 weeks to complete it, while still holding down my day-job. (The programmer I planned to use bailed out on me) I bought VB.net and 4 books, and with the help of this forum made the release date on time.
(I looked at books on both C and VB, and found I could relate better to VB. I had not written any code since 1986. I wrote a lot of utilities for the 1602, (Atari 400,800,1200) using assembly, Basic, and Action!. I have some knowledge of FORTRAN and "Logo". You really had to plan when everything (compiler, program, data, screen memory, stacks) had to fit into just 16K !!!
I guess it's just hard to get "gosub.....retu rn" out of my blood! LOL.
thanx....joisey This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jose Meireles |
last post by:
Hi everyone,
I'm trying to use public variables in a web form to hld specific values.
What happens is that the public variables (declared as public x as y in the
beginning of the class), doesn't seem to hold the value from function call
to function call.
Does anyone can help me abou this?
best regards
|
by: darrel |
last post by:
I'm still not quite sure how best to handle the passing of data between
controls.
This is a method I'm using at the moment:
I have an XML file that contains a variety of page-centric variables. I have
one control that loads the XML file, reads through it, and grabs the
variables it needs. It then sets these to PUBLIC variables.
Then, other usercontrols simply request that variable.
|
by: Mrs. Conni Drejer |
last post by:
Please help anyone: I have made a DLL (for DBCommunication) in which I have
defined some public static variables/fields in a public class. This because I
want these variables to be shared in all methods in the total application.
Both web- and windowsapplications and other DLL's are using this DLL. When
one of the Web-application uses the DLL, my variables are shared across
sessions, but I do not want this to happen - I want the variables to...
|
by: Webster |
last post by:
Hello,
Just wondering what's better programming style; to use public variables in a
class or to use private/protected variables and then expose them via
properties?
For example:
--------------------------------
Public Class public_person
|
by: Nick Dreyer |
last post by:
Is it possible to see public class variables of a COM addin in Excel 97 VBA?
I have successfully created the (Visual Basic 2003 .NET) COM
and referenced it in an Excel 97 VBA project. The VBA object browser sees -
and the project otherwise successfully interacts with - all the COM addin
methods and properties, but none of the public variables - target, init and
size in the code below - can be accessed. When I reference the exact same...
| |
by: Steve Mauldin |
last post by:
I have a public variable that is declared in a public module. This Variable
is stored into a Session variable and used to pass data from page to page.
I am seeing on my local development box that once the variable is created
and loaded with data and stored into the session variable that on the next
aspx page, before the first line of the page load is executed, the public
variables data persists. I have not done an assignment from the...
|
by: jopperdepopper |
last post by:
Hi,
finally giving php 5 a go, and going over the new approach to classes.
Can someone clarify the public, private and protected to me?
I quote the php manual: "The visibility of a property or method can be
defined by prefixing the declaration with the keywords: public,
protected or private. Public declared items can be accessed
everywhere."
|
by: Web Search Store |
last post by:
Hello,
I made a web page using visual studio.
I also made a public class in the app_code folder called 'allvars'
In the main web page durning the page startup, I can refer to public shared
variables by simply saying:
x=allvars.variable1
|
by: PhilippeM |
last post by:
Hi everyone!
I have defined 3 public variables:
Public OldCompany As Variant
Public OldLast As Variant
Public OldFirst As Variant
A procedure defines those variables:
OldCompany = !Company
OldLast = !
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |