ASP for each Next usage and for each instance tutorial

Source: Internet
Author: User

In For Each ... Next loop like, for ... Next loop. Rather than the specified number of repeated statements,

Every name ... Next loops a repeating collection of objects (or each item) for each element in the array.

The following code fragment creates a Drop-down list to select one of the array elements:

Select Actionselect alltry it<%
Dim booktypes (7) ' Creates-a-i-array
Booktypes (0) = "Classic"
Booktypes (1) = "Information Books"
Booktypes (2) = "Fantasy"
Booktypes (3) = "Mystery"
Booktypes (4) = "Poetry"
Booktypes (5) = "Humor"
Booktypes (6) = "biography"
Booktypes (7) = "Fiction"

Dim Arrcars (4) ' creates second array
Arrcars (0) = "BMW"
Arrcars (1) = "Mercedes"
Arrcars (2) = "Audi"
Arrcars (3) = "Bentley"
Arrcars (4) = "Mini"

Sub createlist (Some_array) ' takes an array and creates Drop-down list
Dim i
Response.Write ("<select name=" "MyList" ">" & vbCrLf) ' VbCrLf stands for

Carriage return and line feeds
For each item in Some_array
Response.Write ("<option value=" & I & ">" & Item & "</option>" &

VBCRLF)
i = i + 1
Next ' Repeat the code and move on to the next value of I
Response.Write ("</select>")
End Sub

' Now let's call the Sub & print out we lists on the screen
Call CreateList (Booktypes) ' takes booktypes array as a argument
Call CreateList (Arrcars) ' takes arrcars array as a argument
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.