0

我的代码中不断出现错误:

Public Class frmPresentTest
    Dim correctAnswer As Double
    Dim i As Int32
    Dim wrongAnswer As Double
    Dim responses(((noOfQuestions - 1) + 1) - 1) As String

    Private Sub cmdFinished_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFinished.Click
        Dim str1 As String = "Correct Answer     Your Answer"
        FindChecked(i)
        Dim num2 As Double = 0
        Dim num3 As Integer = (noOfQuestions - 1)
        Dim num1 As Integer = 0
        Do While (num1 <= num3)
            If (responses(num1) <> "*") Then
                If (responses(num1) = test(num1).correctAnswer) Then
                    num2 = (num2 + correctAnswer)
                Else
                    num2 = (num2 - wrongAnswer)
                End If
            End If
            str1 = New String() {str1 & "  " & test(num1).correctAnswer & "    " & responses(num1), " "}
            num1 = (num1 + 1)

        Loop
        str1 = str1 & " * indicates that you did answer that question "
        str1 = str1 & "  Your score is: " & num2.ToString()
        MsgBox(str1, MsgBoxStyle.OkOnly, "Test Results")
        tookTest = True
        frmTestGen.Show()
        Me.Hide()

    End Sub

    Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
        FindChecked(i)
        i = (i + 1)
        If (i = (noOfQuestions - 1)) Then
            cmdNext.Visible = False
            cmdFinished.Visible = True
        End If
        ShowQuestion(i)
    End Sub

    Public Sub FindChecked(ByRef i As Int32)
        If (OptA.Checked) Then
            responses(i) = "A"
        ElseIf (optB.Checked) Then
            responses(i) = "B"
        ElseIf (optC.Checked) Then
            responses(i) = "C"
        ElseIf (optD.Checked) Then
            responses(i) = "D"
        Else
            responses(i) = "*"
        End If
    End Sub

    Private Sub frmPresentTest_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        correctAnswer = (100 / noOfQuestions)
        wrongAnswer = (correctAnswer / 2)
        i = 0
        OptA.Checked = False
        cmdNext.Visible = True
        cmdFinished.Visible = False
        ShowQuestion(i)
    End Sub

    Public Sub ShowQuestion(ByVal i As Int32)
        lblCount.Text = (i + 1).ToString() & "."
        OptA.Checked = False
        optB.Checked = False
        optC.Checked = False
        optD.Checked = False
        lblQuestion.Text = test(i).question
        OptA.Text = test(i).choiceA
        optB.Text = test(i).choiceB
        optC.Text = test(i).choiceC
        optD.Text = test(i).choiceD
    End Sub

End Class

str1 = New String() {str1 & " " & test(num1).correctAnswer & " " &responses(num1), " "}是我遇到的问题。

4

2 回答 2

1

您最初声明str1为字符串并且str1 = New String()= String Array 不是字符串。为什么不这样做:

str1 = str1 & "  " & test(num1).correctAnswer & "    " & responses(num1)
于 2013-10-17T02:15:31.253 回答
0

这意味着您应该学习如何执行以下操作之一:

  • 使用谷歌(你有几个“这是什么意思”的问题,任何搜索引擎都可以回答)
  • 问你的老师
  • 看看你的同学在过去 2 天里从 SO 那里得到的所有代码,同时制作他们自己的 BlackJack 游戏。
于 2013-10-17T17:16:16.707 回答