如何根据用户表单组合框响应动态计算分数
How to calculate score based on userform combobox responses dynamically
我有一个带有 7 个组合框的用户窗体,这些组合框可以选择 Yes
、No
、Partially
和 N/A
。根据每个框中的响应,我有一个填充总分的文本框。
Yes = 1
,
Partially = 0.5
,
No = 0
和
NA = 0
。
我有根据组合框响应进行计算的代码,如果我简单地除以总框数 (7),它会计算,但并非所有表单都会有 7 个响应(NA 是一个选项,但基本上没有支持或反对他们)。所以我需要弄清楚如何将总分除以总回复。我确信这非常简单,但我并不费力去弄明白。
这是我目前拥有的代码,它没有给我正确的 %
TXTScore = Format((nYes + nPartial * 0.5) / nYes + nPartial + nNo, "Percent")
Private Sub CommandButton1_Click()
Dim c As Control, nYes As Long, nPartial As Long, nNo As Long
For Each c In Me.Controls
If TypeName(c) = "ComboBox" Then
If c.Value = "Yes" Then nYes = nYes + 1
If c.Value = "Partially" Then nPartial = nPartial + 1
If c.Value = "No" Then nNo = nNo + 1
End If
Next c
TXTScore = Format((nYes + nPartial * 0.5) / nYes + nPartial + nNo, "Percent")
End Sub
例如 - 6 个是响应和 1 个 NA = 100%,5 个是响应,1 个部分响应和 1 个 NA 等于 92%
你也应该算上 NA(我想加上一些括号)
Private Sub CommandButton1_Click()
Dim c As Control, nYes As Long, nPartial As Long, nNo As Long, nNA As Long
nYes = 0
nPartial = 0
nNo = 0
nNA = 0
For Each c In Me.Controls
If TypeName(c) = "ComboBox" Then
If c.Value = "Yes" Then nYes = nYes + 1
If c.Value = "Partially" Then nPartial = nPartial + 1
If c.Value = "No" Then nNo = nNo + 1
If c.Value = "NA" Then nNA = nNA + 1
End If
Next c
TXTScore = Format((nYes + nPartial * 0.5) / (nYes + nPartial + nNo + nNA), "Percent")
End Sub
我有一个带有 7 个组合框的用户窗体,这些组合框可以选择 Yes
、No
、Partially
和 N/A
。根据每个框中的响应,我有一个填充总分的文本框。
Yes = 1
,
Partially = 0.5
,
No = 0
和
NA = 0
。
我有根据组合框响应进行计算的代码,如果我简单地除以总框数 (7),它会计算,但并非所有表单都会有 7 个响应(NA 是一个选项,但基本上没有支持或反对他们)。所以我需要弄清楚如何将总分除以总回复。我确信这非常简单,但我并不费力去弄明白。
这是我目前拥有的代码,它没有给我正确的 %
TXTScore = Format((nYes + nPartial * 0.5) / nYes + nPartial + nNo, "Percent")
Private Sub CommandButton1_Click()
Dim c As Control, nYes As Long, nPartial As Long, nNo As Long
For Each c In Me.Controls
If TypeName(c) = "ComboBox" Then
If c.Value = "Yes" Then nYes = nYes + 1
If c.Value = "Partially" Then nPartial = nPartial + 1
If c.Value = "No" Then nNo = nNo + 1
End If
Next c
TXTScore = Format((nYes + nPartial * 0.5) / nYes + nPartial + nNo, "Percent")
End Sub
例如 - 6 个是响应和 1 个 NA = 100%,5 个是响应,1 个部分响应和 1 个 NA 等于 92%
你也应该算上 NA(我想加上一些括号)
Private Sub CommandButton1_Click()
Dim c As Control, nYes As Long, nPartial As Long, nNo As Long, nNA As Long
nYes = 0
nPartial = 0
nNo = 0
nNA = 0
For Each c In Me.Controls
If TypeName(c) = "ComboBox" Then
If c.Value = "Yes" Then nYes = nYes + 1
If c.Value = "Partially" Then nPartial = nPartial + 1
If c.Value = "No" Then nNo = nNo + 1
If c.Value = "NA" Then nNA = nNA + 1
End If
Next c
TXTScore = Format((nYes + nPartial * 0.5) / (nYes + nPartial + nNo + nNA), "Percent")
End Sub