我有一个名为'Company'的类,它具有'CompanyName','CompanyCode'和'IsActive'等属性。这个类在VBScript中。我想在经典ASP中使用VBScript存储Company对象的集合。这是可能的,如果是的话,那我该怎么做呢?
答案 0 :(得分:9)
您可以使用数组或字典对象:
<强>阵列强>
' 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