5.asp script variable, function, process, and conditional statement

xiaoxiao2021-03-06  53

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 "<")

if1.asp </ title></p> <p></ head> <body bgcolor = "# ffffff"></p> <p><form action = "if2.asp" method = get></p> <p>Your first name <input name = "firstname" maxlength = 20> <p></p> <p>Your Last Name <input name = "lastname" maxlength = 20> <p></p> <p><Input Type = Submit> <Input Type = Reset></p> <p></ form></p> <p></ body></p> <p></ html></p> <p>Scrapped the following statement into the Notepad and saved as if2.asp <html></p> <p><HEAD></p> <p><Title> ifrespond.asp </ title> </ head></p> <p><% FNAME = Request.QueryString ("firstname")</p> <p>LName = Request.QueryString ("Lastname")</p> <p>IF fname = "george" and lname = "Washington" THEN%></p> <p>Hi.you Must Be The First President!</p> <p><% ELSE%></p> <p>Hi! Nice to meet you</p> <p><% end if%></p> <p></ body></p> <p></ html></p> <p>Asp1.asp produces a text input box that requires the user to enter the name, name, as shown below:</p> <p>Asp2.asp is to determine whether the name entered by the IF statement is "George Washington" and makes corresponding feedback. Here we encounter an ASP built-in object request, access to any information passed with HTTP requests by using the Request object, including parameters, cookies, and user authentication passed from the HTML table or get method. QueryString set retrieves the value of the variable in the HTTP query string, and the HTTP query string is specified by the value after the question mark (?). Such as:</p> <p>http://localhost/if2.asp? firstname = gerge & Lastname = Washington</p> <p>Generate variable name strings for "firstname = george & lastname = Washington". About ASP objects will focus on the future.</p> <p>A variation of if ... then ... ELSE statement allows you to select from multiple conditions, adding the Elseif clause to expand the functionality of the if ... the ... ELSE statement, so that you can control a variety of Possible procedures.</p> <p>We expand the program part of Asp2.asp as follows: <%</p> <p>FNAME = LCase (Request.QueryString ("firstname")))</p> <p>LName = LCase (Request.QueryString ("LastName"))</p> <p>IF fname = "george" and lname = "Washington" THEN%></p> <p>Hi.you Must Be The First President! <P></p> <p><% elseif fname = "ronald" and lname = "REAGAN" THEN%></p> <p>Hi.you Must Be The Actor President! <P></p> <p><% elseif fname = "jimmy" and lname = "Carter" THEN%></p> <p>Hi.you Must Be The Peanut Farmer President! <P></p> <p><% elseif fname = "naoko" or fname = "charles" THEN%></p> <p>Hi.Your Name Reminds Me of someone, But I am Not Sure Who! <P></p> <p><% ELSE%></p> <p>Hi! Nice to meet you</p> <p><% end if%></p> <p>You can add any plurality of ElseiF clauses to provide a variety of options. But using multiple Elseif clauses often make the program become very cumbersome. A better way to choose in multiple conditions is to use the SELECT CASE statement. The SELECT CASE structure provides a variation in the IF ... The Elseif structure, which can be selected from one of the plurality of statements. The functionality provided by the Select Case statement is similar to if ... the ... Else statement, but the code can be easily read. The SELECT CASE structure uses a simple test expression that only calculates only one time at its start. The results of the expression will be compared to the value of each case in the structure. If you match, execute the statement block associated with this case, we can also write the asp2.asp file with the SELECT CASE statement:</p> <p><%</p> <p>FNAME = LCase (Request.QueryString ("firstname")))</p> <p>LName = LCase (Request.QueryString ("LastName"))</p> <p>Name = fname lname</p> <p>Select Case Name</p> <p>Case "Georgewashington"</p> <p>Response.write "Hi.you Must Be The First President! <P>"</p> <p>Case "Ronaldreagan"</p> <p>Response.write "Hi.you Must Be The Actor President! <P>"</p> <p>Case "JimmyCarter"</p> <p>Response.write "Hi.you Must Be The Peanut Farmer President! <P>"</p> <p>Case "naokocharles"</p> <p>Response.write "Hi.Your Name Reminds Me of someone, But I am Not Sure Who! <P>"</p> <p>Case Else</p> <p>Response.write "hi! nice to meet you"</p> <p>End select%></p> <p>Note that the SELECT CASE structure only calculates an expression at the beginning and only calculates once, and if ... Then ... Elseif structure calculates the expression of each elseiF statement, which can vary. Therefore, the Select Case structure can be used instead of the IF ... The Elseif structure only when each Elseif statement is calculated. SELECT CASE statement is also nested, and each layer is nested, the SELECT CASE statement must have the End SELECT statement that matches it.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-58015.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="58015" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.051</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '7I3O1ysNWqoxhkajlcfAegI7aq6gKodeUfiKvfZwOxh9ZqjGMuqz5eFFbjf7jv1DqH8KLmjL0VasVjve_2FD6bmg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>