当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP > ASP 变量

ASP
ASP Drive
ASP File
ASP Folder
ASP Dictionary
ASP ADO
ASP AdRotator
ASP BrowserCap
ASP Content Linking
ASP Content Rotator
ASP Quick Ref
ASP 摘要
ASP 实例

ASP 变量


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 910 ::
收藏到网摘: n/a

A variable is used to store information.
变量是用来存储需要的信息的

If the variable is declared outside a procedure it can be changed by any script in the ASP file. If the variable is declared inside a procedure, it is created and destroyed every time the procedure is executed.
如果你是在一个子程序(比如:VBScript中的sub,function)的外部声明变量的话,那么ASP文件里的所有脚本程序都可以对这个变量的值进行修改;如果你是在一个子程序的内部声明变量的话,那么,每次当这个子程序被执行的时候,这个变量的值都会随之建立或取消。


 

Examples
实例

Declare a variable
声明一个变量
Variables are used to store information. This example demonstrates how to declare a variable, assign a value to it, and use the value in a text.
变量是用来存储信息的。下面的例子告诉我们如何声明一个变量,并给它赋一个值,以及如何在一个文本当中使用这些变量的值。

Declare an array
声明一个数组
Arrays are used to store a series of related data items. This example demonstrates how to declare an array that stores names.
数组变量是存储一系列相关联的数据项的(可以说,这些数据项都常是有内在联系的)。下面的例子将告诉我们如何声明一个数组变量并且存储姓名。

Loop through the HTML headers
循环显示HTML的字号
How to loop through the six headers in HTML.
如何循环显示HTML的六种字号。

Time-based greeting using VBScript
在不同的时间段内显示不同的问候语的“VBScript”脚本程序
This example will display a different message to the user depending on the time on the server.
这个案例将展示给我们的是,脚本程序将根据服务器上不同的时间段显示不同的问候语。

Time-based greeting using JavaScript
在不同的时间段内显示不同的问候语的“JavaScript”脚本程序
This example is the same as the one above, but the syntax is different.
这个上面的案例差不多,只不过语法上略有不同。


Lifetime of Variables 变量存在的生命周期

A variable declared outside a procedure can be accessed and changed by any script in the ASP file.
如果你是在一个子程序之外去声明变量的值,那么它的值可以被ASP文件中的所有脚本程序存取和改变。

A variable declared inside a procedure is created and destroyed every time the procedure is executed. No scripts outside the procedure can access or change the variable.
如果你是在一个子程序的内部声明变量的话,那么,每次当这个子程序被执行的时候,这个变量的值都会随之建立或取消;而在这个子程序之外的脚本程序则不能存取或改变这个变量的值。

To declare variables accessible to more than one ASP file, declare them as session variables or application variables.
如果你想让声明的变量被多个ASP文件调用,那么你必须以Session变量或是Application变量的形式去声明这些变量的值。

Session Variables
Session变量

Session variables are used to store information about ONE single user, and are available to all pages in one application. Typically information stored in session variables are name, id, and preferences.
Session变量是用来存储一个单一用户的信息的,同一个应用程序所包含的所有页面都可以访问到它。我们经常在Session变量中存储姓名、id号以及喜好等常用信息。

Application Variables
Application变量

Application variables are also available to all pages in one application. Application variables are used to store information about ALL users in a specific application.
同样的,Application变量可以被同一个应用程序中所包含的所有页面访问到。Application变量通常被用来存储在特定请求下的所有用户的信息资料。

评论 (0) All

登陆 | 还没注册?