ASP variables



Variables are used to store information.


tryitimg.gif

Try it - Example

Declare variables
Variables are used to store information. This example demonstrates how to declare a variable, assign a value to the variable, and use the variable in a program.

Declare arrays
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 titles
This example demonstrates how to loop to generate 6 different HTML titles.

Use Vbscript to make a time-based greeting
This example demonstrates how to display different messages to the user based on the server time.

Use JavaScript to make a time-based greeting
This example is the same as above, demonstrating how to display different messages to the user based on the server time, but with different syntax.


The lifetime of variables

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

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

If you need to declare variables for use by multiple ASP files, please declare the variables as session variables or application variables.

Session variable

Session variable is used to store information for a single user and is valid for all pages in an application. Typical information stored in a Session is name, id, and parameters.

Application Variables

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