我正在尝试使此VBA宏能够使用ms-word中的活动x控件来计算两组数据。对于表格中的每个框
我希望计算给出每次在Label1.caption上从S1A到S1D和S2A到S2D都为“ 2”时计数的次数。
另一组计算将给出每次在T1A到T1D和T2A到T2D都被选中为“ 2”的情况下计数的数量,输出结果为Label2.caption。
下面是我开始的内容,但没有达到我想要的目的。
enter code here
Dim count_of_0 As Integer
Dim count_of_2 As Integer
Sub calculate_the_score()
count_of_0 = 0
count_of_2 = 0
If S1A.Value = True Then count_of_0 = count_of_0 + 0
If S2A.Value = True Then count_of_2 = count_of_2 + 2
If S1B.Value = True Then count_of_0 = count_of_0 + 0
If S2B.Value = True Then count_of_2 = count_of_2 + 2
If S1C.Value = True Then count_of_0 = count_of_0 + 0
If S2C.Value = True Then count_of_2 = count_of_2 + 2
If S1D.Value = True Then count_of_0 = count_of_0 + 0
If S2D.Value = True Then count_of_2 = count_of_2 + 2
If T1A.Value = True Then count_of_0 = count_of_0 + 0
If T2A.Value = True Then count_of_2 = count_of_2 + 2
If T1B.Value = True Then count_of_0 = count_of_0 + 0
If T2B.Value = True Then count_of_2 = count_of_2 + 2
If T1C.Value = True Then count_of_0 = count_of_0 + 0
If T2C.Value = True Then count_of_2 = count_of_2 + 2
If T1D.Value = True Then count_of_0 = count_of_0 + 0
If T2D.Value = True Then count_of_2 = count_of_2 + 2
Dim the_sum As Double
the_sum = (count_of_0) + (count_of_2)
Label1.Caption = "Total:" & the_sum & ""
Label2.caption = "Total :" & the_sum & ""
End Sub
Private Sub S1A_Click()
If S1A = True Then
S2A = False
End If
calculate_the_score
End Sub
Private Sub S1B_Click()
If S1B = True Then
S2B = False
End If
calculate_the_score
End Sub
Private Sub S1C_Click()
If S1C = True Then
S2C = False
End If
calculate_the_score
End Sub
Private Sub S1D_Click()
If S1D = True Then
S2D = False
End If
calculate_the_score
End Sub
Private Sub S2A_Click()
If S2A = True Then
S1A = False
End If
calculate_the_score
End Sub
Private Sub S2B_Click()
If S2B = True Then
S1B = False
End If
calculate_the_score
End Sub
Private Sub S2C_Click()
If S2C = True Then
S1C = False
End If
calculate_the_score
End Sub
Private Sub S2D_Click()
If S2D = True Then
S1D = False
End If
calculate_the_score
Private Sub T1A_Click()
If T1A = True Then
T2A = False
End If
calculate_the_score
End Sub
Private Sub T1B_Click()
If T1B = True Then
T2B = False
End If
calculate_the_score
End Sub
Private Sub T1C_Click()
If T1C = True Then
T2C = False
End If
calculate_the_score
End Sub
Private Sub T1D_Click()
If T1D = True Then
T2D = False
End If
calculate_the_score
End Sub
Private Sub T2A_Click()
If T2A = True Then
T1A = False
End If
calculate_the_score
End Sub
Private Sub T2B_Click()
If T2B = True Then
T1B = False
End If
calculate_the_score
End Sub
Private Sub T2C_Click()
If T2C = True Then
T1C = False
End If
calculate_the_score
End Sub
Private Sub T2D_Click()
If T2D = True Then
T1D = False
End If
calculate_the_score
End Sub
答案 0 :(得分:0)
尝试以下方法:
Dim count_of_0 As Integer
Dim scount_of_2 As Integer
Dim tcount_of_2 As Integer
Sub calculate_the_score()
count_of_0 = 0
scount_of_2 = 0
tcount_of_2 = 0
If S1A.Value = True Then count_of_0 = count_of_0 + 0
If S2A.Value = True Then scount_of_2 = scount_of_2 + 2
If S1B.Value = True Then count_of_0 = count_of_0 + 0
If S2B.Value = True Then scount_of_2 = scount_of_2 + 2
If S1C.Value = True Then count_of_0 = count_of_0 + 0
If S2C.Value = True Then scount_of_2 = scount_of_2 + 2
If S1D.Value = True Then count_of_0 = count_of_0 + 0
If S2D.Value = True Then scount_of_2 = scount_of_2 + 2
If T1A.Value = True Then count_of_0 = count_of_0 + 0
If T2A.Value = True Then tcount_of_2 = tcount_of_2 + 2
If T1B.Value = True Then count_of_0 = count_of_0 + 0
If T2B.Value = True Then tcount_of_2 = tcount_of_2 + 2
If T1C.Value = True Then count_of_0 = count_of_0 + 0
If T2C.Value = True Then tcount_of_2 = tcount_of_2 + 2
If T1D.Value = True Then count_of_0 = count_of_0 + 0
If T2D.Value = True Then tcount_of_2 = tcount_of_2 + 2
Label1.Caption = "Total:" & scount_of_2 & ""
Label2.Caption = "Total :" & tcount_of_2 & ""
End Sub