Solved

Globals within class libraries

Posted on 2004-11-02
231 Views
Last Modified: 2010-04-24
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
Question by:MIKEV
    6 Comments
     
    LVL 28

    Assisted Solution

    by:iboutchkine
    Cretae a module and add the global variables there
    0
     
    LVL 5

    Accepted Solution

    by:
    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
     

    Author Comment

    by:MIKEV
    "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
     
    LVL 5

    Expert Comment

    by:Ignacio Soler Garcia
    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
     
    LVL 28

    Expert Comment

    by:iboutchkine
    Module is not absolete. Just in VB.NET it is Shared class. that is all
    0
     
    LVL 5

    Expert Comment

    by:Ignacio Soler Garcia
    Okok, that's right, but in normal OOP you don't use to define shared classes aren't you?
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    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 …
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    884 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now