Don't use array can solve
CodePudding user response:
With a control array, so that you don't tiredUse the control array and then Click event loop, easy to implement
CodePudding user response:
Can use collection instead of control arrays, the code is as follows:
Option Explicit
Private McOlChecks As New Collection
Private Sub Check1_Click ()
UpdateStatus
End Sub
Private Sub Check2_Click ()
UpdateStatus
End Sub
Private Sub Check3_Click ()
UpdateStatus
End Sub
Private Sub Check4_Click ()
UpdateStatus
End Sub
Private Sub Check5_Click ()
UpdateStatus
End Sub
Private Sub Check6_Click ()
UpdateStatus
End Sub
The Public Function UpdateStatus ()
Dim blnEnabled As Boolean
BlnEnabled=IsOtherUsable
Dim objCheck As CheckBox
For Each objCheck McOlChecks In
If blnEnabled Then
ObjCheck. Enabled=True
The Else
If objCheck. Value=https://bbs.csdn.net/topics/vbChecked Then
ObjCheck. Enabled=True
The Else
ObjCheck. Enabled=False
End the If
End the If
Next
End the Function
Private Function IsOtherUsable () As a Boolean
Dim intCount As Integer
IntCount=0
Dim objCheck As CheckBox
For Each objCheck McOlChecks In
If objCheck. Value=https://bbs.csdn.net/topics/vbChecked Then
IntCount=intCount + 1
End the If
Next
IsOtherUsable=(intCount & lt; 2)
End the Function
Private Sub Form_Load ()
McOlChecks. Add Check1
McOlChecks. Add Check2
McOlChecks. Add Check3
McOlChecks. Add Check4
McOlChecks. Add Check5
McOlChecks. Add Check6
End Sub
Run the example:
Download address:
Link: https://pan.baidu.com/s/1APPDqMaoQPAVSluU0jj2Pg
The extracted code: 1 rl3
CodePudding user response:
Simple use ncJoins each operating variables add + 1 or - 1
And then set off a patrol
Patrol found variable into 2 then joins all the whole do not unavailable
Less code absolute speed
CodePudding user response:
Forget it I help you readyEstablish a check1 then copy
In continuous paste
A total of eight
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- it is the code you see my code simple
Dim C_index As Integer
Private Sub Check1_Click (Index As an Integer)
If Check1 (Index) Value=https://bbs.csdn.net/topics/1 Then C_index=C_index + 1
If Check1 (Index) Value=https://bbs.csdn.net/topics/0 Then
C_index=C_index - 1
For I=0 To 7
Check1 (I) Enabled=True
Next I
End the If
If C_index & gt; 1 Then
For I=0 To 7
If Check1 (I) Value=https://bbs.csdn.net/topics/0 Then
Check1 (I) Enabled=False
End the If
Next I
End the If
End Sub