Variables | procedures | functions | scripts | conditions | Statements in the previous issue, the author briefed you on some of the basics of VBScript, one of the ASP scripting languages, and this issue will continue to explain VBScript's scripting methods and show VBScript in the process of writing an ASP program A series of examples gives you a deeper understanding of VBScript.
After learning the basic concepts of variables, constants, and processes in the scripting language VBScript, this issue will continue to introduce you to the functions and syntax of VBScript.
Functions and procedures are named blocks of code, but they are very different, the process completes the program task, and the function returns the value. We can understand that the process is like a complete sentence, while the function is like a word. For example, when you want to get the square root of a number, you simply pass the number to the SQR () function in VBScript, which immediately returns the square root of the number. Such as:
A=SQR (9)
Is a=3. Mastering the scripting language functions will bring you great convenience in writing ASP programs, for the after-school exercises that the authors have assigned to you at the end of the previous issue, if you don't have a complete grasp of the scripting language's functions, solving such a small problem is likely to cost you quite a lot of effort. Now let's review the practice after this lesson.
"The author is using ASP to make a web-based BBS system, in the hope of adding a special feature, that is, when any user login to the BBS will be able to access the nearly seven days of all new information published." ”
If you are unfamiliar with Vbscrip, you will not know that Vbscrip itself provides a function DateSerial to get the difference between dates, and its syntax is as follows:
DateSerial (year, month, day)
If you want to specify a date, for example: November 10, 1998, then the range of values for each parameter in the DateSerial function should be acceptable, and the value of the day should be between 1 and 31, and the value of the month should be between 1 and 12. However, you can also specify a relative date for each parameter by using a numeric expression that represents the number of years, months, or days before or after a day. The following sample uses a numeric expression instead of an absolute date. Here, the DateSerial function returns the date of 20 years (1990-20) 2 months (11-2) and one day (10-1) before November 10, 1998: September 9, 1978. The procedure is as follows:
Datep=dateserial (1998-20, 11-2,10-1)
For the year parameter, if the value range is from 0 to 99, it is interpreted as 1900-1999 years. For year parameters outside of this range, four-digit numbers are used to represent years (for example, 1800). When the value of any one parameter is acceptable, it is appropriately rounded to the next larger time unit. For example, if you specify 35 days, the number of days will be interpreted as a month plus extra days, depending on the year and month. However, an error occurs if the parameter value exceeds the range of 32,768 to 32,767, or if the date specified by three parameters, whether directly or through an expression, is outside the acceptable date range.
When we understand and master the use of function DateSerial, and then look at the author's layout of this problem, everything will be solved. I'll publish this part of the code in the program as follows: Itemp=dateserial (date), month (date), day (date)-7)
Itemp=datevalue (ITEMP)
Sql= "Select * from Message Where message.creatime Between #" &date& "# and #" &itemp& "#"
Here we come to a set of function Year,month,day, which are used to get the year, month, and day of a date. Date is a constant that represents today's date, and function DateValue is a variable that converts a string variable into a date format. In the third line of this procedure, we first contacted the standard SQL query statement, what does this sentence mean?
"Select" is a standard SQL database query command, in which we can retrieve data from the database and provide the results to the user, where "*" means to query all records in the database named "Message", and "where" The function is to set a query condition to take out the qualifying records in the database, "Message.creatime" is a variable that stores the date the record was created in the database. The whole sentence is understood by querying all the records in the database named message, and storing all the records in the variable SQL that were created in today and 7th before today. Perhaps because of the first contact with SQL statements, a time can not fully understand its role, but do not worry in the future chapters of the author will be devoted to the introduction of the use of SQL.
Through the above study, we should have been able to understand the function in the program, of course, we do not have to die back function, but to be proficient in the use of only a shortcut-more practice. Let's look at the basic syntax of VBScript.
Know the programming language friend must know in the program control process flow statements can be divided into conditional statements and circular statements, in VBScript can use the following conditional statement: If ... Then ... Else statement
Select Case Statement
If ... Then ... The Else statement evaluates to whether the condition is True or False and specifies the statement to run based on the result of the calculation. Typically, a condition is an expression that compares a value or variable using a comparison operator, If ... Then ... The Else statement can be nested as needed.
Let's create two sample files: If1.asp and if2.asp
Clip the following statement into a memo book and save it as if1.asp (note: Remove the space after < in the program) < html>
< head>
< title>if1.asp</title>
< form action= "if2.asp" method=get>
Your name< INPUT name= "FirstName" maxlength=20>< p>
Your last name< INPUT name= "LastName" maxlength=20>< p>
< input type=submit>< input type=reset>
</form>
</body>
Clip the following statement into a memo book and save it as if2.asp < html>
< head>
< title>ifrespond.asp</title>
<% fname=request.querystring ("Firstname")
Lname=request.querystring ("Lastname")
If fname= "George" and Lname= "Washington" then%>
Hi.you must be the president!
<% Else%>
Hi! Nice to Meet
<%end if%>
</body>
Asp1.asp produces a text input box that requires the user to enter a last name, a name, and the following figure:
Asp2.asp is to use if statements to determine whether the user entered the name is "George Washington", and make corresponding feedback. Here we encounter an ASP's built-in object request, which allows you to access any information that is delivered with an HTTP request, including parameters, cookies, and user authentication that are passed from the HTML table using the POST method or the Get method. The QueryString collection retrieves the value of the variable in the HTTP query string, which is specified by the value after the question mark (?). Such as:
Http://localhost/if2.asp?Firstname=George&Lastname=Washington
Generates a variable name string with a value of "Firstname=george&lastname=washington". About the ASP object the author will focus on the next few.
If ... Then ... A variant of the ELSE statement allows you to select from multiple conditions, that is, to add a ElseIf clause to augment the If ... Then ... Else statement, so that you can