Globals within class libraries

I have a DLL project with muliple classes;  Data classes actually and all these use the same basic connection string.  Rather than define them separately for each class I tried this at the top of the file:

Dim ConnectString as String

But I get the error "Statement not valid within a namespace".  I understand why but what would be a workaround that will accomplish the same thing; maintain a value common to all the classes within the class library?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cretae a module and add the global variables there
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Create a class on the same DLL project called "Config" or "Global" or whatever and create public constants like:

Public Class Config

    Public Const connectionString as String = "PutHereTheText"

End Class

Then do an import of this class on the other classes

Imports Config


Askme more if you need it!


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MIKEVAuthor Commented:
"Cretae a module and add the global variables there"

I've read the concept of modules in VB.Net will become obsolete, I'd rather not back myself into that corner, but it's currently a valid solution.

"Create a class on the same DLL project called "Config" or "Global" or whatever and create public constants like:"

That's it.  Perfect, thanks!!!
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Yeah, I have the luck of just being a programmer without having vb6 skills. I don't like anything that is not related with OOP :)
Module is not absolete. Just in VB.NET it is Shared class. that is all
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Okok, that's right, but in normal OOP you don't use to define shared classes aren't you?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.