473,490 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

constants in global.asa

I've been trying to create read-only global variables by creating
constants (Const) in my global.asa, but I can't seem to reference them.
Sticking them in an include works fine, but it seems more structurally
sound to use Application_OnStart. Am I attempting the impossible, and
if so, why?

Jul 22 '05 #1
20 4440
2obvious wrote on 04 feb 2005 in microsoft.public.inetserver.asp.general:
I've been trying to create read-only global variables by creating
constants (Const) in my global.asa, but I can't seem to reference them.
Sticking them in an include works fine, but it seems more structurally
sound to use Application_OnStart. Am I attempting the impossible, and
if so, why?


Use application variables.

Constants are vbscript [or other script] and die with the page.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #2
What about using the Public declaration in the global.asa? (uh, Can
you use a Public declaration with a constant--isn't Const a declaration
as well?) From what I read, Public cannot be used within a procedure,
so I would have to put it outside Application_OnStart, but it would
still be in the global.asa...

Jul 22 '05 #3
AFAIK you can declare objects but not VBScript constants..

My personal preference is to include a single file in all my ASP Pages that
contains in tunrs includes the most frequently used stuff such as constants,
UI utilities, database access etc...
In each page I can include sometimes more files with very specialized needs.

This way I generally just have to care about a single include file...

Patrice
--

"2obvious" <va********@hotmail.com> a écrit dans le message de
news:11*********************@o13g2000cwo.googlegro ups.com...
I've been trying to create read-only global variables by creating
constants (Const) in my global.asa, but I can't seem to reference them.
Sticking them in an include works fine, but it seems more structurally
sound to use Application_OnStart. Am I attempting the impossible, and
if so, why?

Jul 22 '05 #4
2obvious wrote:
What about using the Public declaration in the global.asa? No (uh, Cany ou use a Public declaration with a constant--isn't Const a
declaration as well?) From what I read, Public cannot be used within
a procedure, so I would have to put it outside Application_OnStart,
but it would still be in the global.asa...


No!
You have to put it into an application variable if you want other pages to
see it!
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #5
Patrice wrote:
AFAIK you can declare objects but not VBScript constants..


That's wrong too.

const cText = "This is constant text"

is a perfectly valid statement.

You just can't put a const into an application variable.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #6
Ok, I actually meant a constant that is public to the whole application
which is what Evertjan is after....

It left finally us with two options :
- using Application variables
- using an include file

Patrice
--

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> a écrit dans le message de
news:uF**************@TK2MSFTNGP12.phx.gbl...
Patrice wrote:
AFAIK you can declare objects but not VBScript constants..


That's wrong too.

const cText = "This is constant text"

is a perfectly valid statement.

You just can't put a const into an application variable.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jul 22 '05 #7
Patrice wrote on 04 feb 2005 in microsoft.public.inetserver.asp.general:
Ok, I actually meant a constant that is public to the whole application
which is what Evertjan is after....

It left finally us with two options :
- using Application variables
- using an include file


As far as I am concerned, in modern programming a constant is just a
variable that is set only once.

In ancient cybertime, often and especially in compiled programs, a constant
was kept in programming memory and a variable in a part of the memory that
could be dynamicly reassigned, taking a lot of processor time, but saving
expensive memory space. Then having seperate constants was a bonus.

Nowadays the idea of a constant is more it's global use, but a variable
will do, if the programmer is not too stupid.

Having seperate constants in vbscript is just nostalgia and useful for the
same stupidity in the context of debugging[, as is option explicit].
The runtime usefullness is zero.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #8
Choose the method that best fit in ASP.

