Option Explicit On
Option Strict On
Public Class SurveyForm
Structure Question
Dim QuestionString As String
End Structure
Structure Answer
Dim AnswerInteger As Integer
End Structure
Private QuestionGroup(9) As Question
Private AnswerGroup(9, 4) As Answer
Private indexinteger As Integer = 0
Private Sub QuestionGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuestionGroupBox.Enter
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub SurveyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim always As Integer
Dim never As Integer
Dim seldom As Integer
Dim sometimes As Integer
Dim usually As Integer
If AlwaysRadioButton.Checked = True Then always += 1
If NeverRadioButton.Checked = True Then never += 1
If SeldomRadioButton.Checked = True Then seldom += 1
If SometimesRadioButton.Checked = True Then sometimes += 1
If UsuallyRadioButton.Checked = True Then usually += 1
AlwaysRadioButton.Checked = False
NeverRadioButton.Checked = False
SeldomRadioButton.Checked = False
SometimesRadioButton.Checked = False
UsuallyRadioButton.Checked = False
QuestionGroup(0).QuestionString = "Question 1: Do you read the textbook chapter after class"
QuestionGroup(1).QuestionString = "Question 2: Do you complete the homework when it is assigned"
QuestionGroup(2).QuestionString = "Question 3: Do attend class regularly"
QuestionGroup(3).QuestionString = "Question 4: Do you participate in class discussions"
QuestionGroup(4).QuestionString = "Question 5: Do you participate in a study group"
QuestionGroup(5).QuestionString = "Question 6: Do you answer questions in the textbook"
QuestionGroup(6).QuestionString = "Question 7: Do you practice with the hands on excersice"
QuestionGroup(7).QuestionString = "Question 8: Do you try little projects to test all new topics"
QuestionGroup(8).QuestionString = "Question 9: Do you ask questions when you are unsure about a topic?"
QuestionGroup(9).QuestionString = "Question 10: Do you use the online help to learn more about each feature?"
AnswerGroup(0, 0).AnswerInteger = always
End Sub
Private Sub BeginSurveyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeginSurveyButton.Click
QuestionLabel.Text = QuestionGroup(indexinteger).QuestionString
If indexinteger < QuestionGroup.Length Then
indexinteger += 1
If indexinteger = 10 Then
QuestionLabel.Text = "Thank you for completing the survey"
End If
End If
BeginSurveyButton.Text = "Next Question"
If indexinteger = 10 Then
BeginSurveyButton.Enabled = False
End If
If AlwaysRadioButton.Checked = False Then
If NeverRadioButton.Checked = False Then
If SeldomRadioButton.Checked = False Then
If SometimesRadioButton.Checked = False Then
If UsuallyRadioButton.Checked = False Then
MessageBox.Show("Please select an answer", "Invalid Answer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
indexinteger -= 1
End If
End If
End If
End If
End If
PrintButton.Enabled = False
NextButton.Enabled = False
If indexinteger = 10 Then
PrintButton.Enabled = True
NextButton.Enabled = True
End If
End Sub
Private Sub AlwaysRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlwaysRadioButton.CheckedChanged, NeverRadioButton.CheckedChanged, SeldomRadioButton.CheckedChanged, SometimesRadioButton.CheckedChanged, UsuallyRadioButton.CheckedChanged
End Sub
Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
NextButton.Enabled = False
PrintButton.Enabled = False
BeginSurveyButton.Enabled = True
QuestionLabel.Text = QuestionGroup(0).QuestionString
NeverRadioButton.Checked = False
AlwaysRadioButton.Checked = False
SeldomRadioButton.Checked = False
SometimesRadioButton.Checked = False
UsuallyRadioButton.Checked = False
End Sub
End Class
好的,这是我的代码 任务是创建一个项目,用户将在其中完成10个问题调查。创建一个包含以下每个问题的标签的表单和每个问题的一组单选按钮,并带有以下响应:始终,通常,有时,很少,从不 使用2d数组来累积每个问题的每个响应的数量有一个菜单或按钮选项,它将在打印机上打印项目分析,显示问题编号和每个响应的计数 即时通讯试图打印多个调查的答案总和,我想知道我该怎么做呢
答案 0 :(得分:0)
您必须依赖相应控件的事件来更新全局变量(always
,never
等)。您当前的代码只检查在开始时发生的情况,而不是在用户执行任何更改之后。原则上,每个控件的默认事件应该足够了(即,在设计视图上双击此控件后生成其方法的控件)。例如:
Private Sub AlwaysRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlwaysRadioButton.CheckedChanged
If (AlwaysRadioButton.Checked) Then
always += 1
End If
End Sub
每次检查always
时,此代码会向AlwaysRadioButton
变量添加一个。但请记住,您必须单独管理事件;因此,每个方法不会关联多个事件(默认情况下会生成一个VB)。