PC Review


Reply
Thread Tools Rate Thread

How can I have global variables?

 
 
MeAgin
Guest
Posts: n/a
 
      19th Feb 2007
Hi all,



I want to maintain few variables available for all the classes within the
system. For example the session key and the logged in user'd ID. How can I
do this? I can have a class with all these as properties. But how can I make
a instance of that classes available everywhere?

Thanks.

Nadee




 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      19th Feb 2007
"MeAgin" <(E-Mail Removed)> schrieb
> I want to maintain few variables available for all the classes
> within the system. For example the session key and the logged in
> user'd ID. How can I do this? I can have a class with all these as
> properties. But how can I make a instance of that classes available
> everywhere?



For example by making it available by a Public Shared Readonly Property. I
usually have an Application class for this purpose.


Armin

 
Reply With Quote
 
Branco Medeiros
Guest
Posts: n/a
 
      19th Feb 2007
MeAgin wrote:
> I want to maintain few variables available for all the classes within the
> system. For example the session key and the logged in user'd ID. How can I
> do this? I can have a class with all these as properties. But how can I make
> a instance of that classes available everywhere?

<snip>

Put an instance of your class in a Module:

<aircode>
Module Globals
Private mState As New AppState

Public ReadOnly Property State As AppState
Get
Return mState
End Get
End Property
...
End Module
</aircode>

In the above example, the State property will be available to the
entire application.

HTH.

Regards,

Branco.

 
Reply With Quote
 
Spam Catcher
Guest
Posts: n/a
 
      19th Feb 2007
"MeAgin" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> I want to maintain few variables available for all the classes within
> the system. For example the session key and the logged in user'd ID.
> How can I do this? I can have a class with all these as properties.
> But how can I make a instance of that classes available everywhere?


You can use Shared (Static) variables or the My.Applications.Settings
class.
 
Reply With Quote
 
Juan Romero
Guest
Posts: n/a
 
      19th Feb 2007
You can add a module to your project and expose these values either as
variables or as properties.

You can also add a class with shared properties.

Adding a module is basically the same as adding a class since the compiler
will silently create the class with shared methods out of the module for you
upon compilation.

Good luck!

JR

"MeAgin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
>
>
>
> I want to maintain few variables available for all the classes within the
> system. For example the session key and the logged in user'd ID. How can I
> do this? I can have a class with all these as properties. But how can I
> make
> a instance of that classes available everywhere?
>
> Thanks.
>
> Nadee
>
>
>
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      19th Feb 2007
Branco,

> In the above example, the State property will be available to the
> entire application.


Nice, what can I add, Maybe:

To make your program good maintable you can use this as:
Globals.State

:-)

Cor

"Branco Medeiros" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> MeAgin wrote:
>> I want to maintain few variables available for all the classes within the
>> system. For example the session key and the logged in user'd ID. How can
>> I
>> do this? I can have a class with all these as properties. But how can I
>> make
>> a instance of that classes available everywhere?

> <snip>
>
> Put an instance of your class in a Module:
>
> <aircode>
> Module Globals
> Private mState As New AppState
>
> Public ReadOnly Property State As AppState
> Get
> Return mState
> End Get
> End Property
> ...
> End Module
> </aircode>
>
> In the above example, the State property will be available to the
> entire application.
>
> HTH.
>
> Regards,
>
> Branco.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Global Variables/Session Variables =?Utf-8?B?ZGNoMw==?= Microsoft Outlook VBA Programming 2 31st May 2007 01:11 PM
Global variables Ed Microsoft Excel Programming 6 19th Nov 2006 10:55 PM
Global variables, reading variables from a file Andrew Cushen Microsoft Outlook VBA Programming 15 22nd Jan 2004 03:02 PM
Global variables on par with ASP's global.asa Wayne Microsoft ASP .NET 2 11th Nov 2003 10:58 PM
Global Variables J Microsoft ASP .NET 4 19th Aug 2003 05:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:33 PM.