|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Global VariableI 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). -- Show quoteHide quoteBryan Phillips MCSD, MCDBA, MCSE Blog: http://bphillips76.spaces.live.com Web Site: http://www.composablesystems.net "Elmo Watson" <wha***@yahoo.com> wrote in message news:OGlyucSgHHA.3676@TK2MSFTNGP05.phx.gbl: > 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? 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 Show quoteHide quote "Elmo Watson" <wha***@yahoo.com> wrote in message news:OGlyucSgHHA.3676@TK2MSFTNGP05.phx.gbl... >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? >
Other interesting topics
Databind a nullable date to a masked textbox
This code compiles/runs but breaks designer... Adding an event handler to a dynamically populated control Datagridview help ClickOnce Deployment in a Plug-in architecture context Generated Program.cs uses special way of disposing native resource Login window vs Main window Newbie question: how to set focus to a usercontrol How to read Default Values from App.Config for User Settings? print the current time on the screen |
|||||||||||||||||||||||