Solved

VB.net - holding string variable that is used all over the application

Posted on 2011-09-08
4
248 Views
Last Modified: 2012-05-12
Hi

In VB.net 2010 I load the path of a database into a variable
declared as follows at the top of a standard module

 Public sPath  As String

Will this be held in that variable while the application is running or is there a better place to store
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36504921
Sounds like you would want a configuration setting. Have you considered adding it to the config file?
0
 
LVL 13

Expert Comment

by:khairil
ID: 36505058
Hi,

What DB are you using, is it PATH of database or Connection string?

You can always put public declared variables by adding a Module and put declaration in there. It can now be access/change from anywhere in the project.

For database connection, it is better to store in in <app>.config file. Since it is a plain text and your connection string consist userid and password, it must be protected, here is how to do, http://msdn.microsoft.com/en-us/library/89211k9b(v=vs.80).aspx
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 36505161
May be an issue if you wantthe variable utilized in another class where you have to expressly pass its value. Utilize My.Settings to hod your string variable and you can reference it directly (from any class without expressly  passing it).
0
 

Author Closing Comment

by:murbro
ID: 36505856
Thanks that worked perfectly for my purposes
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question