no global constants in global.asax?

2

2obvious

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.
 
K

Karl

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top