Examples explain in detail the ASP tutorial method of using Variables in ASP

Source: Internet
Author: User
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中所有用户的信息。



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.