Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collection of objects in classic ASP using VBScript?

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?

like image 963
Sunil Avatar asked Dec 20 '22 23:12

Sunil


1 Answers

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
like image 196
Guido Gautier Avatar answered Feb 08 '23 23:02

Guido Gautier