In the previous phase, the author briefly introduces some basic knowledge of VBScript from the ASP scripting language. This issue will continue to explain the script writing method for VBScript, and make everyone through a series of instances of VBScript in the ASP program. There is a more understanding of VBScript.
Everyone learns the variables, constants and processes of scripting language VBScript, which will continue to introduce VBScript functions and syntax to you. The function and process are named code blocks, but they have a big difference, the process completes the program task, and the function returns a value. We can understand this, the process is like a complete sentence, and the function is like a word. For example, when you want to get a square root, you only pass the number to the SQR () function of the VBScript, which will return to the square root of the number. Such as:
A = SQR (9)
Then a = 3. The function of mastering the scripting language will give you a great convenience of writing ASP programs. If you are arranged by the author of the first phase, the author is practicing, if you are not comprehensive enough to master the function of the scripting language, then solve this A small problem will be very likely to spend considerable energy. Let us now take a look at this lesson exercise.
"The author is using the ASP to make a web-based BBS system, hoping to add a special feature, even if any user logs in the BBS, it is possible to consult all newly released information in recent seven days."
If you are not familiar with VBScrip, you won't know that VBScrip itself provides a function DateSerial that acquires the difference between the date, its syntax is as follows:
Dateserial (Year, Month, Day)
If you want to specify a date, for example: November 10, 1998, the value range of each parameter in the DateSerial function should be acceptable, the value of the day should be between 1 and 31, the month value It should be between 1 and 12. However, you can also use the numerical expression that represents the year, month, month, monthly, and daily number of days before a certain day, specifies the relative date for each parameter. A numerical expression is used instead of an absolute date in the following examples. Here, the DateSerial function returned to the date of 20 years (1990-20) for twenty years (1990-20) (11-2) (10-1) for twenty years (11-2) (10-1): That is, 1978. The procedure is as follows:
Datep = DateSerial (1998-20, 11-2, 10-1)
For a Year parameter, if the value range is from 0 to 99, it is interpreted as 1900 to 1999. For the Yearar parameters other than this range, the four digits represent the year (for example, 1800). When the value of any of the parameters exceeds an acceptable range, it will be appropriately carried out to the next larger time unit. For example, if you specify 35 days, the number of days will be interpreted as many days of days in a month, and the number of days from the day depends on its year and month. However, if the parameter value exceeds -32, 768 to 32, 767, or if the date specified by three parameters (whether direct or through expressive specified) is exceeded, an error occurs. When we understand and master the use of the function DateSerial, let's take a look at the title of the author, everything is solved. Below I will publish this part of the program as follows: itemp = dateserial (year (date), month (date), day (date) -7)
Itemp = DateValue (item)
SQL = "Select * from message where message.creatime between #" & Date & "# And #" & itemp & "#" Here we have come into contact with a set of functions Year, Month, Day, they are used to get a date, month ,day. Date is a constant, indicating today, and the function DateValue is a variable that transforms string variables into date format. In the third line of this section, we first touched the standard SQL query statement, what does this statement mean?
"SELECT" is a standard SQL database query command. With the SELECT statement we can retrieve data in the database, and provide the query results to the user, "*" here, "*" indicates all records in the database called "Message". And "where" role is to set a query condition, to take a record in the database, "Message.Creatime" is a variable stored in the database records creation date. Connect the entire sentence to: query all records in the database named Message, and store all records in the variable SQL in today and today. Maybe for everyone to contact the SQL statement, I can't fully understand its role in a time, but don't worry that in the future, the author will specifically use the first phase to introduce SQL usage.
Through the above learning, everyone should have been able to understand the role of the function in the program, of course, we don't have to go back the back function, but you have to use only one shortcut to practice - multi-practice. Let's take a look at the basic syntax of VBScript.
Understanding programming languages must know that the statement of the control program process in the program can primarily be divided into conditional statements and loop statements, and the following conditional statements can be used in VBScript: if ... Then ... Else statement
SELECT CASE statement
If ... Then ... Else statement is used to calculate whether the condition is TRUE or FALSE, and specifies the statement to run based on the calculation result. Typically, conditions are expressions that compare values or variables using comparison operators, if ... Then ... ELSE statement can be nested in need.
Let's create two sample files: if1.asp and if2.asp
Scrapped the following statement to the Notepat and save to if1.asp (Note: Please remove the space after "<")
head>