VBA слово активный х контроль - PullRequest
0 голосов
/ 06 марта 2019

Я пытаюсь заставить этот макрос VBA работать для вычисления двух наборов данных, используя активные элементы управления x в ms-word. Для каждой коробки в таблице

enter image description here

Я хочу, чтобы вычисление давало количество отсчетов каждый раз, когда "2" отмечается как истинное для S1A - S1D и S2A - S2D для Label1.caption.

И другой набор вычислений будет давать число отсчетов каждый раз, когда «2» помечается как истинное для T1A до T1D и T2A до T2D с выходом в 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

1 Ответ

0 голосов
/ 08 марта 2019

Попробуйте вместо этого:

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
...