Introduction to ASP Programming (12): ASP skills Accumulation (i) _asp Foundation

Source: Internet
Author: User
One, on Error statements
The purpose of this statement is to enable or disable an error handler. The general usage is as follows:


On Error Resume Next
On Error GoTo 0


If you are in your code not usedOn Error Resume Next statement, a run-time error occurs that displays an error message, and the execution of the code terminates.

When you take it, however, the program continues to execute according to the statement following the statement that generated the error or the statement in the procedure that was last called (the procedure contains an on Error Resume Next statement). This statement can continue executing the program regardless of run-time errors, and you can then create an error-handling routine inside the procedure.

The On Error Resume Next statement becomes inactive when another procedure is invoked. So, if you want to do this in a routine Internal error Handling, the on Error Resume Next statement should be executed in each of the invoked routines.

If you have enabled the On Error Resume Next fault handler, you can disable the error handler using On Error GoTo 0.

<textarea class="bk" id="temp29072" rows="12"><script language=vbs> On Error Resume Next err.raise 6 ' generates an overflow error. MsgBox ("Error #" & CStr (Err.Number) & "& Err.Description) cnbruce.com ' missing objects because Cnbruce is a custom MsgBox (" Error # "& CStr (Err.Number) &" "& Err.Description) err.com ' object does not support this property or method MsgBox (" Error # "& CStr (Err.Number ) & "& Err.Description) Err.Clear ' clears the error. </script></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

Note: To generate a run-time error in your code, use the Raise method of the Err object.
This situation is often seen in the debugger, such as debugging the following two programs will show.

1,err1.asp

<%err.raise 6%>


Technical information (for support staff)

Error type:
Microsoft VBScript run-time Error (0x800a0006)
Overflow


2,err2.asp

<%cnbruce.com%>

When it comes to debugging,

Technical information (for support staff)

Error type:
Microsoft VBScript run-time Error (0X800A01A8)
Missing object: ' Cnbruce '


However, when you add On Error Resume next in the first line, you find no error prompts, indicating that internal error processing is complete.

But the following procedures were found
3,err3.asp

<%
On Error Resume Next
Cnbruce.com
On Error GoTo 0
Cnbruce.com
%>

Using the On Error GoTo 0, the error message is displayed, except that it is not the third line, but the cnbruce.com Error object in line fifth.

With the above examples, I believe you should have some understanding of this statement. Then look again.

Two, Option Explicit statement
The purpose of this statement is to force the requirement an explicit declarationAll variables in the script.

The so-called explicit declaration is to declare all variables using Dim, Private, public, or REDIM statements. If you try to use an undeclared variable name in your program, an error occurs. Use this statement to avoid misspelled variable names that already exist. Using this statement can also avoid confusion for variables that are not scoped.

Of course, if you want to use Option Explicit, the statement must appear before any other statements in the script.
4,err4.asp

<%
Option Explicit ' forces a declaration variable to be displayed.
Dim MyVar ' declares a variable.
MyVar = 10 ' Declaring a variable does not produce an error.
MyInt = 10 ' does not declare a variable to produce an error.
Response.Write (MYINT)
%>

The error message is as follows:

Technical information (for support staff)

Error type:
Microsoft VBScript run-time Error (0X800A01F4)
Variable not defined: ' MyInt '


Plus: The ASP provides strong support for VBScript, seamless integration of VBScript functions, methods, which extend the existing functionality of the ASP is greatly facilitated. Since the concept of variable types has been blurred in ASP, many programmers are wont to declare VBScript variables (I am also-_-!, later) in the process of interacting ASP and VBScript, thus aggravating the server's resolution burden, thus affecting the server's response request speed.

For this reason, we can force a user to declare a variable in VBScript just as a variable declaration is enforced in VB. The implementation method is to place <% option explicit%> at the beginning of the ASP program. The practice also proves that using "Option Explicit" in ASP files can minimize the chance of program error and greatly improve overall performance.

In addition, the declared variables have a sequential trick, either at compile time or at run time. The declared variables are referenced in this order.

third, <% @LANGUAGE = "xxx" codepage= "936"%>

Generally divided into <% @LANGUAGE = "VBSCRIPT" codepage= "936"%> and <% @LANGUAGE = "JAVASCRIPT" codepage= "936"%> two kinds.

language= "VBSCRIPT"And language= "JAVASCRIPT", stating that the programming scripts currently used by ASP are VBScript and JavaScript, respectively. It is generally stated in the first line of the procedure. When the script is declared, all of the following programs use all the syntax that conforms to the scripting language, which cannot be confused or error. When we write ASP, we generally do not qualify, because we often write different scripts on an ASP page, of course, at the expense of execution efficiency.

CodePage: Readable/writable. Integral type. Defines the code page that is used to display the content of a page in a browser. The code page is the numeric value of the character set, and different languages use different code pages. For example, the ANSI code page is 1252, the Japanese code page is 932, and the Simplified Chinese code page is 936. Under normal circumstances, when you upload a foreign web page space, or extract the database records and other garbled, this method is used to solve.

Four, the absolute Foundation, must grasp

Program Comment:

In order to develop a good programming style, a modest annotation is necessary, the ASP provides two ways to annotate
1, single quotation marks, after the single quotation mark this line of text is considered as a comment
2, REM keywords, in rem after the text, as a comment

Assignment statement:

The assignment statement of general variables in ASP is "="
And the object is assigned with the SET statement.

Arithmetic operators:

+ Addition
-Subtraction
* Multiplication
/Division
\ integer Division
Mod remainder
^ Index

Relational operators:

= equals
<> Not equal to
< less than
> Greater than
<= less than or equal
>= is greater than or equal to
Is comparison variable pointing to the same object

logical operators:

1, not to reverse the logical value
2, and "and" or "and" operations.
3, or "or" operation
4, XOR "exclusive or" operation
5, EPV judge two expression logic equal, the same result is true, otherwise false
6. IMP determines whether two expressions are logically related.

string Operators

ASP has only one string operator, "&", which can force two expressions to do string concatenation

Variable Declaration

Variable declarations must be noted:
1. A valid variable name cannot be greater than 255 characters
2. The variable name must begin with a letter
3. The variable name must be unique within the same valid range

Variable declaration DIM variable name
Constant declaration CONST Constant name = constant value

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.