我统计有多少学生回答调查问题1到问题17。
Do you go to the lab?
我可以从Q1到Q15计算,如下面的代码所示,但我无法处理Q16(y / n)。输出需要显示Q1-Q15,跳过Q16并显示Q17。
我还有一张表tblSurveyQuestion(questID, questType, question)
。在Q16,questID = Survey16,questType =“Y”。
您能告诉我如何插入代码来处理Q16吗?到目前为止我的代码:
'assume dt is a datatable that is declared and the connection works
Dim ans(16, 3) As Integer '17 questions with Q16 is a y/n question
For I As Integer = 0 To dt.Rows.Count - 1
If dt.Rows(I).Item(2) = 1 Then
Dim Answer1() As String = dt.Rows(I).Item(3).Split(";")
For j1 As Integer = 0 To 16
Dim k1 As Integer = (Val(Answer1(j1)))
ans(j1, k1 - 1) += 1
Next
End If
Next
答案 0 :(得分:0)
由于您按顺序评估答案,并且您希望在某个时刻了解以前的数据,因此您需要在代码中知道您正在评估(或显示)当前为了采取相应行动的问题。
您已经在ans(15)
中对问题16进行了评估,但您只需要检查您是否在索引16(=问题17),并处理ans(15)
的结果。一种可能性是使用:
if / elseif / else / end if
你需要:
一个非常简单的解决方案可能如下所示:
'assume dt is a datatable that is declared and the connection works
Dim ans(16, 3) As Integer '17 questions with Q16 is a y/n question
For I As Integer = 0 To dt.Rows.Count - 1
If dt.Rows(I).Item(2) = 1 Then
Dim Answer1() As String = dt.Rows(I).Item(3).Split(";")
'declare a store for the answer of question 16
Dim answer16IsPositive as Boolean = False
For j1 As Integer = 0 To 16
Dim k1 As Integer = (Val(Answer1(j1)))
ans(j1, k1 - 1) += 1
If (j1 = 15) ' we are at the 16th answer
If (k1 = 1) 'save result of answer 16!
answer16IsPositive = True
End If
End If
If (j1 = 16) ' we are at the 17th answer
If (Not answer16IsPositive)
' deal with answer 17!
'Else
' do nothing
End If
End If
Next
End If
Next