Static Variables
am 21.03.2005 07:13:30 von harishHi,
Just I want to use a static variable, that should be accessible for any of
my ASP pages.
How should I declare a variable as static?
TIA
Harish
Hi,
Just I want to use a static variable, that should be accessible for any of
my ASP pages.
How should I declare a variable as static?
TIA
Harish
Harish wrote on 21 mrt 2005 in microsoft.public.inetserver.asp.db:
> Just I want to use a static variable,
"static variable"?
A contradictio in terminis.
> that should be accessible for any of my ASP pages.
... from .. ?
put it in an include.
or
declare a application variable.
> How should I declare a variable as static?
application("myStaticVariable") = 17
' Don't touch this variable, you will get a static shock.
================
btw, why ask this in NG .db instead of .general ?
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)
Thanks for your quick help
Harish
"Evertjan."
news:Xns96206F4DA2EC4eejj99@194.109.133.29...
> Harish wrote on 21 mrt 2005 in microsoft.public.inetserver.asp.db:
> > Just I want to use a static variable,
>
> "static variable"?
>
> A contradictio in terminis.
>
> > that should be accessible for any of my ASP pages.
>
> .. from .. ?
>
> put it in an include.
>
> or
>
> declare a application variable.
>
>
> > How should I declare a variable as static?
>
> application("myStaticVariable") = 17
> ' Don't touch this variable, you will get a static shock.
>
> ================
>
> btw, why ask this in NG .db instead of .general ?
>
> --
> Evertjan.
> The Netherlands.
> (Replace all crosses with dots in my emailaddress)
>
Harish wrote:
> Hi,
> Just I want to use a static variable, that should be accessible for
> any of my ASP pages.
>
> How should I declare a variable as static?
>
> TIA
> Harish
Let's define terms:
"static" is used to describe a variable whose value does not change until
the code changes it, even when it goes out of "immediate" scope.. For
example, in this VB function:
function dothis()
static statvar as integer
statvar=statvar + 1
msgbox statvar
end function
dothis
dothis
dothis
When this code is run, you will get three message boxes, containing 1, then
2, then 3. if statvar was declared using the Dim keyword, instead of the
Static keyword, the message boxes would each display the value 1.
Neither vbscript nor javascript supports the concept of a static variable.
So, if this is what you mean by "static" then the answer is "no".
However, given your requirement that the data element be accessible
globally, I suspect that you are actually talking about a "constant", which
is defined as a data element whose value is assigned at design/compile time
and cannot be changed during runtime.
Javascript does not support constants: all data elements are variables.
Vbscript does support the use of the Const keyword:
const notchangable="some data"
Since ASP supports multiple languages, it does not support the idea of a
global constant. Application and Session variables are globally accessible,
but they are changable.
So let's concentrate on vbscript Constants are only usable when they are in
scope. That means they have to be created every time a page loads. There are
three ways to do this:
1. Include files. The adovbs.inc file located on your hard drive is an
example of this. There are disadvantages: the include file has to be
included on each page, and since it probably contains constant delarations
that will not be used on every page in which it is included, it causes your
page size to be larger than necessary.
2. Classes. You can create read-only properties in vbscript classes. Again,
you need to write code on every page to bring the class into scope.
3. Create a dll with a type library. You can use a metadata tag in
global.asa to make this type library accessible to all the pages in your
application. This is the best solution, however, you require a diffferent
development tool and expertise to use that tool to accomplish this (use
Google to get details).
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"
Thanks for your explanation.
"Bob Barrows [MVP]"
news:#aRAF$gLFHA.732@TK2MSFTNGP12.phx.gbl...
> Harish wrote:
> > Hi,
> > Just I want to use a static variable, that should be accessible for
> > any of my ASP pages.
> >
> > How should I declare a variable as static?
> >
> > TIA
> > Harish
>
> Let's define terms:
>
> "static" is used to describe a variable whose value does not change until
> the code changes it, even when it goes out of "immediate" scope.. For
> example, in this VB function:
>
> function dothis()
> static statvar as integer
> statvar=statvar + 1
> msgbox statvar
> end function
> dothis
> dothis
> dothis
>
> When this code is run, you will get three message boxes, containing 1,
then
> 2, then 3. if statvar was declared using the Dim keyword, instead of the
> Static keyword, the message boxes would each display the value 1.
>
> Neither vbscript nor javascript supports the concept of a static
variable.
> So, if this is what you mean by "static" then the answer is "no".
>
> However, given your requirement that the data element be accessible
> globally, I suspect that you are actually talking about a "constant",
which
> is defined as a data element whose value is assigned at design/compile
time
> and cannot be changed during runtime.
>
> Javascript does not support constants: all data elements are variables.
> Vbscript does support the use of the Const keyword:
>
> const notchangable="some data"
>
> Since ASP supports multiple languages, it does not support the idea of a
> global constant. Application and Session variables are globally
accessible,
> but they are changable.
>
> So let's concentrate on vbscript Constants are only usable when they are
in
> scope. That means they have to be created every time a page loads. There
are
> three ways to do this:
>
> 1. Include files. The adovbs.inc file located on your hard drive is an
> example of this. There are disadvantages: the include file has to be
> included on each page, and since it probably contains constant delarations
> that will not be used on every page in which it is included, it causes
your
> page size to be larger than necessary.
>
> 2. Classes. You can create read-only properties in vbscript classes.
Again,
> you need to write code on every page to bring the class into scope.
>
> 3. Create a dll with a type library. You can use a metadata tag in
> global.asa to make this type library accessible to all the pages in your
> application. This is the best solution, however, you require a diffferent
> development tool and expertise to use that tool to accomplish this (use
> Google to get details).
>
>
> 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"
>
>