这是什么意思:'1维数组String'类型的值不能转换为'String'。

时间:2013-10-17 01:54:31

标签: vb.net visual-studio-2010

我的代码中一直出现错误:

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&amp; “”&amp; test(num1).correctAnswer&amp; “”&amp;回复(num1),“”} 是我遇到的问题。

2 个答案:

答案 0 :(得分:1)

您最初将str1声明为字符串,而str1 = New String() =字符串数组不是字符串。为什么不这样做:

str1 = str1 & "  " & test(num1).correctAnswer & "    " & responses(num1)

答案 1 :(得分:0)

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

  • 使用谷歌(你有一些“这是什么意思”的问题,任何搜索引擎都可以回答)
  • 问你的老师
  • 在制作自己的BlackJack游戏的同时,查看过去2天内同学们从中获得的所有代码。