2013年10月31日 星期四

asp-for-each-in-array

asp for each in array
asp-for-loop
asp for all in
asp-for-all-in

inf http://webcheatsheet.com/asp/loops.php

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

沒有留言:

張貼留言