You probably meant the other way round. Constants are still there and should
be used when needed (they guarantee you can't update them). They are
available in .NET...

Patrice
--

"Evertjan." <ex**************@interxnl.net> a écrit dans le message de
news:Xn********************@194.109.133.29...
Patrice wrote on 04 feb 2005 in microsoft.public.inetserver.asp.general:
Ok, I actually meant a constant that is public to the whole application
which is what Evertjan is after....

It left finally us with two options :
- using Application variables
- using an include file

As far as I am concerned, in modern programming a constant is just a
variable that is set only once.

In ancient cybertime, often and especially in compiled programs, a

constant was kept in programming memory and a variable in a part of the memory that
could be dynamicly reassigned, taking a lot of processor time, but saving
expensive memory space. Then having seperate constants was a bonus.

Nowadays the idea of a constant is more it's global use, but a variable
will do, if the programmer is not too stupid.

Having seperate constants in vbscript is just nostalgia and useful for the
same stupidity in the context of debugging[, as is option explicit].
The runtime usefullness is zero.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #9
Patrice wrote on 04 feb 2005 in microsoft.public.inetserver.asp.general:
"Evertjan." <ex**************@interxnl.net> a ‚crit dans le message de
As far as I am concerned, in modern programming a constant is just a
variable that is set only once.

In ancient cybertime, often and especially in compiled programs, a constant
was kept in programming memory and a variable in a part of the memory
that could be dynamicly reassigned, taking a lot of processor time,
but saving expensive memory space. Then having seperate constants was
a bonus.

Nowadays the idea of a constant is more it's global use, but a
variable will do, if the programmer is not too stupid.

Having seperate constants in vbscript is just nostalgia and useful
for the same stupidity in the context of debugging[, as is option
explicit]. The runtime usefullness is zero.


Choose the method that best fit in ASP.

You probably meant the other way round.


No.
Constants are still there and
should be used when needed (they guarantee you can't update them).
As I said, Constants used to have a runtime advantage,
now they have ony a limited [sorry I said zero] use in the programming
phase.

I don't thing that use is important,
so I never use a contant anymore in ASP vbs.
They are available in .NET...


Perhaps, but strictly that is off topic on this classic asp NG.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #10
Ok, this is not my option. I found them usefull and actually it's likely you
are using some of them (such as some ADO, VBScript,
Scripting.FileSystemObject etc...) even if I admit you need to declare them
less frequently.

If you have to define some constant values in your VBScript code library, I
would definitely recommend using constants rather than variables that could
be changed "by accident".

Patrice
Jul 22 '05 #11
Patrice wrote on 04 feb 2005 in microsoft.public.inetserver.asp.general:
Ok, this is not my option. I found them usefull and actually it's
likely you are using some of them (such as some ADO, VBScript,
Scripting.FileSystemObject etc...) even if I admit you need to declare
them less frequently.

If you have to define some constant values in your VBScript code
library, I would definitely recommend using constants rather than
variables that could be changed "by accident".


[Please Patrice, this is not email, but usenet, and others perghaps are not
able to remember the last posting, so please quote relevant parts. Its
netiquette]

Thank you for your recommendation.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #12
Okay, this is what I'm getting:

1) Simply sticking a variable, object, constant, etc. inside the
global.asa isn't enough to make it global. I /must/ be instantiated
inside a procedure.

2) The whole question of whether "Public" and "Const" can be used at
the same time is mute, because you can't have a VBscript constant with
a scope any greater than page scope.

3) VBscript user-created constants are a legacy coding technique.

I can buy that. Especially considering the troubles I've had trying to
translate some of my ASP over to ASP.NET.

Patrice said:
[Constants] are available in .NET...


--are you /sure/? I certainly couldn't find them. I'm talking
specifically about ASP.NET, not the whole VB.NET language. 'Best I
could do was read-only variables.

But Evertjan. is right. Sticking to ASP issues: really, I only use
constants to prevent accidentally changing variables that are...well,
constant. So a new spin on this question:

Is there a way to create read-only variables with application scope in
the Application_OnStart procedure?

Jul 22 '05 #13
2obvious wrote:
Okay, this is what I'm getting:

1) Simply sticking a variable, object, constant, etc. inside the
global.asa isn't enough to make it global. I /must/ be instantiated
inside a procedure.
No. it must be put into either a Session or Application variable in order to
make it global to all pages. This can be done anywhere: in global.asa, or in
any of the pages in the application, either inside or outside a procedure.
In global.asa:

Sub Application_onstart
Application("globalvar") = "test"
end sub
in test.asp:
<%
Response.Write Application("globalvar")
%>


2) The whole question of whether "Public" and "Const" can be used at
the same time is mute, because you can't have a VBscript constant with
a scope any greater than page scope.
True

