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. :)
Printable View
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. :)
How about in a Module?
Typically connection strings are stored in a config file.
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.
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. :)
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.
Many thanks for your help.
Computerman :)