nummyofthedowd
New Member
- Joined
- Apr 10, 2013
- Messages
- 13
Hi,
I have been writing some VBA (Excel) classes and using the Property Let and Get functions. I understand the Get syntax, but not the Let. I have pasted a typical example below, could someone clarify why it does not use me.PenColor("Red") as seen below? As far as I can tell the Let property function accepts an argument but in all examples I can find (MrExcel, Chip Pearson etc) they all have a simple assignment. Why does the Let property function not require an argument when called?
Thanks in advance.
David
I have been writing some VBA (Excel) classes and using the Property Let and Get functions. I understand the Get syntax, but not the Let. I have pasted a typical example below, could someone clarify why it does not use me.PenColor("Red") as seen below? As far as I can tell the Let property function accepts an argument but in all examples I can find (MrExcel, Chip Pearson etc) they all have a simple assignment. Why does the Let property function not require an argument when called?
Thanks in advance.
David
Code:
' Begin Class Definition
Dim CurrentColor As Integer
Const BLACK = 0, RED = 1, GREEN = 2, BLUE = 3
' Set the pen color property for a Drawing package.
' The module-level variable CurrentColor is set to
' a numeric value that identifies the color used for drawing.
Property Let PenColor(ColorName As String)
Select Case ColorName ' Check color name string.
Case "Red"
CurrentColor = RED ' Assign value for Red.
Case "Green"
CurrentColor = GREEN ' Assign value for Green.
Case "Blue"
CurrentColor = BLUE ' Assign value for Blue.
Case Else
CurrentColor = BLACK ' Assign default value.
End Select
End Property
' Returns the current color of the pen as a string.
Property Get PenColor() As String
Select Case CurrentColor
Case RED
PenColor = "Red"
Case GREEN
PenColor = "Green"
Case BLUE
PenColor = "Blue"
End Select
End Property
Sub pen()
' The following code sets the PenColor property for a drawing package
' by calling the Property let procedure.
PenColor = "Red"
'************** Why Not **********************************
me.PenColor("Red")
'************** Why Not **********************************
' The following code gets the color of the pen
' calling the Property Get procedure.
ColorName = PenColor
MsgBox ColorName
End Sub