|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how do you use Class to hold global variables?in the old VB, you can use global variables to hold commonly use data. i'll
like to pass a variables selected by user in the combobox, how do you hold this variable for other object to use. does anyone have an example? You can use a static property.
For example: public class Global { private Global() {} public static string UserName; } Steven Nagy wrote:
> You can use a static property. Sorry I thought I was in the C# group.> > For example: > > public class Global { > private Global() {} > > public static string UserName; > > } Here's the VB code: public class Global public shared string UserName end class Hello dotnetnoob,
You can create a module, and declare Global variables in the module just the way you did in the old VB. Classes are not actually meant as holders of global variables. Just add a module to your project and declare a variable like this Public myVariable as Integer Regards Cyril Gupta You can do anything with a little bit of 'magination. I have been programming so long, that my brain is now soft-ware. http://www.cyrilgupta.com/blog Show quoteHide quote > in the old VB, you can use global variables to hold commonly use data. > i'll like to pass a variables selected by user in the combobox, how do > you hold this variable for other object to use. does anyone have an > example? > thank all for reply.
how do you pass commonly use variable in C# then? so i can add a module in my program to hold the data selected by user in combobox and use it for other object to access, am i correct? Show quoteHide quote "Cyril Gupta" wrote: > Hello dotnetnoob, > > You can create a module, and declare Global variables in the module just > the way you did in the old VB. Classes are not actually meant as holders > of global variables. > > Just add a module to your project and declare a variable like this > > Public myVariable as Integer > > Regards > Cyril Gupta > > You can do anything with a little bit of 'magination. > I have been programming so long, that my brain is now soft-ware. > http://www.cyrilgupta.com/blog > > > in the old VB, you can use global variables to hold commonly use data. > > i'll like to pass a variables selected by user in the combobox, how do > > you hold this variable for other object to use. does anyone have an > > example? > > > > > Hi there,
Sorry but that is just not true. You can object orientate anything. In fact I'd rather do that than use modules any day. In my honest opinion a shared class is much better than a module, ------------------------- Public Class GlobalObjects '//Hide the constructor as it is not needed Private Sub New() End Sub Public Shared gBlnDebugMode As Boolean End Class ------------------------- Nick. Show quoteHide quote "Cyril Gupta" <cyril@nospam.com> wrote in message news:a95a8c81bae98c8bff169eff700@msnews.microsoft.com... > Hello dotnetnoob, > > You can create a module, and declare Global variables in the module just > the way you did in the old VB. Classes are not actually meant as holders > of global variables. > > Just add a module to your project and declare a variable like this > > Public myVariable as Integer > > Regards > Cyril Gupta > > You can do anything with a little bit of 'magination. > I have been programming so long, that my brain is now soft-ware. > http://www.cyrilgupta.com/blog > >> in the old VB, you can use global variables to hold commonly use data. >> i'll like to pass a variables selected by user in the combobox, how do >> you hold this variable for other object to use. does anyone have an >> example? >> > > Just as an addition: Depending on how you plan to use the variable, you
may want to consider wrapping the variable in a public shared property. This comes in handy for things like validating entries, error trapping, etc... Thanks, Seth Rowe NickP wrote: Show quoteHide quote > Hi there, > > Sorry but that is just not true. You can object orientate anything. In > fact I'd rather do that than use modules any day. > > In my honest opinion a shared class is much better than a module, > > ------------------------- > > Public Class GlobalObjects > > '//Hide the constructor as it is not needed > Private Sub New() > End Sub > > Public Shared gBlnDebugMode As Boolean > > End Class > > ------------------------- > > Nick. > > "Cyril Gupta" <cyril@nospam.com> wrote in message > news:a95a8c81bae98c8bff169eff700@msnews.microsoft.com... > > Hello dotnetnoob, > > > > You can create a module, and declare Global variables in the module just > > the way you did in the old VB. Classes are not actually meant as holders > > of global variables. > > > > Just add a module to your project and declare a variable like this > > > > Public myVariable as Integer > > > > Regards > > Cyril Gupta > > > > You can do anything with a little bit of 'magination. > > I have been programming so long, that my brain is now soft-ware. > > http://www.cyrilgupta.com/blog > > > >> in the old VB, you can use global variables to hold commonly use data. > >> i'll like to pass a variables selected by user in the combobox, how do > >> you hold this variable for other object to use. does anyone have an > >> example? > >> > > > > Exactly, much more friendly than a simple module...
Show quoteHide quote "rowe_newsgroups" <rowe_em***@yahoo.com> wrote in message news:1161100463.848443.200570@e3g2000cwe.googlegroups.com... > Just as an addition: Depending on how you plan to use the variable, you > may want to consider wrapping the variable in a public shared property. > This comes in handy for things like validating entries, error trapping, > etc... > > Thanks, > > Seth Rowe > > > NickP wrote: >> Hi there, >> >> Sorry but that is just not true. You can object orientate anything. >> In >> fact I'd rather do that than use modules any day. >> >> In my honest opinion a shared class is much better than a module, >> >> ------------------------- >> >> Public Class GlobalObjects >> >> '//Hide the constructor as it is not needed >> Private Sub New() >> End Sub >> >> Public Shared gBlnDebugMode As Boolean >> >> End Class >> >> ------------------------- >> >> Nick. >> >> "Cyril Gupta" <cyril@nospam.com> wrote in message >> news:a95a8c81bae98c8bff169eff700@msnews.microsoft.com... >> > Hello dotnetnoob, >> > >> > You can create a module, and declare Global variables in the module >> > just >> > the way you did in the old VB. Classes are not actually meant as >> > holders >> > of global variables. >> > >> > Just add a module to your project and declare a variable like this >> > >> > Public myVariable as Integer >> > >> > Regards >> > Cyril Gupta >> > >> > You can do anything with a little bit of 'magination. >> > I have been programming so long, that my brain is now soft-ware. >> > http://www.cyrilgupta.com/blog >> > >> >> in the old VB, you can use global variables to hold commonly use data. >> >> i'll like to pass a variables selected by user in the combobox, how do >> >> you hold this variable for other object to use. does anyone have an >> >> example? >> >> >> > >> > > I've always hated modules personally... no real scope and no
encapsulation. Funny, I always thought modules were in fact Classes with all the variables
and procedures Shared! Can you explain the difference? -- Show quoteHide quoteDennis in Houston "Steven Nagy" wrote: > I've always hated modules personally... no real scope and no > encapsulation. > > While I could get out the old soapbox, I think I'll just advise readers
to search the ng for this heavily debated topic! But if you don't want to search too much then the main differences I know of are that modules are given an automatic project wide import statement (kinda), and can't be instantiated. Thanks, Seth Rowe Dennis wrote: Show quoteHide quote > Funny, I always thought modules were in fact Classes with all the variables > and procedures Shared! > > Can you explain the difference? > > -- > Dennis in Houston > > > "Steven Nagy" wrote: > > > I've always hated modules personally... no real scope and no > > encapsulation. > > > > I'm not sure how they run under the hood. Chances are that they are
just a class. > the main differences I know of are that modules ... which means that you can't control scope. So its better to use a> are given an automatic project wide import statement (kinda), class and implement it in a way that scope is important. Modules are often misused. People stick everything in them. I've seen forms declared in there, database connections, etc. Implement a class instead. Control access as necessary. Implement a singleton where relevant. There's always a better way to go.
VB.NET Datagrid with pictures
VB equivalent of this C# code Why no patch for the anoying Visual Basic compiler problem What framework is running in this scenario? Pause and Stop Search Help System .chm linking problem Not CLS-compliant warning... Help understanding user created Delegates Arrow on a button control User controls in VS 2005 |
|||||||||||||||||||||||