Global Variable

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
E

Elmo Watson

I have a handfull of variables that I'd like to make Global to my
application
In the old VB6 days, I'd create a Module, and put them there, accessible
from any form in the application

However, in VS.Net 2005, I added a module, and it acts somewhat like a
class, in that, to access a Public variable, there, I must precede the
variable name with the module name, like:
mdlVars.MyVar

Is this pretty much how it's done, or, if not, what's a more acceptible
approach?
 
The module is the best place for it but you can still live up the old
days by adding an import to the project with the full name of your
module (including the namespace).
 
I would suggest class with static members and related properties

Something like this

public class Globals {
internal static <type> globVar1;
...

public static <type> Var1 {
get {
return globVar1;
}
}
....
}

Then you can get your global like this:

myVar = Globals.Var1;

You can compile class into dll or use directly in the app.

Alex
 
Back
Top