procedures can be public or private
private procedures can only be called from within the Class Module
Public Sub Print(arg As String)
Debug.Print arg
End Sub
Public Function Calculate(arg As Double) As Double
Calculate = arg
End Function
Private Function GetValue() As Double
GetValue = 12.34
End Function
class variables can only be private
Private dbl As Double
Public Sub SetBalance(arg as double)
dbl = arg
Debug.Print Balance
End Sub
Private
Public Property Get () As Type
End Property
Public Property Let (varname As Type )
End Property
Public Property Set (varname As Type )
End Property
Private someArray as Varient
Public Property Get SomeCount()
SomeCount = UBound(someArray) + 1
End Property
Let and Get can used as variables in calling code
Private dSomeValue As Double
Property Get SomeValue() As Long
SomeValue = dSomeValue
End Property
Property Let SomeValue(dValue As Long)
SomeValue = dSomeValue
End Property
value property
Private sName As String
' Get/Let Properties
Property Get Name() As String
Name = sName
End Property
Property Let Name(arg As String)
sName = qrg
End Property
object property
Private collPrices As Collection
' Get/Set Properties
Property Get Prices() As Collection
Set Prices = collPrices
End Property
Property Set Prices(arg As Collection)
Set collPrices = arg
End Property
Private iCount As Integer
Public Property Get Count() As Integer
Count = iCount
End Property
Public Property Let Count(Value As Integer)
iCount = Value
End Property
Private Sub Class_Initialize()
iCount = 23
End Sub
Public Sub Increment()
iCount = iCount + 1
End Sub
the calling code
Dim myClass1 As Class1
Private Sub CommandButton1_Click()
If myClass1 Is Nothing Then
Set myClass1 = New Class1
End If
MsgBox myClass1.Count
Call myClass1.Increment
MsgBox myClass1.Count
End Sub