no global constants in global.asax?

Discussion in 'ASP .Net' started by 2obvious, Sep 4, 2004.

  1. 2obvious

    2obvious Guest

    I want to declare some constants on the application level in
    global.asax to use throughout my application, e.g.:

    Sub Application_OnStart()
    Const NUM As Integer = 5
    End Sub

    Problem is, when I do it this way, the scope of the constants is
    local--attempting to use these constants in a typical .aspx file
    throws an error telling me that 'NUM' is undeclared. Doing this:

    Sub Application_OnStart()
    Global Const NUM As Integer = 5
    End Sub

    or this:

    Sub Application_OnStart()
    Public Const NUM As Integer = 5
    End Sub

    doesn't work either; illegal syntax.

    Can this be done? Keep in mind I'm talking about global _constants;_
    I already know how to make Application variables. Those are
    variables, they can be changed.
    2obvious, Sep 4, 2004
    #1
    1. Advertising

  2. 2obvious

    Karl Guest

    Create your own VB file, called it Globals.vb or Utility.Vb or something:

    Public Class Globals
    Private Const _smtpServer As String = "127.0.0.1"
    Public ReadOnly Property SmtpServer() As String
    Get
    Return _smtpServer
    End Get
    End Property
    ...
    End Class


    You can then access this as Globals.SmtpServer

    If this is a serious project, consider implementing a configSection which
    won't hard-code a value into your .dll:
    http://openmymind.net/Configuration/index.html

    Karl



    "2obvious" <> wrote in message
    news:...
    > I want to declare some constants on the application level in
    > global.asax to use throughout my application, e.g.:
    >
    > Sub Application_OnStart()
    > Const NUM As Integer = 5
    > End Sub
    >
    > Problem is, when I do it this way, the scope of the constants is
    > local--attempting to use these constants in a typical .aspx file
    > throws an error telling me that 'NUM' is undeclared. Doing this:
    >
    > Sub Application_OnStart()
    > Global Const NUM As Integer = 5
    > End Sub
    >
    > or this:
    >
    > Sub Application_OnStart()
    > Public Const NUM As Integer = 5
    > End Sub
    >
    > doesn't work either; illegal syntax.
    >
    > Can this be done? Keep in mind I'm talking about global _constants;_
    > I already know how to make Application variables. Those are
    > variables, they can be changed.
    Karl, Sep 4, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    1
    Views:
    770
    Alvin Bruney
    Jul 29, 2003
  2. Daniel Bass
    Replies:
    2
    Views:
    6,864
    Daniel Bass
    Dec 31, 2003
  3. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    804
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  4. Daves

    global.asax or global.ascx?

    Daves, Mar 15, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    3,981
    Scott M.
    Mar 16, 2005
  5. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,143
    Mark Rae
    May 23, 2006
Loading...

Share This Page