小弟從網業搜集到QEE大大物件類別範例,
執行卻出現〝無法處理所指定物件的事件”
請問應如何修正下列語法呢?
[attach]13349[/attach]
語法如下:
Option Explicit
Dim WithEvents mc As myClass '無法處理所指定物件的事件
Public Event Change(ByRef Cancel As Boolean)
Private s$
Public Property Get Value() As String
Value = s
End Property
Public Property Let Value(ByVal c As String)
s = c
End Property
Private Sub Class_Initialize()
s = "abc" '初始值
End Sub
Private Sub CommandButton1_Click()
mc.Value = TextBox1 '賦值
End Sub
Private Sub CommandButton2_Click()
MsgBox "mc當前的值為" & mc.Value '讀值
End Sub
Private Sub mc_Change(ByRef Cancel As Boolean)
If MsgBox("要改變mc的值嗎?", vbYesNo) = vbNo Then Cancel = True
End Sub
Dim mc As New myClass
Private Sub UserForm_Initialize()
Set mc = New myClass
End Sub