2012-04-04 49 views
3

我有一個名爲'Company'的類,具有'CompanyName','CompanyCode'和'IsActive'等屬性。這個類在VBScript中。我想在傳統的ASP中使用VBScript存儲公司對象的集合。這是可能的,如果是的話,那我該怎麼做呢?使用VBScript在經典ASP中收集對象?

+0

數組是一個非常基本的..什麼是你的最終目標是什麼?你會用這個系列做什麼? – 2012-04-05 07:29:12

+0

我需要能夠遍歷公司對象並根據公司屬性創建動態字符串。例如,根據字典集合中的Company對象創建一個逗號分隔的CompanyId列表。 – Sunil 2012-04-05 16:12:21

+0

所以Guido回答下面應該是你要找的,不是嗎? – 2012-04-05 19:42:23

回答

8

可以使用數組或Dictionary對象:

陣列

' 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