熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

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

2022-06-13   來源: .NET編程 

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

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

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

  Select ActionSelect AllTry It<%
Dim bookTypes() creates first array
bookTypes()="Classic"
bookTypes()="Information Books"
bookTypes()="Fantasy"
bookTypes()="Mystery"
bookTypes()="Poetry"
bookTypes()="Humor"
bookTypes()="Biography"
bookTypes()="Fiction"
 
Dim arrCars() creates second array
arrCars()="BMW"
arrCars()="Mercedes"
arrCars()="Audi"
arrCars()="Bentley"
arrCars()="Mini"

  Sub createList(some_array) takes an array and creates dropdown list
  dim i
  responsewrite("<select name=""mylist"">" & vbCrLf) vbCrLf stands for

  Carriage Return and Line Feed
  For Each item in some_array
     responsewrite("<option value=" & i & ">" & item & "</option>" &

  vbCrLf)
     i = i +
  Next repeat the code and move on to the next value of i
  responsewrite("</select>")
End Sub

  Now lets 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
%>


From:http://tw.wingwit.com/Article/program/net/201311/14022.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.