Public Property Let UserName(ByVal UserName As String)
strUserName = UserName
End Property
Public Property Get UserName() As String
UserName = strUserName
End Property
Private Sub Class_Initialize()
strUserName = "ewang11"
End Sub
Private Sub Class_Terminate()
MsgBox "类已被Terminate"
End Sub
窗体代码
Dim a As New clsTest
Private Sub Command0_Click()
MsgBox a.UserName
End Sub
Private Sub Command1_Click()
Set a = Nothing '销毁类,会触发Terminate事件
End Sub