Private WithEvents myTb As MSForms.TextBox
Private WithEvents myLab As MSForms.Label
Private myCktype1 As Long
Private myCktype2 As Long
Public Property Set tb(setTb As MSForms.TextBox)
Set myTb = setTb
End Property
Public Property Get tb() As MSForms.TextBox
End Property
Public Property Let ck1(setCk1 As Long)
myCktype1 = setCk1
End Property
Public Property Set lb(setLb As MSForms.Label)
Set myLab = setLb
End Property
Public Property Let ck2(setCk2 As Long)
myCktype2 = setCk2
End Property
Private Sub myTb_Change()
myTb.Text = UCase(myTb)
Select Case myCktype1
Case 1
'UserForm1.Label1.Caption = myTb.Text
myLab.Caption = myTb.Text '為何會出現沒有設定物變數或With區塊變數呢?
Case 2
'UserForm1.Label2.Caption = myTb.Text
myLab.Caption = myTb.Text
Case 3
'UserForm1.Label3.Caption = myTb.Text
myLab.Caption = myTb.Text
End Select
End Sub
Private Sub UserForm_Initialize()
Dim i As Long
ReDim myTb(1 To 3)
For i = 1 To 3
Set myTb(i) = New mTxtClass
Set myTb(i).tb = Me.Controls("Textbox" & CStr(i))
Next
myTb(1).ck1 = 1
myTb(2).ck1 = 2
myTb(3).ck1 = 3
ReDim myLab(1 To 3)
For i = 1 To 3
Set myLab(i) = New mTxtClass
Set myLab(i).lb = Me.Controls("Label" & CStr(i))
Next
myLab(1).ck2 = 1
myLab(2).ck2 = 2
myLab(3).ck2 = 3
End Sub