ASP: The Beginning - Variables
(Page 2 of 4 )
The easiest way to think of a variable is with your brain. The second easiest way is to think of them as a box that contains a piece of data. You can take the data out and replace it with another piece of information, or you can leave it empty and store something in it later (or never), or if you are obsessive compulsive you can take things out and put them back in over and over again. Or if you are poor like me you can use the box as a chair. Get a tall enough dog to stand behind you and you've got yourself a recliner.
Unlike a box, variables also have a lifetime. I know, it's sad, but we all have to cross over that dark divide. The lifetime (or scope) of a variable depends upon where you declare it. If you declare the variable outside of a procedure (we will discuss these later on), then the variable lives as long as the file does, and can be called by any script in the ASP file. If you declare the variable inside of a procedure however, it is destroyed every time the procedure is executed, and cannot be accessed by any other script in the file.
If you wish to create variables that are available to every page on your website (and not just the ASP file in which you created them), you can either use a session variable or an application variable.
Session variables store information about a single user. They can be used by any page on your website and typically store data such as the user's name, browser type, and any preferences they may have.
Application variables store data about every user relevant to the application and are available to every page on your site.
Next: Working with Variables >>
More ASP Code Articles
More By James Payne