3) VBscript user-created constants are a legacy coding technique.

I can buy that. Especially considering the troubles I've had trying
to translate some of my ASP over to ASP.NET.

I'm not so sure I buy that. When constants are used, the constant values are
written into the compiled code at compile-time. When variables are used,
memory is allocated to contain the values that will be supplied at runtime.
I don't understand why that amounts ot "zero value".
Patrice said:
[Constants] are available in .NET...
--are you /sure/? I certainly couldn't find them.


1. vbscript can still be used in an aspx page. vbscript doesn't lose the
Const keyword just because of where its being used
2. http://msdn.microsoft.com/library/en...vastmConst.asp
I'm talking
specifically about ASP.NET, not the whole VB.NET language. 'Best I
could do was read-only variables.

But Evertjan. is right. Sticking to ASP issues: really, I only use
constants to prevent accidentally changing variables that are...well,
constant. So a new spin on this question:

Is there a way to create read-only variables with application scope in
the Application_OnStart procedure?


No. There is no such thing as a read-only variable. If that is truly what
you want, then you need to use include files or classes.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #14
>When constants are used, the constant values are
written into the compiled code at compile-time.
When variables are used, memory is allocated to
contain the values that will be supplied at runtime.
I thought Active Server Pages were interpreted, not compiled.
There is no such thing as a read-only variable. If
that is truly what you want, then you need to use
include files or classes.


Wait! --And Application variables can't be arrays or objects, they're
just your run-of-the-mill untyped variable? Hmm.

Jul 22 '05 #15
2obvious wrote:
When constants are used, the constant values are
written into the compiled code at compile-time.
When variables are used, memory is allocated to
contain the values that will be supplied at runtime.
I thought Active Server Pages were interpreted, not compiled.


This might help:
http://blogs.msdn.com/ericlippert/ar.../21/53264.aspx
There is no such thing as a read-only variable. If
that is truly what you want, then you need to use
include files or classes.


Wait! --And Application variables can't be arrays or objects, they're
just your run-of-the-mill untyped variable? Hmm.


No, they can be arrays. They can even be objects. However, just because you
can put an object in application or session does not mean that you should.
Only free-threaded objects should be put in application or session.
Otherwise, your application becomes thread-bound, which serializes all uses
of the object, killing performance.
http://www.aspfaq.com/2053

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #16
2obvious wrote:
When constants are used, the constant values are
written into the compiled code at compile-time.
When variables are used, memory is allocated to
contain the values that will be supplied at runtime.

I thought Active Server Pages were interpreted, not compiled.


No. VBScript/Jscript pages are compiled to a pseudo-code (p-code) and
then that p-code is interpreted.

Read this post to see an example of the p-code:
http://groups-beta.google.com/group/...oring=r&rnum=2

Also see Appendix 3 of
http://www.microsoft.com/technet/pro...tune.mspx#ECAA
for details of how the compiled p-code is cached in ASP.
Jul 22 '05 #17
Wow. Given its ramifications, the global.asa file is now seeming
pretty useless.

After all, Application variables can be created anywhere. And from the
looks of things, Session variables are only used by "lazy" programmers.

I can say that, because I happen to be one of those lazy programmers.
I'm maintaining an application that wasn't very well planned out.
Consequently, I end up having to create new data structures after the
fact. Most of this data should be stored in objects, but as things
stand there are a bazillion variables passed in hidden form fields,
which is a royal headache to trace.

....But better for me to do the tracing than to dump this burden on the
server, right?

