Results 1 to 7 of 7

Thread: [RESOLVED] Global Variables

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    Resolved [RESOLVED] Global Variables

    How do I defiine a global variable for the whole application so that it does not have to be defined in all the forms that need it.

    ie data path for database.

    Computerman.
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Global Variables

    How about in a Module?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Global Variables

    Typically connection strings are stored in a config file.
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Global Variables

    Quote Originally Posted by computerman View Post
    How do I defiine a global variable for the whole application so that it does not have to be defined in all the forms that need it.

    ie data path for database.

    Computerman.
    Maybe that is just your example, but a data path for a database should only ever be defined one time. There should be a single method in your project for opening a database connection. If you have it now where everytime you need to connect to the database, you have basically a copy/paste of database connection code, then you should probably consider reworking the code a little. One small change in the database access code turns into 20 places that you need to change in code, versus just doing it in 1 spot.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    Re: Global Variables

    I understand what you are saying. The underlying issue that I have is that I have to open my Application System Parameters file each time I want to get a user defined variable, which could be used in various forms.

    So instead of opening the file everytime I need that variable, it would be advantageous for it to be defined globally.

    Using the data path for the db was not a good example.

    Computerman.
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Global Variables

    Why not just use the built in application settings feature that VB.NET supports in the project properties?

    You can make custom settings in here that can be accessed globally in your code. You also get intellisense support for these settings. Using a scope of 'User' makes these settings read/write, while using a scope of 'application' will make them readonly settings.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    Re: Global Variables

    Many thanks for your help.

    Computerman
    It was much easier in VB6, but I am now liking Vb.Net alot more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width