1. Add App_Code folder
2. Add class file (Globals.vb)
3. Search and replace Class with Module
You now have a module without a problem and it looks like this:
Imports Microsoft.VisualBasic
Public Module Globals
'Implementation here
End Module
This is not necessary, even for "global" variables, however, as you can set
up global configurations in the config file or create your own "config"
object with Shared members (fields and/or properties) and methods. The only
thing Module does for you is force the compiler to share all of the bits in
the class (er, Module) without you having to declare them as Shared (ie, it
saves a small bit of typing while obfuscating meaning ;->).
Public Class Globals2
Private Sub New()
'Make sure it cannot be instantiated
End Sub
Public Shared MagicNumber As Integer= 42
End Class
This serves the same purpose as the Module below, with a few extra keystrokes
Public Module Globals
Public MagicNumber As Integer = 42
End Module
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Iouri" wrote:
I am using VS 2005 team edition. I cannot find Module in ASP.NET 2.0. It is
not in the list of Visual Studio installed templates. Where is it? or what
can I use to hold my global variables and Subs accessible from different
pages.
I tried to add class and make it Shared, but I am getting an error message
that classes cannot be declared Shared.
Also VS does not let me declare shaered constants in a class.
I need to use the same sub from different pages.
Does somebody have a solution for that?
Thank you