How can I have global variables?

  • Thread starter Thread starter MeAgin
  • Start date Start date
M

MeAgin

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
 
MeAgin said:
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
 
MeAgin said:
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.
 
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.
 
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
 
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
 
Back
Top