In the previous article, the editor briefly introduced some basic common sense of VBScript, one of the ASP scripting languages. This issue will continue to explain to you the script writing method of VBScript, and by showing a series of examples of VBScript in the ASP program writing process, we will give you a better understanding of VBScript.
Functions are named blocks of code like procedures, but they are very different. When the process completes the program task, the function returns the value. We can understand this way 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 certain number, you just pass the number to the Sqr() function in VBScript, and this function will immediately return the square root of the number. like:
A=sqr(9)
Then A=3. Proficient in the functions of scripting language will bring you great convenience to writing ASP programs. As for the after-class exercises assigned by the author at the end of the previous issue, if you do not have a comprehensive understanding of the functions of scripting languages, then solving such a small problem will likely cost you a lot of energy. Now let's review this after-class exercise.
“The author is using ASP to create a WEB-based BBS system, hoping to add a special feature to it, that is, when any user logs into the BBS, he will be able to access all newly released information in the past seven days.”
If you are not familiar with VBScript, you will not know that VBScript itself provides a function DateSerial to obtain the difference or sum between dates. Its syntax is as follows:
DateSerial(year, month, day)
If you want to specify a date, for example: November 10, 1998, the range of values for each parameter in the DateSerial function should be acceptable, that is, the value of day should be between 1 and 31, and the value of month should be between 1 and 12. However, a relative date can also be specified for each parameter using a numerical expression representing the number of years, months, and days before or after a certain day. The following example uses numeric expressions instead of absolute dates. Here, the DateSerial function returns the date of twenty years (1990-20) and two months (11-2) and another 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 to 1999. For year parameters outside this range, four digits are used to represent the year (for example, 1800). When the value of any parameter exceeds the acceptable range, it will be properly carried to the next larger unit of time. For example, if 35 days are specified, the number of days will be interpreted as one month plus the number of extra days, which depends on its year and month. But an error occurs if the parameter value exceeds the range of -32,768 to 32,767, or if the date specified by three parameters (either directly or through an expression) is beyond an acceptable date range. After we understand and master the use of the function DateSerial, let’s take a look at the question assigned by the author and everything will be solved. Below I will publish this part of the code in the program as follows: