I have a class called 'Company' that has properties like 'CompanyName', 'CompanyCode' and 'IsActive'. This class is in VBScript. I want to store a collection of Company objects using VBScript in classic ASP. Is this possible, and if yes, then how would I do it?
You can use an array or a dictionary object:
Array
' 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
Dictionary
' 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With