• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

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?

Thanks!
0
MIKEV
Asked:
MIKEV
  • 3
  • 2
2 Solutions
 
iboutchkineCommented:
Cretae a module and add the global variables there
0
 
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!

SoMoS
0
 
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!!!
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Yeah, I have the luck of just being a vb.net programmer without having vb6 skills. I don't like anything that is not related with OOP :)
0
 
iboutchkineCommented:
Module is not absolete. Just in VB.NET it is Shared class. that is all
0
 
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?
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now