|
-
Aug 26th, 2009, 09:20 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Global Variables
How do I defiine a global variable for the whole application so that it does not have to be defined in all the forms that need it.
ie data path for database.
Computerman.
It was much easier in VB6, but I am now liking Vb.Net alot more. 
-
Aug 26th, 2009, 09:24 AM
#2
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Aug 26th, 2009, 09:27 AM
#3
Re: Global Variables
Typically connection strings are stored in a config file.
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Aug 26th, 2009, 09:34 AM
#4
Re: Global Variables
 Originally Posted by computerman
How do I defiine a global variable for the whole application so that it does not have to be defined in all the forms that need it.
ie data path for database.
Computerman. 
Maybe that is just your example, but a data path for a database should only ever be defined one time. There should be a single method in your project for opening a database connection. If you have it now where everytime you need to connect to the database, you have basically a copy/paste of database connection code, then you should probably consider reworking the code a little. One small change in the database access code turns into 20 places that you need to change in code, versus just doing it in 1 spot.
-
Aug 26th, 2009, 09:46 AM
#5
Thread Starter
Hyperactive Member
Re: Global Variables
I understand what you are saying. The underlying issue that I have is that I have to open my Application System Parameters file each time I want to get a user defined variable, which could be used in various forms.
So instead of opening the file everytime I need that variable, it would be advantageous for it to be defined globally.
Using the data path for the db was not a good example.
Computerman.
It was much easier in VB6, but I am now liking Vb.Net alot more. 
-
Aug 26th, 2009, 11:26 AM
#6
Re: Global Variables
Why not just use the built in application settings feature that VB.NET supports in the project properties?
You can make custom settings in here that can be accessed globally in your code. You also get intellisense support for these settings. Using a scope of 'User' makes these settings read/write, while using a scope of 'application' will make them readonly settings.
-
Aug 28th, 2009, 08:16 AM
#7
Thread Starter
Hyperactive Member
Re: Global Variables
Many thanks for your help.
Computerman
It was much easier in VB6, but I am now liking Vb.Net alot more. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|