I. On Error statements
This statement is used to enable or disable error handlers. The general usage is as follows:
On Error Resume Next
On Error GoTo 0
|
In your codeUnusedOn Error Resume Next statement, the Error message is displayed when an Error occurs, and the code execution ends.
But when you use it, the program will continue to execute the statement after the wrong statement is generated, or follow the last called process (this process contains the On Error Resume Next statement) continue running. This statement can continue to execute the program regardless of running errors. Then, you can establish an error handling routine within the process.
When another process is called, The On Error Resume Next statement becomes inactive. Therefore, if you wantInternal error handling, The On Error Resume Next statement should be executed in each call routine.
If you have enabled the On Error Resume Next Error handler, you can use On Error GoTo 0 to disable the handler.
<Script language = vbs> <br/> On Error Resume Next <br/> Err. Raise 6' causes an overflow Error. <Br/> msgbox ("Error #" & CStr (Err. number) & "& Err. description) <br/> cnbruce.com 'the object is missing because cnbruce is a custom <br/> msgbox ("Error #" & CStr (Err. number) & "& Err. description) <br/> Err.com 'object does not support this attribute or method <br/> msgbox ("Error #" & CStr (Err. number) & "& Err. description) <br/> Err. clear' Clear error. <Br/> </script> <br/>
[Ctrl + A select all for copy prompt: you can modify some code before clicking run]
Note: To generate runtime errors in the code, use the Raise method of the Err Object.
This situation is often seen during program debugging. For example, debugging the following two programs will display.
1, err1.asp
| & Lt; % Err. Raise 6% & gt; |
| Technical Information (for support personnel)
Error Type:
Microsoft VBScript runtime error (0x800A0006)
Overflow |
2, err2.asp
When debugging, that is
| Technical Information (for support personnel)
Error Type:
Microsoft VBScript runtime error (0x800A01A8)
Missing Object: 'cnbruce' |
However, after you add On Error Resume Next in the first line, no Error message is displayed, indicating that internal Error handling is complete.
However, we found that
3, err3.asp
<%
On Error Resume Next
Cnbruce.com
On Error GoTo 0
Cnbruce.com
%> |
When On Error GoTo 0 is used, the Error message is displayed, but the cnbruce.com Error object of the fifth line is not the third line.
Through the above examples, I believe you should have understood this statement. Then let's take a look.
2. Option Explicit statement
This statement is mandatory.Explicit declarationAll variables in the script.
Explicit declaration is to declare all variables using Dim, Private, Public, or ReDim statements. If you try to use an undeclared variable name in the program, an error occurs. You can use this statement to avoid misspelling existing variable names. Use this statement to avoid obfuscation of variables with unclear scope.
Of course, to use Option Explicit, this statement must appear before any other statements in the script.
4, err4.asp
<%
Option Explicit 'forces the display of declared variables.
Dim MyVar 'declares the variable.
MyVar = 10' declare variables without generating errors.
MyInt = 10' an error occurs when no variable is declared.
Response. write (MyInt)
%> |
The error message is as follows:
| Technical Information (for support personnel)
Error Type:
Microsoft VBScript runtime error (0x800A01F4)
Variable undefined: 'myint' |
In addition, ASP provides strong support for VBScript and can seamlessly integrate VBScript functions and methods, which greatly facilitates the expansion of existing ASP functions. Because ASP has blurred the concept of variable types, many programmers are also used to not declare VBScript variables during ASP-VBScript interaction (I am also -_-!, Note later). This increases the server's parsing burden and affects the server's Response Request speed.
In view of this, we can force users to declare variables in VBScript just like forcing users to declare variables in VB. The implementation method is to place <% option explicit %> at the beginning of the ASP program line. Practice has also proved that using "Option Explicit" in ASP files can minimize program error opportunities and greatly improve overall performance.
In addition, the declared variables have a sequence technique, either at compile time or run time. Declared variables are referenced in this order.
Iii. <% @ LANGUAGE = "xxx" CODEPAGE = "936" %>
It is generally divided into <% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %> and <% @ LANGUAGE = "JAVASCRIPT" CODEPAGE = "936" %>.
LANGUAGE = "VBSCRIPT"AndLANGUAGE = "JAVASCRIPT"Declare that the current programming scripts used by ASP are VBSCRIPT and JAVASCRIPT. It is generally stated in the first line of the program. When the script statement is used, all the following programs use all the syntaxes that conform to the script language. The two cannot be used together, otherwise an error occurs. When writing ASP, we generally do not limit it, because different scripts are often written on an ASP page. Of course, this is at the expense of execution efficiency.
CodePage: Readable/writable. Integer. Defines the code page used to display page content in a browser. The code page is the numeric value of the character set. 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. Generally, this method is used when you upload data to a foreign webpage space or extract database records and other garbled characters.
Iv. Absolute Foundation, certain knowledge
Program notes:
In order to develop a good programming style, moderate comments are indispensable. ASP provides two comments
1. Single quotes. This line of text after single quotes is considered as comments.
2. rem keywords. The text after REM is considered as comments.
Assignment Statement:
In ASP, the value assignment statement of a common variable is "="
Objects are assigned values using the set statement.
Arithmetic Operators:
+ Addition
-Subtraction
* Multiplication
/Division
\ Integer Division
Mod Remainder
^ Index
Relational operators:
= Equal
<> Not equal
<Less
> Greater
<= Less than or equal
> = Greater than or equal
IS the comparison variable pointing to the same object?
Logical operators:
1. NOT reverse the logic Value
2. AND "AND" or "AND" operations
3. OR "OR" Operation
4. XOR "exclusive or" operation
5. EPV determines that the two expressions have equal logic and the same result is true. Otherwise, the two expressions are false.
6. IMP checks whether two expressions are logically related.
String Operators
ASP has only one string operator "&", which can force two expressions to connect strings.
Variable Declaration
Note the following when declaring a variable:
1. The valid variable name cannot exceed 255 characters
2. The variable name must start with a letter.
3. The variable name must be unique within the same valid range.
Variable declaration DIM variable name
Constant statement CONST constant name = constant value