ASP Tutorial: ASP script loop

Posted by admin 0 comments

We studied the VBScript scripting language variables, functions, procedures and conditions statement, this will continue to tell you VBScipt the loop, and the scripting language in ASP application to be concluded.

If someone tells you to learn ASP does not require any programming knowledge, then he is wrong; if I told you to learn ASP must master a programming language, so I was wrong. ASP Active Server Pages environment features is that it is through one or several scripts written language, scripting language can be seen as a simplified version of the programming language that is easy to learn and master, which to the vast dynamic website designer to provide considerable convenience. You could say: use a scripting language is directly related to the ASP application’s superiority and inferiority. Following the one we have studied the scripting language VBScript functions and conditional statements, they are now we continue to look at VBScript in the loop.

The role of loop is the repeat procedure code cycle can be divided into three categories: one in the condition to “false” statement before the repeat, the conditions for a class to “real” repeat the statement before, and the other in accordance with the designated the number of repeat statements. VBScript can be used in the following loop:

Do … Loop: while (or until) the conditions for the “true” when the cycle.

While … Wend: When the condition is “true” when the cycle.

For … Next: the specified number of cycles, use run counter to repeat statements.

For Each … Next: For each collection or array each element, repeat a statement.

Let’s take a look at Do … Loop, it is many times (frequency variable) to run block. When the condition is “true” or when conditions become “true” before the repeat block. See the following example: <html> <head>

<Title> DoLoop.asp </ title> <body bgcolor = “# FFFFFF”> </ head> <p> </ p>
 
<P> Please send this month so far this year sales for each month on billing records to fill in this page. <P>

<%
counter = 1
thismonth = month (now ())
Do while counter <thismonth + 1
response.write “” & counter & “Month:”
response.write “______________________________” & “<BR> <br>”
If counter> 13 then
exit do
end if
counter = counter +1
Loop
%>
<Hr> </ body> </ html>
 
This ASP program using loop produced a settlement of log sales, cut and paste the code above to save the notebook DoLoop.asp, and HTTP in the browser to navigate approach.
Let’s analyze this section procedures, our aim is to print a month based on current form, we first establish a counter “count” and its value set to 1, then we use the function month () and now () be the current month, the last build cycle, when the count value is less than the value of the current month plus one time, that shows the month and count value and the value of a horizontal line by 1, the above loop repeats until the exit condition is false cycle. If the count is greater than 13 of them with exit do loop exit immediately.

Do Loop statement can also use the following syntax:

Do
[Statements] [Exit Do]
[Statements] Loop [(While | Until) condition]
 
While … Wend statement is for those who are familiar with its use of user-supplied. However, due to the lack of flexibility in While … Wend, it would be best to use Do … Loop statement. Let us look For Next statement. For … Next statement is used to run the specified number of times a statement block, use the counter variable in the loop, the variable’s value with the increase or decrease in each cycle.

The following example will repeat the process MyProc 50. For statement specifies the counter variable x and its initial value and termination value. Next statement to add a counter variable each time. Sub DoMyProc50Times ()

Dim x
For x = 1 To 50
MyProc
Next
End Sub

Step counter variable keyword used to specify the value of each increase or decrease. In the following example, each time the counter variable j + 2. After cycling, total value of 2,4,6,8, and 10 combined.

Sub TwosTotal ()
Dim j, total
For j = 2 To 10 Step 2
total = total + j
Next
MsgBox “Total is” & total & “.”
End Sub
 
For counter variable decrease, negative values can be set to Step. At this point the counter variable value must be less than the initial value of termination. In the following example, the counter variable by 2 each time myNum. After cycling, total value of 16,14,12,10,8,6,4 and 2 combined. Sub NewTotal ()

Dim myNum, total
For myNum = 16 To 2 Step -2
total = total + myNum
Next
MsgBox “Total is” & total & “.”
End Sub
 
Exit For statement is used in the counter value reaches its end before the exit For … Next statement. Because usually only in certain special circumstances (for example, when an error occurs) to exit the loop, so you can If … Then … Else statement block using True Exit For statement. If the condition is False, loop runs as usual.

Finally, let us take a look For Each … Next statement, For Each … Next loop and the For … Next loop similar. For Each … Next statement to run than a specified number of times, but each element of the array or object in the collection of a duplicate set of statements for each. This is not to know the number of elements in the collection is very useful. Its syntax is as follows: For Each element In group

[Statements]
[Exit For]
[Statements] Next [element]
 
If the group has at least one element, it will enter the For Each block executes. Once in circulation, they first group the first element of the implementation cycle of all the statements. As long as there are other elements in the group will cycle on the implementation of each element in the statement. When the group does not exit the loop when the other elements, then the statement after statement from Next to continue.

So far, we have completed all of the VBScript scripting language to learn basic knowledge, but this alone read the existing articles are not skilled you use VBScript, you must constantly practice to improve their grades. Of course, if you’re familiar with C, you can choose JavaScript as the scripting language ASP applications. I wonder if we have not found ASP debugging more difficult, because there is no ready-made tool, where I like to briefly introduce Microsoft Script Debugger, we can use it for a certain amount of program debugging.

IIS4.0 included in the Microsoft Script Debugger (Script Debugger), providing script debugging features. You can use the Microsoft Script debugging tools for the use of VBScript, JScript scripts written, and Java applets, beans, and ActiveX components, debugging work.

Some scripts on the client browsers, and some scripts (<% …%> in part) executed on the server. Microsoft Script Debugger, you can debug client script execution and implementation of server side script. The implementation of the client browser scripts that are among the client browser implementation, including the standard HTML code in VBScript, Jscript part. In the browser to load the HTML code or trigger events such as the button is pressed, it will do this include the script’s HTML code. The implementation of the client browser, the script, mainly used for the basic HTML form input checking and other functions.

In the implementation of the server script is executed on the server in IIS, including the. Asp program. First in the IIS server performance, the performance results to the standard HTML code, then transmitted to the client browser. Implementation of the server script, mainly for links between multiple pages, HTML form input processing, as well as access to server database information.

Microsoft Script Debugger provides the following debugging functions:

1, setting breakpoints

2 step by step tracking script.

3, set a bookmark.

4, view the call stack.

5, view and more change the value.

6, the script commands.

Filed in Asp 0 comments
No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
«
Next Post
»