VBScript中的对象/类字典 [英] Dictionary of Objects/Classes in VBScript

查看:111
本文介绍了VBScript中的对象/类字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vbscript中是否可以有一个对象/类的字典?

Is it possible to have a dictionary of object/classes in vbscript?

例如:

Class employeeclass
    Public first, last, salary
End Class
Dim employeedict: Set employeedict = CreateObject("Scripting.Dictionary")

'Loop would be here
Dim employee: Set employee = new employeeclass
With employee
    .first = "John"
    .last = "Doe"
    .salary = 50000
End With
employeedict.Add "1", employee

EDIT 上面的方法确实有效

推荐答案

(回答自己的问题)

是的,可以在VBScript中使用对象/类的字典。以下是有兴趣者的示例:

Yes, its possible to use a dictionary of objects/classes in VBScript. The following is an example for those interested:

Class employeeclass
    Public first, last, salary
End Class
Dim employeedict: Set employeedict = CreateObject("Scripting.Dictionary")

Dim employee: Set employee = new employeeclass
With employee
    .first = "John"
    .last = "Doe"
    .salary = 50000
End With
employeedict.Add "1", employee

Set employee = new employeeclass
With employee
    .first = "Mary"
    .last = "Jane"
    .salary = 50000
End With
employeedict.Add "3", employee

Dim employeedetails: Set employeedetails = employeedict.Item("1")
WScript.StdOut.WriteLine("Name:" & employeedetails.first & " " & employeedetails.last & " $" & employeedetails.salary )
WScript.StdOut.WriteLine(employeedict.Item("3").first & " " & employeedict.Item("3").last & " makes $" & employeedict.Item("3").salary)

打印输出:

Name:John Doe $50000 
Mary Jane makes $50000

这篇关于VBScript中的对象/类字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