发布网友 发布时间:2022-04-25 00:03
共1个回答
热心网友 时间:2023-10-16 13:53
'check1、check2、check3为checkbox控件数组
'check1、check2、check3的style属性设置为1
Private Sub Form_Load()
Dim i As Integer
Check1(0).Caption = "除7余0"
For i = 1 To 6
Load Check1(i)
Check1(i).Left = Check1(i - 1).Left + 800
Check1(i).Top = Check1(i - 1).Top
Check1(i).Caption = "除7余" & i
Check1(i).Visible = True
Next i
Check2(0).Caption = "除8余0"
For i = 1 To 7
Load Check2(i)
Check2(i).Left = Check2(i - 1).Left + 800
Check2(i).Top = Check2(i - 1).Top
Check2(i).Caption = "除8余" & i
Check2(i).Visible = True
Next i
Check3(0).Caption = "1到5"
For i = 1 To 3
Load Check3(i)
Check3(i).Left = Check3(i - 1).Left + 1500
Check3(i).Top = Check3(i - 1).Top
Check3(i).Caption = i * 5 + 1 & "到" & (i + 1) * 5
Check3(i).Visible = True
Next i
Command1.Caption = "清除"
Command2.Caption = "统计"
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To Check1.UBound
Check1(i).Value = vbUnchecked
Next
For i = 0 To Check2.UBound
Check2(i).Value = vbUnchecked
Next
For i = 0 To Check3.UBound
Check3(i).Value = vbUnchecked
Next
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, m As Integer
Dim s As String
Dim n(1 To 20) As Integer
For i = 0 To Check1.UBound
If Check1(i).Value = vbChecked Then
s = s & " " & Check1(i).Caption
For j = 1 To 20
If j Mod 7 = i Then
n(j) = n(j) + 1
End If
Next j
End If
Next
For i = 0 To Check2.UBound
If Check2(i).Value = vbChecked Then
s = s & " " & Check2(i).Caption
For j = 1 To 20
If j Mod 8 = i Then
n(j) = n(j) + 1
End If
Next j
End If
Next
For i = 0 To Check3.UBound
If Check3(i).Value = vbChecked Then
s = s & " " & Check3(i).Caption
For j = i * 5 + 1 To (i + 1) * 5
n(j) = n(j) + 1
Next j
End If
Next
Text1.Text = Trim(s)
s = ""
j = 0
For i = 1 To 20
If n(i) > m Then
m = n(i)
End If
Next
For i = 0 To m
If s = "" Then
s = i & "次:"
Else
s = s & vbCrLf & i & "次:"
End If
For j = 1 To 20
If n(j) = i Then
s = s & j & ","
End If
Next
Next
Text2.Text = s
End Sub