3

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

編集上記は機能します。

4

1 に答える 1

4

(自分の質問に答える)

はい、VBScript でオブジェクト/クラスの辞書を使用することは可能です。以下は、興味のある方のための例です。

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
于 2012-11-24T23:59:02.843 に答える