ASP Variables

Variables are used to store information.

If a variable is declared outside a subroutine, then any script within the ASP file can change this variable. If a variable is declared within a subroutine, then it will be created and destroyed each time the subroutine is executed.

Example:

Declare variable
Variables are used to store information. This example demonstrates how to declare a variable, assign a value to it, and use this variable in the program
Declare array
Arrays are used to store a series of related data items. This example demonstrates how to declare an array to store names.
Loop to generate HTML headings
How to loop to generate 6 different HTML headings
Use Vbscript to create time-based greetings
This example will display different messages to the user based on the server time.
Use JavaScript to create time-based greetings
This example is the same as the previous one, but with different syntax.

Variable lifetime

Variables declared outside a subroutine can be accessed and modified by any script within the ASP file.

Variables declared within a subroutine are only created and destroyed when the subroutine is executed each time. Scripts outside the subroutine cannot access or modify this variable.

To declare variables that can be used by multiple ASP files, declare the variables as session variables or application variables.

Session variable

Session variables are used to store information for a single user and are valid for all pages within an application. Typical data stored in a session includes name, id, or parameters.

Application variables

Application variables are also valid for all pages in an application. Application variables are used to store information for all users in a specific application.