2013-07-03 3 views
0
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, чтобы скопировать количество каждого ответа по каждому вопросу есть опция меню или кнопки, которая будет распечатывать анализ товара на принтере, который отображает номер вопроса и счетчик для каждого ответа. im пытается распечатать сумму ответов для нескольких опросов. Им интересно, как мне это сделать?проблема с 2d массив и печать

ответ

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