Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   no global constants in global.asax? (http://www.velocityreviews.com/forums/t86064-no-global-constants-in-global-asax.html)

2obvious 09-03-2004 11:49 PM

no global constants in global.asax?
 
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 09-04-2004 12:36 AM

Re: no global constants in global.asax?
 
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" <vadivasbro@hotmail.com> wrote in message
news:6e537be.0409031549.364cbdaf@posting.google.co m...
> 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.





All times are GMT. The time now is 08:31 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.