Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a variable static (or "global") in Classic ASP?

I want to make my variable static or "global" - so the same effect as static in .NET; every session that accesses it gets the same result, and if one session modifies it it affects everyone else too.

How can I achieve this in Classic ASP?

like image 908
joshcomley Avatar asked May 26 '09 09:05

joshcomley


People also ask

How do you make a global variable static?

To declare a static variable, we have to use the keyword static while in case of global variable, if the variable is declared outside the main function without any special keyword, the compiler interprets it as a global variable.

Can a variable be global and static?

A static variable can be either a global or local variable. Both are created by preceding the variable declaration with the keyword static. A local static variable is a variable that can maintain its value from one function call to another and it will exist until the program ends.

How do I declare a global variable in C#?

However, you can make a global variable by creating a static class in a separate class file in your application. First, create a class called global in your application with the code given below. The class also has a static variable. Now, you can access it from anywhere in your forms after assigning a value to it.


1 Answers

If you want to have a variable that is accessible application wide, you can use the application object. Be sure to use Application.Lock/Unlock to prevent any problems.

Application.Lock
Application("MyVariable") = "SomeValue"
Application.Unlock
like image 175
Jose Basilio Avatar answered Sep 19 '22 00:09

Jose Basilio