gpt4 book ai didi

collections - 使用 VBScript 经典 ASP 中的对象集合?

转载 作者:行者123 更新时间:2023-12-02 21:50:17 28 4
gpt4 key购买 nike

我有一个名为“Company”的类,它具有“CompanyName”、“CompanyCode”和“IsActive”等属性。该类是用 VBScript 编写的。我想在经典 ASP 中使用 VBScript 存储 Company 对象的集合。这可能吗?如果是的话,我该怎么做?

最佳答案

您可以使用数组或字典对象:

数组

' 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com