I have created a simple class, GaugeChart:
Class GaugeChart
Public Essential
Public Lifestyle
Public Spending
Public Average
End Class
That I wish to use inside a dictionary:
Dim items, objGaugeDic, objGaugeChart, objGaugeChartread
Set objGaugeDic = CreateObject("Scripting.Dictionary")
Set objGaugeChart = New GaugeChart ' from GaugeChartClass.asp
objGaugeChart.Essential = intChart1Essential
objGaugeChart.Lifestyle = intChart1Lifestyle
objGaugeChart.Spending = intChart1Spending
objGaugeChart.Average = Chart1Avg
Set objGaugeDic ("Goal1") = objGaugeChart
Response.Write("Essential: " + Cstr(objGaugeChart.Essential) + "<br />")
Set objGaugeChart = New GaugeChart ' from GaugeChartClass.asp
objGaugeChart.Essential = intChart2Essential
objGaugeChart.Lifestyle = intChart2Lifestyle
objGaugeChart.Spending = intChart2Spending
objGaugeChart.Average = Chart2Avg
Set objGaugeDic ("Goal2") = objGaugeChart
' load values
'objGuageDic.Add "Goal1", objGaugeElements
Response.Write("objGaugeDic Keys: " + Cstr(objGaugeDic.Count))
For i = 0 To objGaugeDic.Count -1 'Iterate the array
Response.Write( CType(objGaugeDic.Item(i),objGaugeChart).Essential + "<br />")
Next
Dictionary keys = 2 - so that's fine. However when I try to access the object and properties within the dictionary using CType, I get a runtime error.
Trying with objGaugeDic.Item(i).Essential
I get undefined.
I have also tried, instead of Set objGaugeDic ("Goal1") = objGaugeChart, to do
objGaugeDic.Add "Goal1", objGaugeChart` .
How can I access the object properties of each dictionary item of type objGaugeDic
, something like Response.Write( CType(objGaugeDic.Item(i),objGaugeChart).Essential + "<br />")
?