Asp-Classic

如何在經典 ASP 中遍歷集合?

  • October 25, 2021

我希望能夠做到:

For Each thing In things
End For

經典 ASP - 不是 .NET!

無論您的 [事物] 需要在 VBScript 之外編寫。

在 VB6 中,您可以編寫一個自定義集合類,然後您需要編譯為 ActiveX DLL 並在您的網路伺服器上註冊它以訪問它。

像這樣的東西?

dim cars(2),x
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"

For Each x in cars
 response.write(x & "<br />")
Next

請參閱www.w3schools.com

如果要關聯鍵和值,請改用字典對象

Dim objDictionary
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Name", "Scott"
objDictionary.Add "Age", "20"
if objDictionary.Exists("Name") then
   ' Do something
else
   ' Do something else 
end if

引用自:https://stackoverflow.com/questions/2300