(...I can't wait to finally get this .NET thing figured out...)

Jul 22 '05 #18
2obvious wrote:
Wow. Given its ramifications, the global.asa file is now seeming
pretty useless.

After all, Application variables can be created anywhere.
True, but single-initiation variables should be initiated during
application_onstart. Other pages should only be setting application
variables if the value for the variable either needs to change during the
loading of the pages, or the value is not known during onstart.
And from
the looks of things, Session variables are only used by "lazy"
programmers.
No! Not true at at all! Storing scalar values in session or application is
an excellent way to cache them. Avoiding I/O or database access is still a
laudable goal. Yes, they can be over-used by "lazy" programmers, but their
use does not necessarily indicate laziness.

I can say that, because I happen to be one of those lazy programmers.
I'm maintaining an application that wasn't very well planned out.
Consequently, I end up having to create new data structures after the
fact. Most of this data should be stored in objects, but as things
stand there are a bazillion variables passed in hidden form fields,
which is a royal headache to trace.


As I said, arrays are still do-able. You may also want to look into the XML
Document, an object which IS free-threaded and therefore suitable to being
stored in Application/Session

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #19
In VB.NET this is still the "Const" keyword (I don't see what you meant by
"specifically ASP.NET", ASP.NET uses anyway VB.NET, C# or some other .NET
language).

Here it looks Evertjan is not really after constants but after configuration
variables that are defined outside the application an read only inside in
the application.

I see basically two options :
- constants once again (having for example a const.asp editable file with
all constants for the app)

Const App_Path=\\myserver\folder\whatever

Granted for some reason Id on"t really understand, this is not wanted (don't
want include files ?)

Another option would to use VBScript classes. If the class only has a
proprety get the property can be read but can't be set. Unfortunately
support for classes is quite light and you'll still need include fields
unless you want to type the same things over and over again...

Patrice
--

"2obvious" <va********@hotmail.com> a écrit dans le message de
news:11**********************@f14g2000cwb.googlegr oups.com...
Okay, this is what I'm getting:

1) Simply sticking a variable, object, constant, etc. inside the
global.asa isn't enough to make it global. I /must/ be instantiated
inside a procedure.

2) The whole question of whether "Public" and "Const" can be used at
the same time is mute, because you can't have a VBscript constant with
a scope any greater than page scope.

3) VBscript user-created constants are a legacy coding technique.

I can buy that. Especially considering the troubles I've had trying to
translate some of my ASP over to ASP.NET.

Patrice said:
[Constants] are available in .NET...


--are you /sure/? I certainly couldn't find them. I'm talking
specifically about ASP.NET, not the whole VB.NET language. 'Best I
could do was read-only variables.

But Evertjan. is right. Sticking to ASP issues: really, I only use
constants to prevent accidentally changing variables that are...well,
constant. So a new spin on this question:

Is there a way to create read-only variables with application scope in
the Application_OnStart procedure?

Jul 22 '05 #20
Patrice wrote on 07 feb 2005 in microsoft.public.inetserver.asp.general:
Here it looks Evertjan is not really after constants but after
configuration variables that are defined outside the application an
read only inside in the application.


I wouldn't know where I was after.
Certainly not something "external" to an apllication.
I am not the OP, I thought you where, Patrice?

The only point I wanted to make was, that constants used to have a
compiling advantage in the old days,
and nowadays they only are an additional bonus against programming
mistakes, the usefulness of which is very limited in small scale
programming on an asp page.

In larger programming tasks however,
seperate constants and also option explicit are very usefull.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1854
by: Raymond Hettinger | last post by:
Comments are invited on the following proposed PEP. Raymond Hettinger ------------------------------------------------------- PEP: 329
0
3030
by: David W. Fenton | last post by:
Today I was working on a hideous old app that I created a long time ago that does a lot of showing/hiding/resizing of fields on one of the forms. I had used constants to store reference values for...
4
51141
by: Amadelle | last post by:
Hi all and thanks again in advance, What is the best way of defining global constants in a C# application? (A windows application with no windows forms - basically a set of classes). Would it be...
8
2861
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger...
1
3008
by: 2obvious | last post by:
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...
11
7748
by: Bill Nguyen | last post by:
I need to make a set of constants to be available for the whole application. Public const is confined to the form from which constants are declared. Is there a way to declare once and all forms can...
3
1787
by: www.gerardvignes.com | last post by:
I do most JavaScript programming with objects and methods. I use tiny boot and shutdown scripts as hooks for the browser load and unload events. My JavaScripts interact with scripts running on...
14
1891
by: adam.timberlake | last post by:
This is a really basic question for all you people out there who know PHP. This is not a problem but just something I'm confused about. I was reading the article below and wondered why are normal...
54
3546
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.