我有一个名为“Company”的类,它具有诸如“CompanyName”、“CompanyCode”和“IsActive”之类的属性。此类在 VBScript 中。我想在经典 ASP 中使用 VBScript 存储公司对象的集合。这是可能的,如果是,那我该怎么做?
最佳答案
您可以使用数组或字典对象:
数组
' create an array with a fixed size
dim companies(2)
' fill the array with the companies
set companies(0) = Company1
set companies(1) = Company2
set companies(2) = Company3
' iteration example 1
dim company
for each company in companies
response.write company.CompanyName
next
' iteration example 2
dim i
for i = 0 to ubound(companies)
response.write companies(i).CompanyName
next
字典
' create a dictionary object
dim companies
set companies = server.createObject("Scripting.Dictionary")
' add the companies
companies.add "Key1", Company1
companies.add "Key2", Company2
companies.add "Key3", Company3
' iteration example
dim key
for each key in companies.keys
response.write key & " = " & companies.item(key).CompanyName
next
关于collections - 使用 VBScript 在经典 ASP 中收集对象?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10014986/