程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> 關於ASP編程 >> asp For Each Next 用法與For Each實例教程

asp For Each Next 用法與For Each實例教程

編輯:關於ASP編程

    在For Each ... Next循環類似,對於... Next循環。而不是重復陳述的指定的次數,

    每名... Next循環重復的對象集合為數組中的每個元素的聲明(或每個項目)。

    下面的代碼片斷創建下拉列表中選擇其中一個數組元素:

    Select ActionSelect AllTry It<%
    Dim bookTypes(7) 'creates first 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 Feed
      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 and print out our lists on the screen
    Call createList(bookTypes) 'takes bookTypes array as an argument
    Call createList(arrcars) 'takes arrCars array as an argument
    %>

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved