-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventCheckBoxClick.cls
74 lines (63 loc) · 1.85 KB
/
EventCheckBoxClick.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "EventCheckBoxClick"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'@Folder("Userform.GeneralForm")
Private pForm As UserForm
Private WithEvents pcb_master As msForms.checkbox
Attribute pcb_master.VB_VarHelpID = -1
Private pcb_slave() As msForms.checkbox
Private pArrNum() As Long
Sub Init(form As UserForm, cb_master As msForms.checkbox, _
cb_slave() As msForms.checkbox, isAll As Boolean, arrNum() As Long)
Dim i As Long
Set pForm = form
Set pcb_master = cb_master
ReDim pcb_slave(LBound(cb_slave) To UBound(cb_slave))
For i = LBound(cb_slave) To UBound(cb_slave)
Set pcb_slave(i) = cb_slave(i)
Next i
If isAll Then
ReDim pArrNum(LBound(cb_slave) To UBound(cb_slave))
For i = LBound(cb_slave) To UBound(cb_slave)
pArrNum(i) = i
Next i
Else
ReDim pArrNum(LBound(arrNum) To UBound(arrNum))
For i = LBound(arrNum) To UBound(arrNum)
pArrNum(i) = arrNum(i)
Next i
End If
End Sub
Private Sub pcb_master_Click()
Dim i As Long
For i = LBound(pcb_slave) To UBound(pcb_slave)
If IsInArr(i, pArrNum) Then
pcb_slave(i).value = pcb_master.value
Else
pcb_slave(i).value = False
End If
Next i
End Sub
Private Function IsInArr(str As Variant, arr As Variant) As Boolean
Dim i As Long
If IsArray(arr) Then
For i = LBound(arr) To UBound(arr)
If str = arr(i) Then
IsInArr = True
Exit Function
End If
Next i
Else
If str = arr Then
IsInArr = True
Exit Function
End If
End If
IsInArr = False
End Function