Question With regards to Global variables in VB.Net

Posted on 2006-05-30
Last Modified: 2010-04-23
Can anybody tell me if there is any better way to use global variables. I have created this new flag at global level and I am passing it to other subforms, to determine if the functionality is to be switched on:

Dim args() As Object = {Me.OrderDS, bApplicationStatusOrder}
NewOrderLineForm = Me.ActivateForm(GetType(NewOrderLine), True, args)

But I am findinding that in the Subforms I am having to add the param to alot of Subs and functions. Is there anyway I can use another structure that i can reference directly without modifying the parameter list of subs and functions.


Question by:anwarmir
    LVL 52

    Expert Comment

    by:Carl Tawn
    The easiest way to handle it would be to create a class with Shared members to provide global access.

        Public Class Globals
            Public Shared FirstName As String
        End Class

    Then access it with something like:

        Dim fName As String = Globals.FirstName

    I only use a public variable, rather than a property, to demonstrate the idea.
    LVL 96

    Expert Comment

    by:Bob Learned
    Yeah, create a data access layer in a class.


    Author Comment

    Thanks This seems to work quite well can you tell me what a Shared members class is opposed to a standard class
    LVL 52

    Accepted Solution

    Shared members belong to the class itself rather than instances of the class.


        Public Class Class1
            Public FirstName As String
        End Class

        Public Class Class2
            Public Shared FirstName As String
        End Class

        Dim o1 As New Class1()
        Dim o2 As New Class1()
        o1.FirstName = "Bob"
        o2.FirstName = "Bill"

    These two objects both have a FirstName member each with a different value.

        Class2.FirstName = "Bob"
        Class2.FirstName = "Bill"

    Because FirstName in Class2 is Shared both of the lines above change the same Shared member of Class2. We don not need to create an instance of Class2 in order to access or change its value.

    Author Comment


    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

    Join & Write a Comment

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    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 (…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    729 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

    22 Experts available now in Live!

    Get 1:1 Help Now