Static Variables

Static Variables

am 21.03.2005 07:13:30 von 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

Re: Static Variables

am 21.03.2005 10:56:26 von exjxw.hannivoort

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)

Re: Static Variables

am 21.03.2005 13:07:42 von harish

Thanks for your quick help

Harish


"Evertjan." wrote in message
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)
>

Re: Static Variables

am 21.03.2005 13:16:18 von reb01501

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"

Re: Static Variables

am 21.03.2005 13:31:26 von harish

Thanks for your explanation.


"Bob Barrows [MVP]" wrote in message
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"
>
>