6.asp scripting cycle statement

xiaoxiao2021-03-06  41

In this article, we learned the variables, functions, procedures, and conditional statements of scripting language VBScript, which will continue to introduce you to the cyclic statement of VBSCIPT and summarize the application in ASP in the scripting language. If someone tells you that the ASP does not require any programming knowledge, then he is wrong; if I tell you to learn the ASP must master a programming language, then I am wrong. The ASP Dynamic Server page environment is that it is written by one or several script languages. The scripting language can be regarded as a simplified version of the programming language. It is easy to learn and master, which gives the designers for the majority of dynamic websites. It provides considerable convenience. It can be said that the code is directly related to the excellent and inferior of the ASP application. Following the previous article After learning the function and condition statement of scripting language VBScript, we will continue to see the loop statement in VBScript.

The role of the loop statement is to repeat the program code, and the loop can be divided into three categories: a class repeatedly execute the statement before the condition becomes "false", and a class repeatedly performs the statement before the condition becomes "true", and the other is specified according to the specified The number of times is repeatedly executed. The following cyclic statements can be used in VBScript:

DO ... loop: When the (or until) is "true" time cycle.

While ... Wend: When the condition is "true" time, it is cycled.

For ... next: Specify the number of loops, use the counter to repeat the statement.

For Each ... Next: Repeat a group of statements for each element in each of the collections. Let's take a look at Do ... loop, which can be used multiple times (no number). Repeat the executive block before the condition is "true" or the condition becomes "true". Please see the case:

DOLOOP.ASP </ Title> <body bgcolor = "# fffff"> </ head> <p> </ p></p> <p><p> Please fill in this year's sales settlement record this year to this month. <P></p> <p><%</p> <p>COUNTER = 1</p> <p>thismonth = month (now ())</p> <p>Do While Counter <thismonth 1</p> <p>Response.write "& Counter &" Month: "</p> <p>response.write "______________________________" & "<BR> <br>"</p> <p>IF counter> 13 THEN</p> <p>Exit do</p> <p>END IF</p> <p>Counter = Counter 1</p> <p>Loop</p> <p>%></p> <p><hr> </ body> </ html></p> <p>This ASP program uses a loop statement to make a sales settlement record, save the above code to Doloop.asp to the Notepad, and browse in HTTP in the browser, depending on the current month, you will look To the results below.</p> <p>Let's analyze this program, our purpose is to print a table according to the current month, first we build a counter "count" and set it to 1, then we use the function MONTH () and now () to get The current month, finally establishing a loop, when the value of count is less than the value of the current month, that is, the month value and a horizontal line are displayed and the value of count is added, the cycle statement is repeated until the above condition is time to exit the cycle . This is now exited by Exit DO if count is greater than 13. The Do Loop statement can also use the following syntax:</p> <p>DO</p> <p>[statements] [EXIT DO]</p> <p>[statements] loop [{while | until} Condition]</p> <p>While ... Wend statement is provided for users who are familiar with their usage. However, because of while ... Wend lacks flexibility, it is recommended to use the DO ... Loop statement. Let's take a look at the for next statement. The for ... NEXT statement is used to run the specified number of statements, and the counter variables are used in the loop, which increases or decreases each cycle.</p> <p>The following example repeats the process MyProc executing 50 times. The FOR statement specifies the counter variable x and its starting value and the termination value. The NEXT statement makes the counter variable plus 1. Sub DomyProc50Times ()</p> <p>DIM X</p> <p>For x = 1 to 50</p> <p>MyProc</p> <p>NEXT</p> <p>End Sub</p> <p>Keyword Step is used to specify a value of the counter variable to increase or decrease each time. In the example below, the counter variable j plus 2 each time. After the end of the cycle, the value of Total is 2, 4, 6, 8, and 10. Sub twostotal ()</p> <p>DIM J, TOTAL</p> <p>For j = 2 to 10 step 2</p> <p>Total = Total J</p> <p>NEXT</p> <p>Msgbox "sum is" & Total & "."</p> <p>End Sub</p> <p>To make the counter variable, set STEP to a negative value. At this time, the termination value of the counter variable must be less than the start value. In the example below, the counter variable mYnum minus 2. After the end of the cycle, the value of Total is 16, 14, 12, 10, 8, 6, 4, and 2. Sub newtotal ()</p> <p>Dim MyNum, Total</p> <p>For mynum = 16 to 2 step -2</p> <p>Total = TOTAL MYNUM</p> <p>NEXT</p> <p>Msgbox "sum is" & Total & "."</p> <p>End Sub</p> <p>The exit for statement is used to exit the for ... next statement before the counter reaches its termination value. Because usually just in some special cases (for example, when an error occurs), you can use the EXIT for statement in the TRUE statement of if ... the ... ELSE statement. If the condition is False, the loop will run as usual.</p> <p>Finally, let's take a look at the for Each ... Next statement, the For Each ... Next cycle is similar to for ... next loop. For Each ... next is not the number of times the statement is specified, but repeats a group of statements for each element in an array or a collection of objects. This is very useful when you don't know the number of elements in the collection. Its syntax is as follows: for Each Element in Group</p> <p>[statements]</p> <p>[EXIT for]</p> <p>[statements] Next [ELEMENT]</p> <p>If there is at least one element in Group, it will enter the for Each block. Once entering the loop, you first perform all the statements in the cycle on the first element in Group. As long as there are other elements in Group, the statement in the loop will be performed. When there is no other elements in the group, you exit the loop and then proceed from the statement after the next statement. At this point, we have completed the learning of all basic knowledge of scripting language Vbscript, but only by reading existing articles You cannot skilled VBScript, you must improve your level through constant practice. Of course, if you are familiar with C, you can also choose JavaScript as a scripting language for the ASP application. I don't know if you have discovered the debugging of the ASP program, because there is no ready-made tool, here I briefly introduce Microsoft Script debugger, we can use it to make a certain amount of program debugging work.</p> <p>The Microsoft Script Debugger (Script Defractory Tool) included in IIS4.0, provides the scriptor's detection. You can use the Microsoft Script Default Tool to perform scripts that use VBScript, JScript, and Java Applets, Beans, and ActiveX components.</p> <p>Some scripts are executed in the user-end browser, and some scripts (part of the part in <% ...) are executed on the server side. Microsoft Script Debugger, you can detect scripts executed by the user and the server-side execution script. The script executed in the User-end browser is performed in the user-end browser, including VBScript, JScript part in the standard HTML code. This includes the HTML code that includes the script program when the browser loads this HTML code or, for example, press the button to trigger the event. The script executed by the User-end browser is primarily used to function on the basic inspection of the HTML form input.</p> <p>The script executed on the server side is executed in the IIS server, including in the .asp program. First execute on the IIS server, execute the results generate standard HTML code, and then transfer to the user browser. The script executed by the server side is mainly used for the link between multiple web pages, the HTML form input, and the information on the database on the server, etc.</p> <p>Microsoft Script Debugger provides the following unlocated features:</p> <p>1, set interrupt point</p> <p>2, step by step tracking the script.</p> <p>3, set the bookmark.</p> <p>4, see the call stack.</p> <p>5, review and change the variable value.</p> <p>6. Execute script instructions.</p> <p>From the next article, we will begin to learn the built-in object of ASP, so stay tuned.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-58017.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="58017" 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.071</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 = 'CCAu_2FcZCjNLVr1oGSTfsOFM3H4hD7244zKsNm5Jo_2BRgn3hv_2FTvxYcGm_2Fw3IE_2FifdDj7R1VAQCI34HTNFsAO8mQ_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>