0

It is part of a homework assignment. I have to have structured data, and read the questions in for a .dat file. So far this is what I have. I'm having the most trouble in my Private Sub cmdNext_Click function. There are 4 radio buttons that much display the answers, and a label that must display each question, and when I click the next button, it shows the next question and records the answer that was submitted. At the end, I have to display a message box with the answers and score to the test.

In a module I had to put this code that my teacher gave us:

Module MyModule

Structure testQuestion
    <VBFixedString(100)> Public question As String
    <VBFixedString(30)> Public choiceA As String
    <VBFixedString(30)> Public choiceB As String
    <VBFixedString(30)> Public choiceC As String
    <VBFixedString(30)> Public choiceD As String
    <VBFixedString(1)> Public correctAnswer As String

End Structure
Public Const noOfQuestions = 10
Public test(noOfQuestions - 1) As testQuestion
Public Const correctAnswer = 100 / noOfQuestions
Public Const wrongAnswer = correctAnswer / 2

Then in a form I so far have this code:

Option Explicit On

Public Class Example

Private Sub Example_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Main.Show()
    Me.Hide()
End Sub

Private Sub ShowQuestion()
    FileOpen(1, "Test1.dat", OpenMode.Random, , , Len(test(0)))

End Sub

Private Sub MarkTest()

    Dim grade As Integer = 0


    cmdNext.Text = "Test finished!"
    opt1.Enabled = False
    opt2.Enabled = False
    opt3.Enabled = False
    opt4.Enabled = False


End Sub





Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click

    If opt1.Checked = True Then
        test(noOfQuestions - 1) = opt1.Text
    ElseIf opt2.Checked = True Then
        test(noOfQuestions - 1) = opt2.Text
    ElseIf opt3.Checked = True Then
        test(noOfQuestions - 1) = opt3.Text
    ElseIf opt4.Checked = True Then
        test(noOfQuestions - 1) = opt4.Text
    End If

    opt1.Focus()
    If noOfQuestions < 10 Then
        lblNumber.Text = lblNumber.Text + 1

        lblQuestion.Text = test(testQuestion)
        opt1.Text = choiceA(noOfQuestions - 1, 1)
        opt2.Text = testQuestion(noOfQuestions - 1, 2)
        opt3.Text = testQuestion(noOfQuestions - 1, 3)
        opt4.Text = testQuestion(noOfQuestions - 1, 4)

        If lblNumber.Text = 10 Then
            cmdNext.Text = "Submit"
        End If

    Else
        MarkTest()
    End If

End Sub

End Class
Kazimierz Jawor
  • 18,184
  • 7
  • 30
  • 51
allison Snell
  • 23
  • 1
  • 5
  • 1
    and what is your problem? any errors? What doesn't work? What have you tried on your own? – mr.VVoo Apr 07 '13 at 19:01
  • My problem is pretty much how to I set the test questions and answers to the label, and radio buttons? This is the code that I have to set the label with the question, lblQuestion.Text = test(testQuestion), but that is not right and I'm not sure how to fix it. – allison Snell Apr 07 '13 at 19:06

0 Answers0