Variables | tutorials
Variables are used to store information.
If you declare a variable outside of a subroutine, the variable can be changed by any script in the ASP file. If you declare a variable in a subroutine, it is created and revoked every time the subroutine executes
Instance:
-
-
declaring variables
-
-
variables are used to store information. This example shows how to declare a variable, assign a value to a variable, and use that variable in a program
-
-
-
-
Declaring an array
-
-
arrays are used to store a series of related data items. This example shows how to declare an array that stores names.
-
-
-
-
Looping to generate HTML headers
-
-
how to loop through 6 different HTML headings.
-
-
-
-
Using VBScript to make a time based greeting
-
-
This example displays a different message to the user based on the server time.
-
-
-
-
Using JavaScript to make a time based greeting
-
-
This example is the same as the grammar.
-
-
<%@ language= "JavaScript"%>
<body>
<%
var d=new Date()
var h=d.getHours()
Response.Write("<p>")
Response.Write(d + " (Norwegian Time)")
Response.Write("</p>")
if (h<12)
{
Response.Write("Good Morning!")
}
else
{
Response.Write("Good day!")
}
%>
</body>
变量的生存期
在子程序外声明的便利可被ASP文件中的任何脚本访问和修改。
在子程序中声明的变量只有当子程序每次执行时才会被创建和撤销。子程序外的脚本无法访问和修改该变量。
如需声明用于超过一个ASP文件使用的变量,请将变量声明为session变量或者application变量。
Session变量
Session变量变量用于存储单一用户的信息,并且对一个application中的所有页面均有效。存储于session中的典型数据是名称、id或参数。
Application变量
Application变量同样对一个application中的所有页面均有效。Application变量用于存储一个特定的application中所有用户的信息。