Using the code from the OP, the following works. In a module:
Sub TestMe()
Dim x As New clsSubject
x.INN = 3276132761#
Debug.Print x.PINN
End Sub
And this in the class:
Public PINN As String
Property Let INN(val As String)
If IsNumeric(val) And Len(val) = 10 Then
PINN = val
Else
Dim errorMessage As String
errorMessage = val & " is an Invalid value"
Err.Raise vbObjectError + 513, "ClsSubject", errorMessage
End If
End Property
In order to make the code running, call TestMe()
.
In the general case, the fields of the class should be private, and should be accessed through public properties. E.g. private PINN as String
, but this is only for illustration.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…