由于VBScript不支持继承,因此可以获取/设置子类参数的值:
<%
Set ChartDict = CreateObject("Scripting.Dictionary")
Dim ChartData: Set ChartData = new ChartDataClass
With ChartData
.Essential = 10
.Lifestyle = 40
.Spending = 30
' .Average is calcualted
.ColorScheme("Default") ' sets chart colors
End With
ChartDict.Add "Chart1", ChartData ' add chartData object to dictionary
'''''''''''''''''''''''''''''''''''''
'from using ChartData.ColorScheme("Default"), I want to use ChartData.ChartColors.{OuterLeft, OuterFill, OuterRight, etc...}
'*****************************************************************************
'
' Description:
' An ASP class to
' - create a charts class that contains all required parameters
' - for use with essential, lifestyle and spending gauge data sets
'
'*****************************************************************************
Class ChartDataClass
Public Essential
Public Lifestyle
Public Spending
Dim ChartColors
' automatically calculates the average of the three main values
Public Property Get Average
Average = Round((Essential + Lifestyle + Spending) / 3, 2)
End Property
' setting colors
Public Sub ColorScheme(ByVal SchemeName)
Set ChartColors = New ChartColorsClass
Select Case SchemeName
Case LCase("default")
With ChartColors
.OuterLeft = ""
.OuterFill = ""
.OuterRight = ""
.OuterRight = ""
.InnerLeft = "#3180B8"
.InnerFill = "#DADADA"
End With
End Select
Response.Write("<br>SchemeName: " + SchemeName)
Response.Write("<br>ChartColors.InnerLeft: " + ChartColors.InnerLeft)
End Sub
End Class
'*****************************************************************************
'
' Description:
' An ASP class to
' - contain color parameters
' - for use with essential, lifestyle and spending gauge data sets
'
'*****************************************************************************
Class ChartColorsClass
Public OuterLeft
Public OuterFill
Public OuterRight
Public InnerLeft
Public InnerFill
End Class
%>
我想使用ChartData.ColorScheme("Default")
设置配色方案,我想使用设置值ChartData.ChartColors.{OuterLeft, OuterFill, OuterRight, etc...}
我可以设置更长的名称属性:
Public ColorOuterLeft, ColorOuterFill, ColorOuterRight, ColorInnerLeft, ColorInnerFill
。
其他选项?
答案 0 :(得分:0)
我刚结束使用公共财产来解决这个问题。
尽管如此,其他建议还是很棒的。
Class ChartDataClass
Public Essential
Public Lifestyle
Public Spending
Public ChartTitle
Public ColorOuterLeft, ColorOuterFill, ColorOuterRight, ColorInnerLeft, ColorInnerFill
' automatically calculates the average of the three main values
Public Property Get Average
Average = Round((Essential + Lifestyle + Spending) / 3, 2)
End Property
'Constructor
Public Default Function Init()
SetColorScheme("default")
Set Init = Me
End Function
Public Sub SetChartTitle(ByVal ThisChartTitle)
ChartTitle = ThisChartTitle
End Sub
' setting colors
Public Sub SetColorScheme(ByVal SchemeName)
Select Case LCase(SchemeName)
Case "default"
ColorOuterLeft = "#BFDFA3"
ColorOuterFill = "#d1e8f9"
ColorOuterRight = "#3b9ac8"
ColorInnerLeft = "#3180B8"
ColorInnerFill = "#DADADA"
FontColor = "#235E7C"
FontType = "OpenSans"