Through the study of the first two articles, I believe that you have already gained a basic concept and overall impression of ASP's dynamic website design. Starting from this article, the author will start with the use of scripting languages and lead everyone to explore the true mysteries of ASP dynamic website design from shallow to deep.
After the second article of this article was published, many friends sent me a girl, hoping to see the third, fourth, and even the first chapter of this article as soon as possible. Some friends even asked me to post the full text of the ASP article. Give it to him. Seeing so many like-minded friends has greatly boosted my spirits. Although ASP was launched two years ago, it was not until this year that it has received attention from Chinese people for its flexible and convenient development process and good WEB database connection function. However, due to the lack of ASP's development of WEB applications in China, it is still lacking in China. Detailed textbooks have made the majority of WEB developers in China still in the stage of judging E-texts behind closed doors, including the author himself. It is precisely because of this that the author was inspired to write an article. After receiving the strong support of Mr. Weng Bin from Chinabyte Network Academy, you were able to see this article.
The author sincerely hopes to provide convenience for WEB developers and enthusiasts through this article, so that everyone can participate in ASP learning and communication. In order to take into account the needs of readers at different levels, the author decided to start with the most basic scripting language preparation, and then We will explain ASP built-in objects, ActiveX components, and examples of using ASP to develop WEB applications step by step. I believe that through a period of continuous learning, you will be able to develop your own dynamic website in less than a few months. Let me first learn some basic knowledge of applying scripting languages (mainly VBScript) in ASP.
Before you start learning scripting languages, you should understand some simple concepts - variables, processes. The so-called variable is a named storage location in computer memory, which contains data such as numbers or strings. It makes it easy for users to understand the name of script operations and provides users with a way to store, retrieve and operate data. A program is composed of one or more processes. In VBScript, a process is an instruction block. A process in the usual sense, such as Sub, is just for simple data processing.
In VBScript, strictly speaking, variables do not need to be declared.
For example: < % Mystring=This is my string % >
However, even if you do not need to declare variables before using them, you should develop a good habit of declaring variables when programming, as this helps prevent errors. Declaring a variable means telling the script engine that there is a variable with a specific name so that the variable can be referenced in the script. Declaring a variable in VBScript can use the Dim statement, as follows:
< script language=VBScript >
< !--
Option Explicit ' requires that all variables be declared in the script
Dim Mystring
Mystring=This is my string
-->
< /script>
The scope of a variable is the life period, which determines which script commands can access the variables. Variables declared inside the process have local scope. Each time the process is executed, the variable is created and then died. And no command outside the process can access it. Variables declared outside the process have a global scope and their values can be accessed and modified by any script command on the ASP page. When declaring a variable, local variables and global variables can have the same name. Changing one of the values does not change the other. If a variable is not declared, it may accidentally change the value of a global variable. For example, the following script command returns a value of 1, although there are two variables named Y:
< %
Dim YY = 1Call SetLocalVariableResponse.Write Y
Sub SetLocalVariable
Dim Y
Y = 2End Sub % >
Since the variable is not explicitly declared, the following script command will return 2. When the procedure call sets Y to 2, the script engine considers that the procedure is to modify the global variable:
<%
Y = 1Call SetLocalVariableResponse.Write Y
Sub SetLocalVariable
Y = 2
End Sub% >
However, global variables are only available in a single ASP page, and to make it available outside of a single ASP page, you must assign a session or application scope to the variable. Session scope variables are available for all pages in the ASP application requested by a user. The same is true for application scope variables. For a single user, session variables are the best way to store information, such as user preferences, usernames, or user identification. For all users of a special application, application scope is the best way to store information, such as application-specific greetings or initial values required by the application. ASP provides two built-in objects to let you store variables: Session object and Application object, which will be discussed in future ASP built-in objects.
Let's look at the definition of a constant, which is used instead of a number or string name, and remains unchanged throughout the script. You can use the Const statement to create user-defined constants in VBScript. Use the Const statement to create string or numeric constants with certain meanings and assign them original values. For example:.
For example: < % Const mystring= This is a constant% >
< % Const myage=100 % >
Note that the string literal is contained between two quotes ( ). This is the most obvious way to distinguish between string-type constants and numerical constants. Date text and time text are contained between two pound signs (#). For example:
< % Const CutoffDate = #6-1-97# % >
After understanding constants and variables, let's take a look at what a process is. It is a set of script commands that can execute specified tasks and have return values. You can define your own procedures and then call them repeatedly in the script. You can place the process definition in the .asp file that calls the process, or you can place the general procedure in a shared .asp file and include it in the other .asp file that calls its procedures with the SSI #include directive. You can also choose another way to package these features in ActiveX components. Process definitions can appear inside the <SCRIPT> and <SCRIPT> tags and must follow the rules that declare scripting language. If the language used by the procedure is different from the main scripting language, use the <SCRIPT> element. Procedures in the main scripting language are separated by script delimiters (< % and % >). When tagging with HTML<SCRIPT>, two properties must be used to ensure that the server side can handle scripts. The syntax of using <SCRIPT> tag is as follows:
< SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT >
procedure definition
< /SCRIPT >
The RUNAT=SERVER property here notifies the web server to process scripts on the server. If this property is not set, the script will be processed by the client browser. The LANGUAGE property determines the script language used by this script block. You can specify any language with a scripting engine. Please use VBSCRIPT to specify VBScript; use JSCRIPT to specify JScript. If the LANGUAGE property is not set, the script block will be interpreted in the main script language.
In VBScript, processes are divided into two categories: Sub process and Function process. A Sub procedure is a set of VBScript statements contained between Sub and End Sub statements, performing operations but not returning values. Sub procedure can use parameters (constants, variables, or expressions passed by the calling procedure). If the Sub procedure does not have any parameters, the Sub statement must contain empty brackets().
The Function procedure is a set of VBScript statements that are included between the Function and End Function statements. The Function process is similar to the Sub process, but the Function process can return values. Function procedures can use parameters (constants, variables, or expressions passed by the calling procedure). If the Function procedure has no parameters, the Function statement must contain empty brackets(). Function The process returns a value through the function name, which is assigned to the function name in the statement of the process. Function The data type of the return value is always Variant. In the following example, the Sub procedure uses two inherent (or built-in) VBScript functions, namely MsgBox and InputBox, to prompt the user for information. The results calculated based on this information are then displayed. Calculation is done by the Function process created using VBScript, and the Celsius function converts Fahrenheit to Celsius. Sub procedure ConvertTemp When this function is called, a variable containing the parameter value is passed to the function. The conversion result is returned to the calling process and displayed in the message box.
Sub ConvertTemp()
temp = InputBox(Please enter Fahrenheit temperature., 1)
MsgBox The temperature is & Celsius(temp) & degrees Celsius.
End Sub
Function Celsius(fDegrees)
Celsius = (fDegrees - 32) *
5 / 9
End Function
The way to pass data to the process is to use parameters. The parameter is used as a placeholder for the data to be passed to the process. The parameter name can be any valid variable name. When creating a process using a Sub statement or a Function statement, the process name must be followed by brackets. All parameters are included in brackets, separated by commas. For example, in the following example, fDegrees is a placeholder for the value passed to the Celsius function:
Function Celsius(fDegrees)
Celsius = (fDegrees - 32) * 5 / 9
End Function
To get data from a process, the Function procedure must be used. Remember that the Function process can return values; the Sub process does not return values.
The above briefly introduces VBScript to you. Due to the length, the author cannot introduce all the knowledge of VBScript here in detail. However, since ASP itself is not a programming language, in the process of writing ASP applications, we must use scripting language to implement many special functions. Therefore, we can flexibly master scripting language to write WEB applications using ASP It is crucial for the staff. Whether you are a master with extensive programming experience or a beginner, as long as you now want to write WEB applications through ASP, the author strongly recommends that you master at least one scripting language (such as VBScript). At the end of this article, the author will leave a post-class assignment for everyone. I hope you can learn about the relevant books by yourself and quickly master the script language in practice.
After-school assignments:
The author is using ASP to create a WEB-based BBS system. The author hopes to add a special feature to it, that is, when any user logs into the BBS, he can access all newly released information in the past seven days. Since the built-in objects and components of ASP itself do not provide this function, the author asks you to start with VBScript to design such a function. If you have any questions, please ask the EMAIL author, and the answer will be announced in the next article. stay tuned.