Simple Getting Started ASP variables

Source: Internet
Author: User
Tags valid

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 each time the subroutine executes.

Instance:

declaring variables

The following are the referenced contents:

<body>

<%

Dim name

Name= "Donald Duck"

Response.Write ("My Name is:" & name)

%>

</body>

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

The following are the referenced contents:

<body>

<%

Dim fname (5), I

fname (0) = "George"

fname (1) = "John"

fname (2) = "Thomas"

fname (3) = "James"

fname (4) = "Adrew"

fname (5) = "Martin"

For i = 0 to 5

Response.Write (FName (i) & "<br/>")

Next

%>

</body>

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

The following are the referenced contents:

<body>

<%

Dim i

For I=1 to 6

Response.Write ("
Next

%>

</body>

How to loop through 6 different HTML headings.

Using Vbscript to make a time based greeting

The following are the referenced contents:

<body>

<%

Dim h

H=hour (now ())

Response.Write ("<p>" & Now ())

Response.Write ("(Beijing time) </p>")

If H<12 Then

Response.Write ("Good morning!")

Else

Response.Write ("Good day!")

End If

%>

</body>

This example displays a different message to the user based on the server time.

Using JavaScript to make a time based greeting

The following are the referenced contents:

<%@ language= "JavaScript"%>

<body>

<%

var d=new Date ()

var h=d.gethours ()

Response.Write ("<p>")

Response.Write (D + "(Beijing time)")

Response.Write ("</p>")

if (h<12)

{

Response.Write ("Good morning!")

}

Else

{

Response.Write ("Good day!")

}

%>

</body>

This example is the same as the grammar.

The lifetime of a variable

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

A variable declared in a subroutine is created and revoked only when the subroutine is executed every time. Scripts outside of a subroutine cannot access and modify the variable.

To declare a variable for use by multiple ASP files, declare the variable as a session variable or a application variable. (www.3lian.com)

Session variable

The session variable is used to store information for a single user and is valid for all pages in an application. The typical data stored in the session is the name, ID, or parameter.

Application variable

The application variable is also valid for all pages in an application. The application variable is used to store information for all users in a particular application.

Related Article

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.