tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,834
- Office Version
- 365
- 2019
- Platform
- Windows
I was of the understanding the syntax for a class is as follows:
You create a private variable and then have public let / get properties to pass in / retrieve the data, like:
I came across this code:
How come DataRange, DataPointToExplode and Title all have a Let Property but no corresponding private variable?
Thanks
You create a private variable and then have public let / get properties to pass in / retrieve the data, like:
Code:
Private pSomeProperty As Integer
Property Get SomeProperty As Integer
SomeProperty = pSomeProperty
End Property
Property Let SomeProperty (p As Integer)
pSomeProperty = p
End Property
I came across this code:
Code:
Option Explicit
Private PieChart As Chart 'the chart we're creating
Private ThisSheet As Worksheet 'the worksheet we're on
Public Property Let DataRange(ThisRange As String)
PieChart.SetSourceData ThisSheet.Range(ThisRange), PlotBy:=xlRows
End Property
Public Property Let DataPointToExplode(ThisPoint As Integer)
'explode nth point on first and only data seriesr
PieChart.SeriesCollection(1).Points(ThisPoint).Explosion = 15
End Property
Public Property Let Title(ThisTitle As String)
'the chart has a title - set its text
PieChart.HasTitle = True
With PieChart.ChartTitle
.Characters.Text = "Peruvian GDP per head ($)"
.Border.Weight = xlHairline
.Shadow = True
End With
End Property
Private Sub Class_Initialize()
'store which worksheet we are on
Set ThisSheet = ActiveSheet
'create the new chart, and set some basic things about it
Set PieChart = Charts.Add
'what sort of chart this is
PieChart.ChartType = xlPie
'where it is (separate sheet)
PieChart.Location Where:=xlLocationAsNewSheet
End Sub
Sub PrintPreview()
PieChart.PrintPreview
End Sub
How come DataRange, DataPointToExplode and Title all have a Let Property but no corresponding private variable?
Thanks